Merge branch 'master' into hooks/sh_dotbash
commit
3f751eb528
|
|
@ -11,7 +11,7 @@ jobs:
|
|||
bats-test:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15, macos-11.0]
|
||||
os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@ lint_clean_files.sh
|
|||
|
||||
# themes
|
||||
#
|
||||
themes/agnoster
|
||||
themes/90210
|
||||
themes/powerline
|
||||
themes/barbuk
|
||||
|
||||
# plugins
|
||||
#
|
||||
|
|
|
|||
|
|
@ -6,33 +6,36 @@ _sdkman_complete()
|
|||
COMPREPLY=()
|
||||
|
||||
if [ $COMP_CWORD -eq 1 ]; then
|
||||
COMPREPLY=( $(compgen -W "install uninstall rm list ls use current outdated version default selfupdate broadcast offline help flush" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
COMPREPLY=( $(compgen -W "install uninstall rm list ls use default home env current upgrade ug version broadcast help offline selfupdate update flush" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
elif [ $COMP_CWORD -eq 2 ]; then
|
||||
case "${COMP_WORDS[COMP_CWORD-1]}" in
|
||||
"install" | "uninstall" | "rm" | "list" | "ls" | "use" | "current" | "outdated" )
|
||||
"install" | "i" | "uninstall" | "rm" | "list" | "ls" | "use" | "u" | "default" | "d" | "home" | "h" | "current" | "c" | "upgrade" | "ug" )
|
||||
CANDIDATES=$(echo "${SDKMAN_CANDIDATES_CSV}" | tr ',' ' ')
|
||||
COMPREPLY=( $(compgen -W "$CANDIDATES" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
;;
|
||||
"env" )
|
||||
COMPREPLY=( $(compgen -W "init" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
;;
|
||||
"offline" )
|
||||
COMPREPLY=( $(compgen -W "enable disable" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
;;
|
||||
"selfupdate" )
|
||||
COMPREPLY=( $(compgen -W "force" -P "[" -S "]" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
COMPREPLY=( $(compgen -W "force" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
;;
|
||||
"flush" )
|
||||
COMPREPLY=( $(compgen -W "candidates broadcast archives temp" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
COMPREPLY=( $(compgen -W "archives tmp broadcast version" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
elif [ $COMP_CWORD -eq 3 ]; then
|
||||
case "${COMP_WORDS[COMP_CWORD-2]}" in
|
||||
"uninstall" | "rm" | "use" | "default" )
|
||||
_sdkman_candidate_versions ${COMP_WORDS[COMP_CWORD-1]}
|
||||
"uninstall" | "rm" | "use" | "u" | "default" | "d" | "home" | "h" )
|
||||
_sdkman_candidate_local_versions ${COMP_WORDS[COMP_CWORD-1]}
|
||||
COMPREPLY=( $(compgen -W "$CANDIDATE_VERSIONS" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
;;
|
||||
"install")
|
||||
_sdkman_candidate_not_installed_versions ${COMP_WORDS[COMP_CWORD-1]}
|
||||
"install" | "i" )
|
||||
_sdkman_candidate_all_versions ${COMP_WORDS[COMP_CWORD-1]}
|
||||
COMPREPLY=( $(compgen -W "$CANDIDATE_VERSIONS" -- ${COMP_WORDS[COMP_CWORD]}) )
|
||||
;;
|
||||
*)
|
||||
|
|
@ -43,24 +46,22 @@ _sdkman_complete()
|
|||
return 0
|
||||
}
|
||||
|
||||
_sdkman_candidate_versions(){
|
||||
_sdkman_candidate_local_versions(){
|
||||
|
||||
CANDIDATE_VERSIONS=$(__sdkman_cleanup_local_versions $1)
|
||||
|
||||
}
|
||||
|
||||
_sdkman_candidate_all_versions(){
|
||||
|
||||
CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions $1)
|
||||
if [ "$SDKMAN_OFFLINE_MODE" = "true" ]; then
|
||||
CANDIDATE_VERSIONS=$CANDIDATE_LOCAL_VERSIONS
|
||||
else
|
||||
CANDIDATE_ONLINE_VERSIONS="$(curl -s "${SDKMAN_SERVICE}/candidates/$1" | tr ',' ' ')"
|
||||
CANDIDATE_VERSIONS="$(echo $CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS |sort | uniq ) "
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
_sdkman_candidate_not_installed_versions(){
|
||||
CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions $1)
|
||||
if [ "$SDKMAN_OFFLINE_MODE" = "false" ]; then
|
||||
CANDIDATE_ONLINE_VERSIONS="$(__sdkman_list_versions $1 | grep " " | grep "\." | cut -c 6-)"
|
||||
CANDIDATE_ONLINE_VERSIONS="$(__sdkman_list_versions $1 | grep " " | grep "\." | cut -c 62-)"
|
||||
CANDIDATE_VERSIONS="$(echo $CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS | tr ' ' '\n' | sort | uniq -u) "
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
__sdkman_cleanup_local_versions(){
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ PROMPT_DIRTRIM=2 # bash4 and above
|
|||
######################################################################
|
||||
DEBUG=0
|
||||
debug() {
|
||||
if [[ ${DEBUG} -ne 0 ]]; then
|
||||
>&2 echo -e $*
|
||||
fi
|
||||
if [[ ${DEBUG} -ne 0 ]]; then
|
||||
echo >&2 -e "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
######################################################################
|
||||
|
|
@ -87,178 +87,176 @@ LEFT_SUBSEG=''
|
|||
RIGHT_SUBSEG=''
|
||||
|
||||
text_effect() {
|
||||
case "$1" in
|
||||
reset) echo 0;;
|
||||
bold) echo 1;;
|
||||
underline) echo 4;;
|
||||
esac
|
||||
case "$1" in
|
||||
reset) echo 0 ;;
|
||||
bold) echo 1 ;;
|
||||
underline) echo 4 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# to add colors, see
|
||||
# http://bitmote.com/index.php?post/2012/11/19/Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux
|
||||
# under the "256 (8-bit) Colors" section, and follow the example for orange below
|
||||
fg_color() {
|
||||
case "$1" in
|
||||
black) echo 30;;
|
||||
red) echo 31;;
|
||||
green) echo 32;;
|
||||
yellow) echo 33;;
|
||||
blue) echo 34;;
|
||||
magenta) echo 35;;
|
||||
cyan) echo 36;;
|
||||
white) echo 37;;
|
||||
orange) echo 38\;5\;166;;
|
||||
esac
|
||||
case "$1" in
|
||||
black) echo 30 ;;
|
||||
red) echo 31 ;;
|
||||
green) echo 32 ;;
|
||||
yellow) echo 33 ;;
|
||||
blue) echo 34 ;;
|
||||
magenta) echo 35 ;;
|
||||
cyan) echo 36 ;;
|
||||
white) echo 37 ;;
|
||||
orange) echo 38\;5\;166 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
bg_color() {
|
||||
case "$1" in
|
||||
black) echo 40;;
|
||||
red) echo 41;;
|
||||
green) echo 42;;
|
||||
yellow) echo 43;;
|
||||
blue) echo 44;;
|
||||
magenta) echo 45;;
|
||||
cyan) echo 46;;
|
||||
white) echo 47;;
|
||||
orange) echo 48\;5\;166;;
|
||||
esac;
|
||||
case "$1" in
|
||||
black) echo 40 ;;
|
||||
red) echo 41 ;;
|
||||
green) echo 42 ;;
|
||||
yellow) echo 43 ;;
|
||||
blue) echo 44 ;;
|
||||
magenta) echo 45 ;;
|
||||
cyan) echo 46 ;;
|
||||
white) echo 47 ;;
|
||||
orange) echo 48\;5\;166 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# TIL: declare is global not local, so best use a different name
|
||||
# for codes (mycodes) as otherwise it'll clobber the original.
|
||||
# this changes from BASH v3 to BASH v4.
|
||||
ansi() {
|
||||
local seq
|
||||
declare -a mycodes=("${!1}")
|
||||
local seq
|
||||
declare -a mycodes=("${!1}")
|
||||
|
||||
debug "ansi: ${!1} all: $* aka ${mycodes[@]}"
|
||||
debug "ansi: ${!1} all: $* aka " "${mycodes[@]}"
|
||||
|
||||
seq=""
|
||||
for ((i = 0; i < ${#mycodes[@]}; i++)); do
|
||||
if [[ -n $seq ]]; then
|
||||
seq="${seq};"
|
||||
fi
|
||||
seq="${seq}${mycodes[$i]}"
|
||||
done
|
||||
debug "ansi debug:" '\\[\\033['${seq}'m\\]'
|
||||
echo -ne '\[\033['${seq}'m\]'
|
||||
# PR="$PR\[\033[${seq}m\]"
|
||||
seq=""
|
||||
for ((i = 0; i < ${#mycodes[@]}; i++)); do
|
||||
if [[ -n $seq ]]; then
|
||||
seq="${seq};"
|
||||
fi
|
||||
seq="${seq}${mycodes[$i]}"
|
||||
done
|
||||
debug "ansi debug:" '\\[\\033['"${seq}"'m\\]'
|
||||
echo -ne '\[\033['"${seq}"'m\]'
|
||||
# PR="$PR\[\033[${seq}m\]"
|
||||
}
|
||||
|
||||
ansi_single() {
|
||||
echo -ne '\[\033['$1'm\]'
|
||||
echo -ne '\[\033['"$1"'m\]'
|
||||
}
|
||||
|
||||
# Begin a segment
|
||||
# Takes two arguments, background and foreground. Both can be omitted,
|
||||
# rendering default background/foreground.
|
||||
prompt_segment() {
|
||||
local bg fg
|
||||
declare -a codes
|
||||
local bg fg
|
||||
declare -a codes
|
||||
|
||||
debug "Prompting $1 $2 $3"
|
||||
debug "Prompting $1 $2 $3"
|
||||
|
||||
# if commented out from kruton's original... I'm not clear
|
||||
# if it did anything, but it messed up things like
|
||||
# prompt_status - Erik 1/14/17
|
||||
# if commented out from kruton's original... I'm not clear
|
||||
# if it did anything, but it messed up things like
|
||||
# prompt_status - Erik 1/14/17
|
||||
|
||||
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
||||
codes=("${codes[@]}" $(text_effect reset))
|
||||
# fi
|
||||
if [[ -n $1 ]]; then
|
||||
bg=$(bg_color $1)
|
||||
codes=("${codes[@]}" $bg)
|
||||
debug "Added $bg as background to codes"
|
||||
fi
|
||||
if [[ -n $2 ]]; then
|
||||
fg=$(fg_color $2)
|
||||
codes=("${codes[@]}" $fg)
|
||||
debug "Added $fg as foreground to codes"
|
||||
fi
|
||||
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
||||
codes=("${codes[@]}" "$(text_effect reset)")
|
||||
# fi
|
||||
if [[ -n $1 ]]; then
|
||||
bg=$(bg_color "$1")
|
||||
codes=("${codes[@]}" "$bg")
|
||||
debug "Added $bg as background to codes"
|
||||
fi
|
||||
if [[ -n $2 ]]; then
|
||||
fg=$(fg_color "$2")
|
||||
codes=("${codes[@]}" "$fg")
|
||||
debug "Added $fg as foreground to codes"
|
||||
fi
|
||||
|
||||
debug "Codes: "
|
||||
# declare -p codes
|
||||
debug "Codes: "
|
||||
# declare -p codes
|
||||
|
||||
if [[ $CURRENT_BG != NONE && $1 != $CURRENT_BG ]]; then
|
||||
declare -a intermediate=($(fg_color $CURRENT_BG) $(bg_color $1))
|
||||
debug "pre prompt " $(ansi intermediate[@])
|
||||
PR="$PR $(ansi intermediate[@])$SEGMENT_SEPARATOR"
|
||||
debug "post prompt " $(ansi codes[@])
|
||||
PR="$PR$(ansi codes[@]) "
|
||||
else
|
||||
debug "no current BG, codes is $codes[@]"
|
||||
PR="$PR$(ansi codes[@]) "
|
||||
fi
|
||||
CURRENT_BG=$1
|
||||
[[ -n $3 ]] && PR="$PR$3"
|
||||
if [[ $CURRENT_BG != NONE && $1 != "$CURRENT_BG" ]]; then
|
||||
declare -a intermediate=("$(fg_color $CURRENT_BG)" "$(bg_color "$1")")
|
||||
debug "pre prompt " "$(ansi intermediate[@])"
|
||||
PR="$PR $(ansi intermediate[@])$SEGMENT_SEPARATOR"
|
||||
debug "post prompt " "$(ansi codes[@])"
|
||||
PR="$PR$(ansi codes[@]) "
|
||||
else
|
||||
debug "no current BG, codes is " "${codes[@]}"
|
||||
PR="$PR$(ansi codes[@]) "
|
||||
fi
|
||||
CURRENT_BG=$1
|
||||
[[ -n $3 ]] && PR="$PR$3"
|
||||
}
|
||||
|
||||
# End the prompt, closing any open segments
|
||||
prompt_end() {
|
||||
if [[ -n $CURRENT_BG ]]; then
|
||||
declare -a codes=($(text_effect reset) $(fg_color $CURRENT_BG))
|
||||
PR="$PR $(ansi codes[@])$SEGMENT_SEPARATOR"
|
||||
fi
|
||||
declare -a reset=($(text_effect reset))
|
||||
PR="$PR $(ansi reset[@])"
|
||||
CURRENT_BG=''
|
||||
if [[ -n $CURRENT_BG ]]; then
|
||||
declare -a codes=("$(text_effect reset)" "$(fg_color "$CURRENT_BG")")
|
||||
PR="$PR $(ansi codes[@])$SEGMENT_SEPARATOR"
|
||||
fi
|
||||
declare -a reset=("$(text_effect reset)")
|
||||
PR="$PR $(ansi reset[@])"
|
||||
CURRENT_BG=''
|
||||
}
|
||||
|
||||
### virtualenv prompt
|
||||
prompt_virtualenv() {
|
||||
if [[ -n $VIRTUAL_ENV ]]; then
|
||||
color=cyan
|
||||
prompt_segment $color $PRIMARY_FG
|
||||
ve=`basename "$VIRTUAL_ENV"`
|
||||
prompt_segment $color white "$ve"
|
||||
fi
|
||||
if [[ -n $VIRTUAL_ENV ]]; then
|
||||
color=cyan
|
||||
prompt_segment $color "$PRIMARY_FG"
|
||||
ve=$(basename "$VIRTUAL_ENV")
|
||||
prompt_segment $color white "$ve"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
### Prompt components
|
||||
# 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)
|
||||
prompt_context() {
|
||||
local user=`whoami`
|
||||
local user=$(whoami)
|
||||
|
||||
if [[ $user != $DEFAULT_USER || -n $SSH_CLIENT ]]; then
|
||||
prompt_segment black default "$user@\h"
|
||||
fi
|
||||
if [[ $user != "$DEFAULT_USER" || -n $SSH_CLIENT ]]; then
|
||||
prompt_segment black default "$user@\h"
|
||||
fi
|
||||
}
|
||||
|
||||
# prints history followed by HH:MM, useful for remembering what
|
||||
# we did previously
|
||||
prompt_histdt() {
|
||||
prompt_segment black default "\! [\A]"
|
||||
prompt_segment black default "\! [\A]"
|
||||
}
|
||||
|
||||
|
||||
git_status_dirty() {
|
||||
dirty=$(git status -s 2> /dev/null | tail -n 1)
|
||||
[[ -n $dirty ]] && echo " ●"
|
||||
dirty=$(git status -s 2> /dev/null | tail -n 1)
|
||||
[[ -n $dirty ]] && echo " ●"
|
||||
}
|
||||
|
||||
# Git: branch/detached head, dirty status
|
||||
prompt_git() {
|
||||
local ref dirty
|
||||
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
|
||||
ZSH_THEME_GIT_PROMPT_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)"
|
||||
if [[ -n $dirty ]]; then
|
||||
prompt_segment yellow black
|
||||
else
|
||||
prompt_segment green black
|
||||
fi
|
||||
PR="$PR${ref/refs\/heads\// }$dirty"
|
||||
fi
|
||||
local ref dirty
|
||||
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
||||
ZSH_THEME_GIT_PROMPT_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)"
|
||||
if [[ -n $dirty ]]; then
|
||||
prompt_segment yellow black
|
||||
else
|
||||
prompt_segment green black
|
||||
fi
|
||||
PR="$PR${ref/refs\/heads\// }$dirty"
|
||||
fi
|
||||
}
|
||||
|
||||
# Dir: current working directory
|
||||
prompt_dir() {
|
||||
prompt_segment blue black '\w'
|
||||
prompt_segment blue black '\w'
|
||||
}
|
||||
|
||||
# Status:
|
||||
|
|
@ -266,13 +264,13 @@ prompt_dir() {
|
|||
# - am I root
|
||||
# - are there background jobs?
|
||||
prompt_status() {
|
||||
local symbols
|
||||
symbols=()
|
||||
[[ $RETVAL -ne 0 ]] && symbols+="$(ansi_single $(fg_color red))✘"
|
||||
[[ $UID -eq 0 ]] && symbols+="$(ansi_single $(fg_color yellow))⚡"
|
||||
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="$(ansi_single $(fg_color cyan))⚙"
|
||||
local symbols
|
||||
symbols=()
|
||||
[[ $RETVAL -ne 0 ]] && symbols+=("$(ansi_single "$(fg_color red)")✘")
|
||||
[[ $UID -eq 0 ]] && symbols+=("$(ansi_single "$(fg_color yellow)")⚡")
|
||||
[[ $(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[@]}"
|
||||
}
|
||||
|
||||
######################################################################
|
||||
|
|
@ -282,89 +280,89 @@ prompt_status() {
|
|||
# doesn't quite work per above
|
||||
|
||||
rightprompt() {
|
||||
printf "%*s" $COLUMNS "$PRIGHT"
|
||||
printf "%*s" $COLUMNS "$PRIGHT"
|
||||
}
|
||||
|
||||
# quick right prompt I grabbed to test things.
|
||||
__command_rprompt() {
|
||||
local times= n=$COLUMNS tz
|
||||
for tz in ZRH:Europe/Zurich PIT:US/Eastern \
|
||||
MTV:US/Pacific TOK:Asia/Tokyo; do
|
||||
[ $n -gt 40 ] || break
|
||||
times="$times ${tz%%:*}\e[30;1m:\e[0;36;1m"
|
||||
times="$times$(TZ=${tz#*:} date +%H:%M)\e[0m"
|
||||
n=$(( $n - 10 ))
|
||||
done
|
||||
[ -z "$times" ] || printf "%${n}s$times\\r" ''
|
||||
local times=n=$COLUMNS tz
|
||||
for tz in ZRH:Europe/Zurich PIT:US/Eastern \
|
||||
MTV:US/Pacific TOK:Asia/Tokyo; do
|
||||
[ "$n" -gt 40 ] || break
|
||||
times="$times ${tz%%:*}\e[30;1m:\e[0;36;1m"
|
||||
times="$times$(TZ=${tz#*:} date +%H:%M)\e[0m"
|
||||
n=$(("$n" - 10))
|
||||
done
|
||||
[ -z "$times" ] || printf "%${n}s$times\\r" ''
|
||||
}
|
||||
# PROMPT_COMMAND=__command_rprompt
|
||||
|
||||
# this doens't wrap code in \[ \]
|
||||
ansi_r() {
|
||||
local seq
|
||||
declare -a mycodes2=("${!1}")
|
||||
local seq
|
||||
declare -a mycodes2=("${!1}")
|
||||
|
||||
debug "ansi: ${!1} all: $* aka ${mycodes2[@]}"
|
||||
debug "ansi: ${!1} all: $* aka " "${mycodes2[@]}"
|
||||
|
||||
seq=""
|
||||
for ((i = 0; i < ${#mycodes2[@]}; i++)); do
|
||||
if [[ -n $seq ]]; then
|
||||
seq="${seq};"
|
||||
fi
|
||||
seq="${seq}${mycodes2[$i]}"
|
||||
done
|
||||
debug "ansi debug:" '\\[\\033['${seq}'m\\]'
|
||||
echo -ne '\033['${seq}'m'
|
||||
# PR="$PR\[\033[${seq}m\]"
|
||||
seq=""
|
||||
for ((i = 0; i < ${#mycodes2[@]}; i++)); do
|
||||
if [[ -n $seq ]]; then
|
||||
seq="${seq};"
|
||||
fi
|
||||
seq="${seq}${mycodes2[$i]}"
|
||||
done
|
||||
debug "ansi debug:" '\\[\\033['"${seq}"'m\\]'
|
||||
echo -ne '\033['"${seq}"'m'
|
||||
# PR="$PR\[\033[${seq}m\]"
|
||||
}
|
||||
|
||||
# Begin a segment on the right
|
||||
# Takes two arguments, background and foreground. Both can be omitted,
|
||||
# rendering default background/foreground.
|
||||
prompt_right_segment() {
|
||||
local bg fg
|
||||
declare -a codes
|
||||
local bg fg
|
||||
declare -a codes
|
||||
|
||||
debug "Prompt right"
|
||||
debug "Prompting $1 $2 $3"
|
||||
debug "Prompt right"
|
||||
debug "Prompting $1 $2 $3"
|
||||
|
||||
# if commented out from kruton's original... I'm not clear
|
||||
# if it did anything, but it messed up things like
|
||||
# prompt_status - Erik 1/14/17
|
||||
# if commented out from kruton's original... I'm not clear
|
||||
# if it did anything, but it messed up things like
|
||||
# prompt_status - Erik 1/14/17
|
||||
|
||||
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
||||
codes=("${codes[@]}" $(text_effect reset))
|
||||
# fi
|
||||
if [[ -n $1 ]]; then
|
||||
bg=$(bg_color $1)
|
||||
codes=("${codes[@]}" $bg)
|
||||
debug "Added $bg as background to codes"
|
||||
fi
|
||||
if [[ -n $2 ]]; then
|
||||
fg=$(fg_color $2)
|
||||
codes=("${codes[@]}" $fg)
|
||||
debug "Added $fg as foreground to codes"
|
||||
fi
|
||||
# if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then
|
||||
codes=("${codes[@]}" "$(text_effect reset)")
|
||||
# fi
|
||||
if [[ -n $1 ]]; then
|
||||
bg=$(bg_color "$1")
|
||||
codes=("${codes[@]}" "$bg")
|
||||
debug "Added $bg as background to codes"
|
||||
fi
|
||||
if [[ -n $2 ]]; then
|
||||
fg=$(fg_color "$2")
|
||||
codes=("${codes[@]}" "$fg")
|
||||
debug "Added $fg as foreground to codes"
|
||||
fi
|
||||
|
||||
debug "Right Codes: "
|
||||
# declare -p codes
|
||||
debug "Right Codes: "
|
||||
# declare -p codes
|
||||
|
||||
# right always has a separator
|
||||
# if [[ $CURRENT_RBG != NONE && $1 != $CURRENT_RBG ]]; then
|
||||
# $CURRENT_RBG=
|
||||
# fi
|
||||
declare -a intermediate2=($(fg_color $1) $(bg_color $CURRENT_RBG) )
|
||||
# PRIGHT="$PRIGHT---"
|
||||
debug "pre prompt " $(ansi_r intermediate2[@])
|
||||
PRIGHT="$PRIGHT$(ansi_r intermediate2[@])$RIGHT_SEPARATOR"
|
||||
debug "post prompt " $(ansi_r codes[@])
|
||||
PRIGHT="$PRIGHT$(ansi_r codes[@]) "
|
||||
# else
|
||||
# debug "no current BG, codes is $codes[@]"
|
||||
# PRIGHT="$PRIGHT$(ansi codes[@]) "
|
||||
# fi
|
||||
CURRENT_RBG=$1
|
||||
[[ -n $3 ]] && PRIGHT="$PRIGHT$3"
|
||||
# right always has a separator
|
||||
# if [[ $CURRENT_RBG != NONE && $1 != $CURRENT_RBG ]]; then
|
||||
# $CURRENT_RBG=
|
||||
# fi
|
||||
declare -a intermediate2=("$(fg_color "$1")" "$(bg_color $CURRENT_RBG)")
|
||||
# PRIGHT="$PRIGHT---"
|
||||
debug "pre prompt " "$(ansi_r intermediate2[@])"
|
||||
PRIGHT="$PRIGHT$(ansi_r intermediate2[@])$RIGHT_SEPARATOR"
|
||||
debug "post prompt " "$(ansi_r codes[@])"
|
||||
PRIGHT="$PRIGHT$(ansi_r codes[@]) "
|
||||
# else
|
||||
# debug "no current BG, codes is $codes[@]"
|
||||
# PRIGHT="$PRIGHT$(ansi codes[@]) "
|
||||
# fi
|
||||
CURRENT_RBG=$1
|
||||
[[ -n $3 ]] && PRIGHT="$PRIGHT$3"
|
||||
}
|
||||
|
||||
######################################################################
|
||||
|
|
@ -385,22 +383,22 @@ prompt_right_segment() {
|
|||
# 'dirtrack-filter-out-pwd-prompt t t)))
|
||||
|
||||
prompt_emacsdir() {
|
||||
# no color or other setting... this will be deleted per above
|
||||
PR="DIR \w DIR$PR"
|
||||
# no color or other setting... this will be deleted per above
|
||||
PR="DIR \w DIR$PR"
|
||||
}
|
||||
|
||||
######################################################################
|
||||
## Main prompt
|
||||
|
||||
build_prompt() {
|
||||
[[ ! -z ${AG_EMACS_DIR+x} ]] && prompt_emacsdir
|
||||
prompt_status
|
||||
#[[ -z ${AG_NO_HIST+x} ]] && prompt_histdt
|
||||
[[ -z ${AG_NO_CONTEXT+x} ]] && prompt_context
|
||||
prompt_virtualenv
|
||||
prompt_dir
|
||||
prompt_git
|
||||
prompt_end
|
||||
[[ -n ${AG_EMACS_DIR+x} ]] && prompt_emacsdir
|
||||
prompt_status
|
||||
#[[ -z ${AG_NO_HIST+x} ]] && prompt_histdt
|
||||
[[ -z ${AG_NO_CONTEXT+x} ]] && prompt_context
|
||||
prompt_virtualenv
|
||||
prompt_dir
|
||||
prompt_git
|
||||
prompt_end
|
||||
}
|
||||
|
||||
# from orig...
|
||||
|
|
@ -409,16 +407,16 @@ build_prompt() {
|
|||
# use that.
|
||||
|
||||
set_bash_prompt() {
|
||||
RETVAL=$?
|
||||
PR=""
|
||||
PRIGHT=""
|
||||
CURRENT_BG=NONE
|
||||
PR="$(ansi_single $(text_effect reset))"
|
||||
build_prompt
|
||||
RETVAL=$?
|
||||
PR=""
|
||||
PRIGHT=""
|
||||
CURRENT_BG=NONE
|
||||
PR="$(ansi_single "$(text_effect reset)")"
|
||||
build_prompt
|
||||
|
||||
# uncomment below to use right prompt
|
||||
# PS1='\[$(tput sc; printf "%*s" $COLUMNS "$PRIGHT"; tput rc)\]'$PR
|
||||
PS1=$PR
|
||||
# uncomment below to use right prompt
|
||||
# PS1='\[$(tput sc; printf "%*s" $COLUMNS "$PRIGHT"; tput rc)\]'$PR
|
||||
PS1=$PR
|
||||
}
|
||||
|
||||
PROMPT_COMMAND=set_bash_prompt
|
||||
|
|
|
|||
|
|
@ -41,71 +41,71 @@ SCM_THEME_CURRENT_USER_PREFFIX=' '
|
|||
SCM_GIT_SHOW_CURRENT_USER=false
|
||||
|
||||
function _git-uptream-remote-logo {
|
||||
[[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT"
|
||||
[[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT"
|
||||
|
||||
local remote remote_domain
|
||||
remote=$(_git-upstream-remote)
|
||||
remote_domain=$(git config --get remote."$remote".url | awk -F'[@:.]' '{print $2}')
|
||||
local remote remote_domain
|
||||
remote=$(_git-upstream-remote)
|
||||
remote_domain=$(git config --get remote."$remote".url | awk -F'[@:.]' '{print $2}')
|
||||
|
||||
# remove // suffix for https:// url
|
||||
remote_domain=${remote_domain//\//}
|
||||
# remove // suffix for https:// url
|
||||
remote_domain=${remote_domain//\//}
|
||||
|
||||
case $remote_domain in
|
||||
github ) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITHUB";;
|
||||
gitlab ) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITLAB";;
|
||||
bitbucket ) SCM_GIT_CHAR="$SCM_GIT_CHAR_BITBUCKET";;
|
||||
* ) SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT";;
|
||||
esac
|
||||
case $remote_domain in
|
||||
github) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITHUB" ;;
|
||||
gitlab) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITLAB" ;;
|
||||
bitbucket) SCM_GIT_CHAR="$SCM_GIT_CHAR_BITBUCKET" ;;
|
||||
*) SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
function git_prompt_info {
|
||||
git_prompt_vars
|
||||
echo -e " on $SCM_GIT_CHAR_ICON_BRANCH $SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX"
|
||||
git_prompt_vars
|
||||
echo -e " on $SCM_GIT_CHAR_ICON_BRANCH $SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX"
|
||||
}
|
||||
|
||||
function _exit-code {
|
||||
if [[ "$1" -ne 0 ]]; then
|
||||
exit_code=" ${purple}${EXIT_CODE_ICON}${yellow}${exit_code}${bold_orange}"
|
||||
else
|
||||
exit_code="${bold_green}"
|
||||
fi
|
||||
if [[ "$1" -ne 0 ]]; then
|
||||
exit_code=" ${purple}${EXIT_CODE_ICON}${yellow}${exit_code}${bold_orange}"
|
||||
else
|
||||
exit_code="${bold_green}"
|
||||
fi
|
||||
}
|
||||
|
||||
function _prompt {
|
||||
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration=
|
||||
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration=
|
||||
|
||||
command_duration=$(_command_duration)
|
||||
command_duration=$(_command_duration)
|
||||
|
||||
_exit-code exit_code
|
||||
_git-uptream-remote-logo
|
||||
_exit-code exit_code
|
||||
_git-uptream-remote-logo
|
||||
|
||||
history -a
|
||||
history -a
|
||||
|
||||
# Detect root shell
|
||||
if [ "$(whoami)" = root ]; then
|
||||
dir_color=$red
|
||||
fi
|
||||
# Detect root shell
|
||||
if [ "$(whoami)" = root ]; then
|
||||
dir_color=$red
|
||||
fi
|
||||
|
||||
# Detect ssh
|
||||
if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then
|
||||
if [ "$HOST_INFO" = long ]; then
|
||||
host="\H"
|
||||
else
|
||||
host="\h"
|
||||
fi
|
||||
ssh_info="${bold_blue}\u${bold_orange}@${cyan}$host ${bold_orange}in"
|
||||
fi
|
||||
# Detect ssh
|
||||
if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then
|
||||
if [ "$HOST_INFO" = long ]; then
|
||||
host="\H"
|
||||
else
|
||||
host="\h"
|
||||
fi
|
||||
ssh_info="${bold_blue}\u${bold_orange}@${cyan}$host ${bold_orange}in"
|
||||
fi
|
||||
|
||||
# Detect python venv
|
||||
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
|
||||
python_venv="$PYTHON_VENV_CHAR${CONDA_DEFAULT_ENV} "
|
||||
elif [[ -n "${VIRTUAL_ENV}" ]]; then
|
||||
python_venv="$PYTHON_VENV_CHAR$(basename "${VIRTUAL_ENV}") "
|
||||
fi
|
||||
# Detect python venv
|
||||
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
|
||||
python_venv="$PYTHON_VENV_CHAR${CONDA_DEFAULT_ENV} "
|
||||
elif [[ -n "${VIRTUAL_ENV}" ]]; then
|
||||
python_venv="$PYTHON_VENV_CHAR$(basename "${VIRTUAL_ENV}") "
|
||||
fi
|
||||
|
||||
PS1="\\n${ssh_info} ${purple}$(scm_char)${python_venv}${dir_color}\\w${normal}$(scm_prompt_info)${command_duration}${exit_code}"
|
||||
[[ ${#PS1} -gt $((COLUMNS*2)) ]] && wrap_char="\\n"
|
||||
PS1="${PS1}${wrap_char}❯${normal} "
|
||||
PS1="\\n${ssh_info} ${purple}$(scm_char)${python_venv}${dir_color}\\w${normal}$(scm_prompt_info)${command_duration}${exit_code}"
|
||||
[[ ${#PS1} -gt $((COLUMNS * 2)) ]] && wrap_char="\\n"
|
||||
PS1="${PS1}${wrap_char}❯${normal} "
|
||||
}
|
||||
|
||||
safe_append_prompt_command _prompt
|
||||
|
|
|
|||
Loading…
Reference in New Issue