shfmt agnoster theme

pull/1697/head
Noah Gorny 2020-10-31 22:09:11 +02:00 committed by Noah Gorny
parent ae9da3b62b
commit 60da498ed4
1 changed files with 196 additions and 198 deletions

View File

@ -71,7 +71,7 @@ PROMPT_DIRTRIM=2 # bash4 and above
DEBUG=0 DEBUG=0
debug() { debug() {
if [[ ${DEBUG} -ne 0 ]]; then if [[ ${DEBUG} -ne 0 ]]; then
>&2 echo -e $* echo >&2 -e $*
fi fi
} }
@ -88,9 +88,9 @@ RIGHT_SUBSEG=''
text_effect() { text_effect() {
case "$1" in case "$1" in
reset) echo 0;; reset) echo 0 ;;
bold) echo 1;; bold) echo 1 ;;
underline) echo 4;; underline) echo 4 ;;
esac esac
} }
@ -99,30 +99,30 @@ text_effect() {
# under the "256 (8-bit) Colors" section, and follow the example for orange below # under the "256 (8-bit) Colors" section, and follow the example for orange below
fg_color() { fg_color() {
case "$1" in case "$1" in
black) echo 30;; black) echo 30 ;;
red) echo 31;; red) echo 31 ;;
green) echo 32;; green) echo 32 ;;
yellow) echo 33;; yellow) echo 33 ;;
blue) echo 34;; blue) echo 34 ;;
magenta) echo 35;; magenta) echo 35 ;;
cyan) echo 36;; cyan) echo 36 ;;
white) echo 37;; white) echo 37 ;;
orange) echo 38\;5\;166;; orange) echo 38\;5\;166 ;;
esac esac
} }
bg_color() { bg_color() {
case "$1" in case "$1" in
black) echo 40;; black) echo 40 ;;
red) echo 41;; red) echo 41 ;;
green) echo 42;; green) echo 42 ;;
yellow) echo 43;; yellow) echo 43 ;;
blue) echo 44;; blue) echo 44 ;;
magenta) echo 45;; magenta) echo 45 ;;
cyan) echo 46;; cyan) echo 46 ;;
white) echo 47;; white) echo 47 ;;
orange) echo 48\;5\;166;; orange) echo 48\;5\;166 ;;
esac; esac
} }
# TIL: declare is global not local, so best use a different name # TIL: declare is global not local, so best use a different name
@ -210,18 +210,17 @@ prompt_virtualenv() {
if [[ -n $VIRTUAL_ENV ]]; then if [[ -n $VIRTUAL_ENV ]]; then
color=cyan color=cyan
prompt_segment $color $PRIMARY_FG prompt_segment $color $PRIMARY_FG
ve=`basename "$VIRTUAL_ENV"` ve=$(basename "$VIRTUAL_ENV")
prompt_segment $color white "$ve" prompt_segment $color white "$ve"
fi fi
} }
### Prompt components ### Prompt components
# Each component will draw itself, and hide itself if no information needs to be shown # Each component will draw itself, and hide itself if no information needs to be shown
# Context: user@hostname (who am I and where am I) # Context: user@hostname (who am I and where am I)
prompt_context() { prompt_context() {
local user=`whoami` local user=$(whoami)
if [[ $user != $DEFAULT_USER || -n $SSH_CLIENT ]]; then if [[ $user != $DEFAULT_USER || -n $SSH_CLIENT ]]; then
prompt_segment black default "$user@\h" prompt_segment black default "$user@\h"
@ -234,7 +233,6 @@ prompt_histdt() {
prompt_segment black default "\! [\A]" prompt_segment black default "\! [\A]"
} }
git_status_dirty() { git_status_dirty() {
dirty=$(git status -s 2> /dev/null | tail -n 1) dirty=$(git status -s 2> /dev/null | tail -n 1)
[[ -n $dirty ]] && echo " ●" [[ -n $dirty ]] && echo " ●"
@ -243,10 +241,10 @@ git_status_dirty() {
# Git: branch/detached head, dirty status # Git: branch/detached head, dirty status
prompt_git() { prompt_git() {
local ref dirty local ref dirty
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then if $(git rev-parse --is-inside-work-tree > /dev/null 2>&1); then
ZSH_THEME_GIT_PROMPT_DIRTY='±' ZSH_THEME_GIT_PROMPT_DIRTY='±'
dirty=$(git_status_dirty) dirty=$(git_status_dirty)
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="$(git show-ref --head -s --abbrev |head -n1 2> /dev/null)" ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="$(git show-ref --head -s --abbrev | head -n1 2> /dev/null)"
if [[ -n $dirty ]]; then if [[ -n $dirty ]]; then
prompt_segment yellow black prompt_segment yellow black
else else
@ -293,7 +291,7 @@ __command_rprompt() {
[ $n -gt 40 ] || break [ $n -gt 40 ] || break
times="$times ${tz%%:*}\e[30;1m:\e[0;36;1m" times="$times ${tz%%:*}\e[30;1m:\e[0;36;1m"
times="$times$(TZ=${tz#*:} date +%H:%M)\e[0m" times="$times$(TZ=${tz#*:} date +%H:%M)\e[0m"
n=$(( $n - 10 )) n=$(($n - 10))
done done
[ -z "$times" ] || printf "%${n}s$times\\r" '' [ -z "$times" ] || printf "%${n}s$times\\r" ''
} }
@ -353,7 +351,7 @@ prompt_right_segment() {
# if [[ $CURRENT_RBG != NONE && $1 != $CURRENT_RBG ]]; then # if [[ $CURRENT_RBG != NONE && $1 != $CURRENT_RBG ]]; then
# $CURRENT_RBG= # $CURRENT_RBG=
# fi # fi
declare -a intermediate2=($(fg_color $1) $(bg_color $CURRENT_RBG) ) declare -a intermediate2=($(fg_color $1) $(bg_color $CURRENT_RBG))
# PRIGHT="$PRIGHT---" # PRIGHT="$PRIGHT---"
debug "pre prompt " $(ansi_r intermediate2[@]) debug "pre prompt " $(ansi_r intermediate2[@])
PRIGHT="$PRIGHT$(ansi_r intermediate2[@])$RIGHT_SEPARATOR" PRIGHT="$PRIGHT$(ansi_r intermediate2[@])$RIGHT_SEPARATOR"