Created
May 5, 2023 22:16
-
-
Save ThinGuy/61d996c95c20f113ad471cbd5a367f8a to your computer and use it in GitHub Desktop.
Display a color-coded IEC 60417-5009 power symbol (⏻) in your Bash Primary Prompt String (PS1) when your host needs a reboot.
This file contains hidden or 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
############################################################################################# | |
### Display the IEC 60417-5009 power symbol (⏻) at the end of your Bash Primary | |
### Prompt String (PS1) when the host needs a reboot. Color changes from green | |
### to red, depending on how many hours the host has | |
### | |
### Ex. craigbender@hpz600:~ ⏻ | |
### | |
### PS1R - Red ⏻ - Host has needed a reboot for > 24 hours | |
### PS1Y - Yellow ⏻ - Host has needed a reboot for > 12 hours but < 24 hours | |
### PS1G - Green ⏻ - Host has needed a reboot < 12 hours | |
### | |
### Add this code to the end of $HOME/.bashrc, then `source ~/.bashrc` | |
### | |
############################################################################################# | |
# Default Ubuntu/Debian Primary Prompt String | |
export PS1_NORM='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
# Color-coded with UTF-8 power symbole | |
export PS1R='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\e[1;38;2;255;0;0m ⏻ \[\033[00m\]\$ ' | |
export PS1Y='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\e[1;38;2;255;255;0m ⏻ \[\033[00m\]\$ ' | |
export PS1G='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\e[1;38;2;0;255;0m ⏻ \[\033[00m\]\$ ' | |
check-hsr() { | |
[[ -f /var/run/reboot-required ]] && { export HSR=$(bc <<< "($(date +%s)-$(stat -c '%W' /var/run/reboot-required))/3600"); } || { export HSR=0; } | |
[[ $HSR -ge 24 ]] && { export PS1=$PS1R; } | |
[[ $HSR -ge 12 && $HSR -lt 24 ]] && { export PS1=$PS1Y; } | |
[[ $HSR -lt 12 ]] && { export PS1=$PS1R; } | |
[[ $HSR -eq 0 ]] && { export PS1=$PS1_NORM; } | |
};export -f check-hsr | |
# Use prompt_command to determine hours since reboot-required (HSR) and set the appropriate prompt | |
[[ ${PROMPT_COMMAND: -1} = ';' ]] && { export PROMPT_COMMAND+="check-hsr"; } || { export PROMPT_COMMAND+=";check-hsr"; } |
Author
ThinGuy
commented
May 5, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment