-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(powerlevel10k): Add Powerlevel10k segment to contrib
- Loading branch information
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Powerlevel10k Segment | ||
|
||
Adds a custom segment to the [Powerlevel10k](https://github.com/romkatv/powerlevel10k) zsh theme. | ||
|
||
![Demo](./screenshot.webp?raw=true) | ||
|
||
## Install | ||
|
||
1. Configure nightscout-menu-bar to write the current data to a local file: | ||
1. Open the nightscout-menu-bar menu. | ||
2. Hover over "Preferences". | ||
3. Check "Write to local file". | ||
2. Install the Powerlevel10k segment: | ||
1. Download the [segment script](nightscout.zsh) to a local file. This file will be sourced during Powerlevel10k initialization.[^1] | ||
1. For example: `~/.p10k/nightscout.zsh`. | ||
2. Edit `~/.p10k.zsh`. | ||
3. Search for `p10k reload`. | ||
4. Somewhere before this line, source the segment file.[^2] | ||
1. For example: `source ~/.p10k/nightscout.zsh` | ||
5. Search for `POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS`. | ||
6. Add `nightscout` somewhere in this array, depending on where you would like the widget to be rendered. | ||
7. Open a new shell, or restart your current shell with `exec zsh`. | ||
8. Nightscout data should be rendered as a right-segment! | ||
|
||
[^1]: The segment script contents can also be pasted directly into `~/.p10k.zsh`, in the same place as the `source` command would be added in step vi. | ||
[^2]: Only necessary if script is being downloaded to a separate file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#################################[ nightscout: blood sugar ]################################# | ||
# Nightscout state file. Typically does not need to be changed. | ||
typeset -g NIGHTSCOUT_STATE_FILE="$TMPDIR/nightscout.csv" | ||
|
||
# Nightscout styling will be chosen if the reading is below a given value. | ||
typeset -g NIGHTSCOUT_THRESHOLD_URGENT_LOW=55 | ||
typeset -g NIGHTSCOUT_THRESHOLD_LOW=80 | ||
typeset -g NIGHTSCOUT_THRESHOLD_IN_RANGE=160 | ||
typeset -g NIGHTSCOUT_THRESHOLD_HIGH=260 | ||
|
||
# Show/hide Nightscout parts. | ||
typeset -g NIGHTSCOUT_SHOW_ARROW=true | ||
typeset -g NIGHTSCOUT_SHOW_DELTA=true | ||
typeset -g NIGHTSCOUT_SHOW_TIMESTAMP=true | ||
# Can be commented out if timestamp is hidden. | ||
zmodload zsh/datetime | ||
|
||
# Nightscout colors. | ||
# Urgent low styling. | ||
typeset -g POWERLEVEL9K_NIGHTSCOUT_URGENT_LOW_BACKGROUND=1 | ||
typeset -g POWERLEVEL9K_NIGHTSCOUT_URGENT_LOW_FOREGROUND=7 | ||
# Low styling. | ||
typeset -g POWERLEVEL9K_NIGHTSCOUT_LOW_BACKGROUND=1 | ||
typeset -g POWERLEVEL9K_NIGHTSCOUT_LOW_FOREGROUND=7 | ||
# In range styling. | ||
typeset -g POWERLEVEL9K_NIGHTSCOUT_IN_RANGE_BACKGROUND=2 | ||
typeset -g POWERLEVEL9K_NIGHTSCOUT_IN_RANGE_FOREGROUND=0 | ||
# High styling. | ||
typeset -g POWERLEVEL9K_NIGHTSCOUT_HIGH_BACKGROUND=3 | ||
typeset -g POWERLEVEL9K_NIGHTSCOUT_HIGH_FOREGROUND=0 | ||
# Urgent high styling. | ||
typeset -g POWERLEVEL9K_NIGHTSCOUT_URGENT_HIGH_BACKGROUND=1 | ||
typeset -g POWERLEVEL9K_NIGHTSCOUT_URGENT_HIGH_FOREGROUND=7 | ||
# Custom icon. | ||
# typeset -g POWERLEVEL9K_NIGHTSCOUT_VISUAL_IDENTIFIER_EXPANSION='⭐' | ||
|
||
# Creates segment with Nightscout blood sugar data. | ||
# | ||
# Example output: 120 → -1 [1m] | ||
function prompt_nightscout() { | ||
emulate -L zsh | ||
|
||
if [[ -s "$NIGHTSCOUT_STATE_FILE" ]]; then | ||
# Read state file into local variables. | ||
typeset bgnow arrow delta timestamp | ||
IFS=, read -r bgnow arrow delta timestamp <"$NIGHTSCOUT_STATE_FILE" | ||
|
||
# State file is invalid. Segment will be hidden. | ||
if [[ -z "$bgnow" ]]; then | ||
p10k segment -c '' | ||
return | ||
fi | ||
|
||
# Choose current state for styling. | ||
if (( bgnow <= NIGHTSCOUT_THRESHOLD_URGENT_LOW )); then | ||
typeset state=URGENT_LOW | ||
elif (( bgnow < NIGHTSCOUT_THRESHOLD_LOW )); then | ||
typeset state=LOW | ||
elif (( bgnow < NIGHTSCOUT_THRESHOLD_IN_RANGE )); then | ||
typeset state=IN_RANGE | ||
elif (( bgnow < NIGHTSCOUT_THRESHOLD_HIGH )); then | ||
typeset state=HIGH | ||
else | ||
typeset state=URGENT_HIGH | ||
fi | ||
|
||
# Generate text | ||
typeset text="$bgnow" | ||
[[ "$NIGHTSCOUT_SHOW_ARROW" == true ]] && text+=" $arrow" | ||
[[ "$NIGHTSCOUT_SHOW_DELTA" == true ]] && text+=" $delta" | ||
[[ "$NIGHTSCOUT_SHOW_TIMESTAMP" == true ]] && text+=" [$(( (EPOCHSECONDS - timestamp + 30) / 60 ))m]" | ||
|
||
# Write segment. | ||
p10k segment -s "$state" -i $'\UF058C' -t "$text" | ||
else | ||
# State file does not exist. Segment will be hidden. | ||
p10k segment -c '' | ||
fi | ||
} |
Binary file not shown.