commit
d97a36af88
|
|
@ -25,6 +25,7 @@ lint_clean_files.sh
|
||||||
|
|
||||||
# themes
|
# themes
|
||||||
#
|
#
|
||||||
|
themes/agnoster
|
||||||
themes/90210
|
themes/90210
|
||||||
themes/powerline
|
themes/powerline
|
||||||
themes/barbuk
|
themes/barbuk
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -132,7 +132,7 @@ ansi() {
|
||||||
local seq
|
local seq
|
||||||
declare -a mycodes=("${!1}")
|
declare -a mycodes=("${!1}")
|
||||||
|
|
||||||
debug "ansi: ${!1} all: $* aka ${mycodes[@]}"
|
debug "ansi: ${!1} all: $* aka " "${mycodes[@]}"
|
||||||
|
|
||||||
seq=""
|
seq=""
|
||||||
for ((i = 0; i < ${#mycodes[@]}; i++)); do
|
for ((i = 0; i < ${#mycodes[@]}; i++)); do
|
||||||
|
|
@ -141,13 +141,13 @@ ansi() {
|
||||||
fi
|
fi
|
||||||
seq="${seq}${mycodes[$i]}"
|
seq="${seq}${mycodes[$i]}"
|
||||||
done
|
done
|
||||||
debug "ansi debug:" '\\[\\033['${seq}'m\\]'
|
debug "ansi debug:" '\\[\\033['"${seq}"'m\\]'
|
||||||
echo -ne '\[\033['${seq}'m\]'
|
echo -ne '\[\033['"${seq}"'m\]'
|
||||||
# PR="$PR\[\033[${seq}m\]"
|
# PR="$PR\[\033[${seq}m\]"
|
||||||
}
|
}
|
||||||
|
|
||||||
ansi_single() {
|
ansi_single() {
|
||||||
echo -ne '\[\033['$1'm\]'
|
echo -ne '\[\033['"$1"'m\]'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Begin a segment
|
# Begin a segment
|
||||||
|
|
@ -164,30 +164,30 @@ prompt_segment() {
|
||||||
# prompt_status - Erik 1/14/17
|
# prompt_status - Erik 1/14/17
|
||||||
|
|
||||||
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
||||||
codes=("${codes[@]}" $(text_effect reset))
|
codes=("${codes[@]}" "$(text_effect reset)")
|
||||||
# fi
|
# fi
|
||||||
if [[ -n $1 ]]; then
|
if [[ -n $1 ]]; then
|
||||||
bg=$(bg_color $1)
|
bg=$(bg_color "$1")
|
||||||
codes=("${codes[@]}" $bg)
|
codes=("${codes[@]}" "$bg")
|
||||||
debug "Added $bg as background to codes"
|
debug "Added $bg as background to codes"
|
||||||
fi
|
fi
|
||||||
if [[ -n $2 ]]; then
|
if [[ -n $2 ]]; then
|
||||||
fg=$(fg_color $2)
|
fg=$(fg_color "$2")
|
||||||
codes=("${codes[@]}" $fg)
|
codes=("${codes[@]}" "$fg")
|
||||||
debug "Added $fg as foreground to codes"
|
debug "Added $fg as foreground to codes"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
debug "Codes: "
|
debug "Codes: "
|
||||||
# declare -p codes
|
# declare -p codes
|
||||||
|
|
||||||
if [[ $CURRENT_BG != NONE && $1 != $CURRENT_BG ]]; then
|
if [[ $CURRENT_BG != NONE && $1 != "$CURRENT_BG" ]]; then
|
||||||
declare -a intermediate=($(fg_color $CURRENT_BG) $(bg_color $1))
|
declare -a intermediate=("$(fg_color $CURRENT_BG)" "$(bg_color "$1")")
|
||||||
debug "pre prompt " $(ansi intermediate[@])
|
debug "pre prompt " "$(ansi intermediate[@])"
|
||||||
PR="$PR $(ansi intermediate[@])$SEGMENT_SEPARATOR"
|
PR="$PR $(ansi intermediate[@])$SEGMENT_SEPARATOR"
|
||||||
debug "post prompt " $(ansi codes[@])
|
debug "post prompt " "$(ansi codes[@])"
|
||||||
PR="$PR$(ansi codes[@]) "
|
PR="$PR$(ansi codes[@]) "
|
||||||
else
|
else
|
||||||
debug "no current BG, codes is $codes[@]"
|
debug "no current BG, codes is " "${codes[@]}"
|
||||||
PR="$PR$(ansi codes[@]) "
|
PR="$PR$(ansi codes[@]) "
|
||||||
fi
|
fi
|
||||||
CURRENT_BG=$1
|
CURRENT_BG=$1
|
||||||
|
|
@ -197,10 +197,10 @@ prompt_segment() {
|
||||||
# End the prompt, closing any open segments
|
# End the prompt, closing any open segments
|
||||||
prompt_end() {
|
prompt_end() {
|
||||||
if [[ -n $CURRENT_BG ]]; then
|
if [[ -n $CURRENT_BG ]]; then
|
||||||
declare -a codes=($(text_effect reset) $(fg_color $CURRENT_BG))
|
declare -a codes=("$(text_effect reset)" "$(fg_color "$CURRENT_BG")")
|
||||||
PR="$PR $(ansi codes[@])$SEGMENT_SEPARATOR"
|
PR="$PR $(ansi codes[@])$SEGMENT_SEPARATOR"
|
||||||
fi
|
fi
|
||||||
declare -a reset=($(text_effect reset))
|
declare -a reset=("$(text_effect reset)")
|
||||||
PR="$PR $(ansi reset[@])"
|
PR="$PR $(ansi reset[@])"
|
||||||
CURRENT_BG=''
|
CURRENT_BG=''
|
||||||
}
|
}
|
||||||
|
|
@ -209,21 +209,20 @@ prompt_end() {
|
||||||
prompt_virtualenv() {
|
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"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
@ -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
|
||||||
|
|
@ -268,11 +266,11 @@ prompt_dir() {
|
||||||
prompt_status() {
|
prompt_status() {
|
||||||
local symbols
|
local symbols
|
||||||
symbols=()
|
symbols=()
|
||||||
[[ $RETVAL -ne 0 ]] && symbols+="$(ansi_single $(fg_color red))✘"
|
[[ $RETVAL -ne 0 ]] && symbols+=("$(ansi_single "$(fg_color red)")✘")
|
||||||
[[ $UID -eq 0 ]] && symbols+="$(ansi_single $(fg_color yellow))⚡"
|
[[ $UID -eq 0 ]] && symbols+=("$(ansi_single "$(fg_color yellow)")⚡")
|
||||||
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="$(ansi_single $(fg_color cyan))⚙"
|
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+=("$(ansi_single "$(fg_color cyan)")⚙")
|
||||||
|
|
||||||
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
|
[[ -n "${symbols[*]}" ]] && prompt_segment black default "${symbols[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
@ -287,13 +285,13 @@ rightprompt() {
|
||||||
|
|
||||||
# quick right prompt I grabbed to test things.
|
# quick right prompt I grabbed to test things.
|
||||||
__command_rprompt() {
|
__command_rprompt() {
|
||||||
local times= n=$COLUMNS tz
|
local times=n=$COLUMNS tz
|
||||||
for tz in ZRH:Europe/Zurich PIT:US/Eastern \
|
for tz in ZRH:Europe/Zurich PIT:US/Eastern \
|
||||||
MTV:US/Pacific TOK:Asia/Tokyo; do
|
MTV:US/Pacific TOK:Asia/Tokyo; do
|
||||||
[ $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" ''
|
||||||
}
|
}
|
||||||
|
|
@ -304,7 +302,7 @@ ansi_r() {
|
||||||
local seq
|
local seq
|
||||||
declare -a mycodes2=("${!1}")
|
declare -a mycodes2=("${!1}")
|
||||||
|
|
||||||
debug "ansi: ${!1} all: $* aka ${mycodes2[@]}"
|
debug "ansi: ${!1} all: $* aka " "${mycodes2[@]}"
|
||||||
|
|
||||||
seq=""
|
seq=""
|
||||||
for ((i = 0; i < ${#mycodes2[@]}; i++)); do
|
for ((i = 0; i < ${#mycodes2[@]}; i++)); do
|
||||||
|
|
@ -313,8 +311,8 @@ ansi_r() {
|
||||||
fi
|
fi
|
||||||
seq="${seq}${mycodes2[$i]}"
|
seq="${seq}${mycodes2[$i]}"
|
||||||
done
|
done
|
||||||
debug "ansi debug:" '\\[\\033['${seq}'m\\]'
|
debug "ansi debug:" '\\[\\033['"${seq}"'m\\]'
|
||||||
echo -ne '\033['${seq}'m'
|
echo -ne '\033['"${seq}"'m'
|
||||||
# PR="$PR\[\033[${seq}m\]"
|
# PR="$PR\[\033[${seq}m\]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -333,16 +331,16 @@ prompt_right_segment() {
|
||||||
# prompt_status - Erik 1/14/17
|
# prompt_status - Erik 1/14/17
|
||||||
|
|
||||||
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
||||||
codes=("${codes[@]}" $(text_effect reset))
|
codes=("${codes[@]}" "$(text_effect reset)")
|
||||||
# fi
|
# fi
|
||||||
if [[ -n $1 ]]; then
|
if [[ -n $1 ]]; then
|
||||||
bg=$(bg_color $1)
|
bg=$(bg_color "$1")
|
||||||
codes=("${codes[@]}" $bg)
|
codes=("${codes[@]}" "$bg")
|
||||||
debug "Added $bg as background to codes"
|
debug "Added $bg as background to codes"
|
||||||
fi
|
fi
|
||||||
if [[ -n $2 ]]; then
|
if [[ -n $2 ]]; then
|
||||||
fg=$(fg_color $2)
|
fg=$(fg_color "$2")
|
||||||
codes=("${codes[@]}" $fg)
|
codes=("${codes[@]}" "$fg")
|
||||||
debug "Added $fg as foreground to codes"
|
debug "Added $fg as foreground to codes"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -353,11 +351,11 @@ 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"
|
||||||
debug "post prompt " $(ansi_r codes[@])
|
debug "post prompt " "$(ansi_r codes[@])"
|
||||||
PRIGHT="$PRIGHT$(ansi_r codes[@]) "
|
PRIGHT="$PRIGHT$(ansi_r codes[@]) "
|
||||||
# else
|
# else
|
||||||
# debug "no current BG, codes is $codes[@]"
|
# debug "no current BG, codes is $codes[@]"
|
||||||
|
|
@ -393,7 +391,7 @@ prompt_emacsdir() {
|
||||||
## Main prompt
|
## Main prompt
|
||||||
|
|
||||||
build_prompt() {
|
build_prompt() {
|
||||||
[[ ! -z ${AG_EMACS_DIR+x} ]] && prompt_emacsdir
|
[[ -n ${AG_EMACS_DIR+x} ]] && prompt_emacsdir
|
||||||
prompt_status
|
prompt_status
|
||||||
#[[ -z ${AG_NO_HIST+x} ]] && prompt_histdt
|
#[[ -z ${AG_NO_HIST+x} ]] && prompt_histdt
|
||||||
[[ -z ${AG_NO_CONTEXT+x} ]] && prompt_context
|
[[ -z ${AG_NO_CONTEXT+x} ]] && prompt_context
|
||||||
|
|
@ -413,7 +411,7 @@ set_bash_prompt() {
|
||||||
PR=""
|
PR=""
|
||||||
PRIGHT=""
|
PRIGHT=""
|
||||||
CURRENT_BG=NONE
|
CURRENT_BG=NONE
|
||||||
PR="$(ansi_single $(text_effect reset))"
|
PR="$(ansi_single "$(text_effect reset)")"
|
||||||
build_prompt
|
build_prompt
|
||||||
|
|
||||||
# uncomment below to use right prompt
|
# uncomment below to use right prompt
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue