aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/prompt_adam3_setup
diff options
context:
space:
mode:
authorDennis Eriksen <dennis@eriksen.im>2017-05-23 16:56:57 +0200
committerDennis Eriksen <dennis@eriksen.im>2017-05-23 16:56:57 +0200
commit002cfb1273863dd8988d2a8fa2864e9c32fdaf18 (patch)
treed8f3258c9027dab4b89ab52afc746e05d49b410b /prompt_adam3_setup
parentjust added the possibility of using $ as promptchar (diff)
downloadadam3-002cfb1273863dd8988d2a8fa2864e9c32fdaf18.tar.gz
just reworking the code
Diffstat (limited to '')
-rw-r--r--prompt_adam3_setup54
1 files changed, 25 insertions, 29 deletions
diff --git a/prompt_adam3_setup b/prompt_adam3_setup
index a9b792d..2fb0974 100644
--- a/prompt_adam3_setup
+++ b/prompt_adam3_setup
@@ -11,6 +11,7 @@ EOF
}
prompt_adam3_setup () {
+ setopt localoptions nowarncreateglobal
autoload -Uz vcs_info
@@ -20,45 +21,38 @@ prompt_adam3_setup () {
prompt_adam3_color3=${3:-'cyan'}
prompt_adam3_color4=${4:-'green'}
+ prompt_adam3_PS1="%K{${prompt_adam3_color2}}%n@%k"
+
# Change color of host, based on hostname
if [[ $prompt_adam3_color1 == 'multi' ]]; then
- prompt_adam3_hostnamecolor=$(hostname | od | tr ' ' '\n' | awk '{total = total + $1}END{print 1 + (total % 24)}')
- prompt_adam3_hostnamebold=$(hostname | od | tr ' ' '\n' | awk '{total = total + $1}END{print 1 + (total % 2)}')
+ local hostname_color=$(hostname | od | tr ' ' '\n' | awk '{total = total + $1}END{print 1 + (total % 24)}')
+ local hostname_bold=$(hostname | od | tr ' ' '\n' | awk '{total = total + $1}END{print 1 + (total % 2)}')
# for testing purposes
#prompt_adam3_hostnamecolor=$(( ( $RANDOM % 24 ) + 1 ))
#prompt_adam3_hostnamebold=$(( $RANDOM % 2 ))
# Possible prompt colors
- prompt_adam3_hostnamecolors=(black,red black,green black,yellow black,blue black,magenta black,cyan red,white red,yellow red,cyan green,black green,blue yellow,black yellow,blue blue,white blue,red blue,yellow magenta,white magenta,yellow cyan,white cyan,blue white,black white,red white,blue white,magenta)
+ local colors=(black,red black,green black,yellow black,blue black,magenta black,cyan red,white red,yellow red,cyan green,black green,blue yellow,black yellow,blue blue,white blue,red blue,yellow magenta,white magenta,yellow cyan,white cyan,blue white,black white,red white,blue white,magenta)
# This is where we set up the actual prompt.
- base_hostname_prompt="%K{${${prompt_adam3_hostnamecolors[$prompt_adam3_hostnamecolor]}%,*}}%F{${${prompt_adam3_hostnamecolors[$prompt_adam3_hostnamecolor]}##*,}}%m%f%k"
-
+ local hostname_prompt="%K{${${colors[${hostname_color}]}%,*}}%F{${${colors[${hostname_color}]}##*,}}%m%f%k"
# this will set the hostname in bold in 50% of the time
- if [[ $prompt_adam3_hostnamebold -eq 1 ]]; then base_hostname_prompt="%B$base_hostname_prompt%b"; fi
+ if [[ $hostname_bold -eq 1 ]]; then hostname_prompt="%B${hostname_prompt}%b"; fi
else
-
# If one wants a specific color, just set ut, plain and simple
- base_hostname_prompt="%K{$prompt_adam3_color1}%m%k"
-
+ local hostname_prompt="%K{$prompt_adam3_color1}%m%k"
fi
- base_prompt="%K{$prompt_adam3_color2}%n@%k$base_hostname_prompt "
- post_prompt="%b%f%k"
-
- # localoptions allows us to use extendedglob here, and not outside this function.
- setopt localoptions extendedglob
- base_prompt_no_color="${base_prompt//(%K{[^\\\}]#\}|%k)/}"
- post_prompt_no_color="${post_prompt//(%K{[^\\\}]#\}|%k)/}"
+ prompt_adam3_PS1+="${hostname_prompt} "
add-zsh-hook precmd prompt_adam3_precmd
}
prompt_adam3_precmd () {
- #setopt noxtrace prompt_subst localoptions
+ setopt localoptions extendedglob noxtrace nowarncreateglobal
zstyle ':vcs_info:*' enable git svn
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' check-for-staged-changes true
@@ -67,20 +61,20 @@ prompt_adam3_precmd () {
zstyle ':vcs_info:*' formats "%F{grey}%s %F{green}%b%F{red}%u%c "
zstyle ':vcs_info:git*' actionformats "%F{grey}%s %r/%S %F{green}%b%F{red}%u%c%a "
vcs_info
- local base_prompt_expanded_no_color base_prompt_etc
- local prompt_length space_left promptchar
+ local promptchar
+ PS1="${prompt_adam3_PS1}"
- base_prompt_expanded_no_color=$(print -P "$base_prompt_no_color")
- base_prompt_etc=$(print -P "$base_prompt%(4~|...|)%3~")
- prompt_length=${#base_prompt_etc}
+ local prompt_adam3_PS1_length="${#${(S%%)prompt_adam3_PS1//(\%([KF1]|)\{*\}|\%[Bbkf])}}"
+ local prompt_adam3_PS1_etc=$(print -P "${(S%%)prompt_adam3_PS1//(\%([KF1]|)\{*\}|\%[Bbkf])}%~")
+ local prompt_adam3_PS1_etc_length="${#prompt_adam3_PS1_etc}"
# Changing the prompt based on the length of the prompt, should happen based
# on how long it actually is. The method below will need to be changed.
- if [[ $prompt_length -lt 69 ]]; then
- path_prompt="%B%F{$prompt_adam3_color3}%(4~|...|)%3~%b "
+ if [[ ${prompt_adam3_PS1_etc_length} -lt 60 && $((${prompt_adam3_PS1_etc_length} + 40)) -lt $COLUMNS ]]; then
+ PS1+="%B%F{${prompt_adam3_color3}}%(4~|...|)%3~%b "
else
- space_left=$(( $COLUMNS - $#base_prompt_expanded_no_color - 2 ))
- path_prompt="%B%F{$prompt_adam3_color4}%${space_left}<...<%~$prompt_newline%b"
+ local space_left=$(( $COLUMNS - ${prompt_adam3_PS1_length} - 2 ))
+ PS1+="%B%F{${prompt_adam3_color4}}%${space_left}<...<%~${prompt_newline}%b"
fi
# make promptchar bold red if root
@@ -88,9 +82,11 @@ prompt_adam3_precmd () {
# same as above, but with $ instead of % as promptchar for unprivileged users
#if [[ $EUID == 0 ]]; then promptchar="%F{red}%B%#%b%f"; else promptchar="%F{white}%B%(!.#.$)%b%f"; fi
- PS1="$base_prompt$path_prompt${vcs_info_msg_0_}%{$reset_color%}$promptchar $post_prompt"
- PS2="$base_prompt$path_prompt${vcs_info_msg_0_}%{$reset_color%}%_> $post_prompt"
- PS3="$base_prompt$path_prompt${vcs_info_msg_0_}%{$reset_color%}?# $post_prompt"
+ PS1+="${vcs_info_msg_0_}%{${reset_color}%}"
+
+ PS1+="${promptchar} %b%f%k"
+ PS2="${PS1}%_> %b%f%k"
+ PS3="${PS1}?# %b%f%k"
}
prompt_adam3_setup "$@"