Created
November 12, 2018 10:38
-
-
Save JordanAdams/2c65115b3c0ffb6a11045981bd5fbf25 to your computer and use it in GitHub Desktop.
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
LOW_BATTERY_THRESHOLD=20 | |
NEWLINE='\n' | |
ICON_GITHUB="\ue725" | |
ICON_LOW_BATTERY="\uf579" | |
current_branch() { | |
echo $(git branch | grep '* ' | sed 's/* //') | |
} | |
prompt_dir() { | |
if [[ $(pwd) == $HOME ]] | |
then | |
echo "~" | |
else | |
basename=$(pwd | xargs basename | sed 's/^\///') | |
parent_path=$(cd .. && pwd | sed 's/\/$//' | sed 's,^'"$HOME"',~,') | |
echo "%F{008}$parent_path%f/$basename" | |
fi | |
} | |
git_is_clean() { | |
[[ -z $(git status -s) ]] | |
} | |
is_git_directory() { | |
[ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1 | |
} | |
battery_level() { | |
pmset -g batt | grep -Eo "\d+%" | cut -d% -f1 | |
} | |
prompt_git() { | |
if is_git_directory && git_is_clean; then | |
echo " %F{008}on%f %F{green}$(current_branch) $ICON_GITHUB%f" | |
elif is_git_directory; then | |
echo " %F{008}on%f %F{red}$(current_branch) $ICON_GITHUB%f" | |
fi | |
} | |
prompt_rainbow_arrow() { | |
echo "%F{red}⟫%F{yellow}⟫%F{green}⟫%F{blue}⟫%F{098}⟫%f" | |
} | |
prompt_battery() { | |
if [[ $(battery_level) -lt $LOW_BATTERY_THRESHOLD ]]; then | |
echo "%F{008} | %F{red}$ICON_LOW_BATTERY %F{008}(low battery)%f" | |
fi | |
} | |
prompt_mode() { | |
[[ $1 != "" ]] && echo " %F{008}(%F{003}$1%F{008})%f" | |
} | |
prompt_left() { | |
echo "$NEWLINE $(prompt_dir)$(prompt_git)$(prompt_battery)$(prompt_mode $1)$NEWLINE $(prompt_rainbow_arrow) " | |
} | |
precmd() { | |
PROMPT="$(prompt_left)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment