aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/prompt_adam3_setup
diff options
context:
space:
mode:
authorDennis Eriksen <d@ennis.no>2023-01-11 07:56:27 +0100
committerDennis Eriksen <d@ennis.no>2023-01-11 07:56:27 +0100
commit708504eec6dfa34fd945298586fefb2f34c6f40f (patch)
tree782f72ca8cac0d017fb0a27ae9ca78bf55aaecfd /prompt_adam3_setup
parentApparently %* does not zero-pad the hours. I want zero-padding. (diff)
downloadadam3-708504eec6dfa34fd945298586fefb2f34c6f40f.tar.gz
Making prompt more customizable.
Adding globals for more stuff, so everything can be customized. Also, no longer show user@host if on localhost. Only show if using ssh.
Diffstat (limited to 'prompt_adam3_setup')
-rw-r--r--prompt_adam3_setup57
1 files changed, 45 insertions, 12 deletions
diff --git a/prompt_adam3_setup b/prompt_adam3_setup
index 3b885b0..7bc255a 100644
--- a/prompt_adam3_setup
+++ b/prompt_adam3_setup
@@ -14,6 +14,33 @@ This prompt changes the color of your prompt based on the
hostname of your current host. This can be quite nice if you log in to a lot of
different hosts (if you can manage to distribute the prompt, of course).
+Global variables that can be used to change/manipulate the prompt, and their
+defaults:
+PROMPT_ADAM3_COLOR1=multi # host-color. 'multi' means color changes w/hostname
+PROMPT_ADAM3_COLOR2=white,blue # user color
+PROMPT_ADAM3_COLOR3=39,none,1 # color for directory
+PROMPT_ADAM3_COLOR4=66 # color for time
+ # PROMPT_ADAM3_COLOR{1..4} accept comma-separated values for "foreground,
+ # background, bold". Fore- and background color takes both color names and
+ # color values. Bold can be set with 1 for bold, and 0 for not bold. For
+ # example, "blue,white,1" means bold white text on blue background. Values
+ # can be dropped from the right, so "blue,white" means blue text on white
+ # background, and "blue" means just blue text.
+
+PROMPT_ADAM3_COLOR5=white # default prompt-color. Only takes a single color.
+PROMPT_ADAM3_TIME= # Set to 'false' if you don't want time on RPS1
+PROMPT_ADAM3_AOUH= # Set to 'true' if you want "user@host" to show on
+ # localhost. Else it will only be shown when on remote host
+ # (through ssh)
+
+PROMPT_ADAM3_PUSER='%n@'
+PROMPT_ADAM3_PHOST='%m'
+PROMPT_ADAM3_PdirS='%-40<..<%(5~|%-1~/../%3~|%4~)%<< '
+PROMPT_ADAM3_PdirD='%-10<..<%~%<<'
+PROMPT_ADAM3_PTIME='%D{%H:%M:%S}'
+PROMPT_ADAM3_SHLVL='%(10L.%F{58}%L%f .)'
+PROMPT_ADAM3_PROMPTCHAR="%(?..[%F{red}%?%f] )%B%F{%(!.red.$PROMPT_ADAM3_COLOR5)}%#%f%b "
+
EOF
}
@@ -40,27 +67,28 @@ prompt_adam3_setup () {
color[dirS]=${3:-${PROMPT_ADAM3_COLOR3:-39,none,1}} # dir (single-mode) color
color[dirD]=${3:-${PROMPT_ADAM3_COLOR3:-39,none,1}} # dir (double mode) color
color[time]=${4:-${PROMPT_ADAM3_TIME:-${PROMPT_ADAM3_COLOR4:-66}}} # time color
+ color[char]=${5:-${PROMPT_ADAM3_COLOR5:-white}} # default promptchar-color
# Username
- prom[user]='%n@'
+ prom[user]=${PROMPT_ADAM3_PUSER:-'%n@'}
# Hostname
- prom[host]='%m'
+ prom[host]=${PROMPT_ADAM3_PHOST:-'%m'}
# DIR in single-line-mode
- prom[dirS]='%-40<..<%(5~|%-1~/../%3~|%4~)%<< '
+ prom[dirS]=${PROMPT_ADAM3_PdirS:-'%-40<..<%(5~|%-1~/../%3~|%4~)%<< '}
# DIR in double-line-mode
- prom[dirD]='%-10<..<%~%<<'
+ prom[dirD]=${PROMPT_ADAM3_PdirD:-'%-10<..<%~%<<'}
# Time
- [[ $timecolor != false ]] && prom[time]='%D{%H:%M:%S}'
+ [[ $color[time] != false ]] && prom[time]=${PROMPT_ADAM3_PTIME:-'%D{%H:%M:%S}'}
# SHLVL
- prom[shlvl]='%(10L.%F{58}%L%f .)'
+ prom[shlvl]=${PROMPT_ADAM3_SHLVL:-'%(10L.%F{58}%L%f .)'}
# Promptchar (including exitcode)
- typeset -g PROMPT_ADAM3_PROMPTCHAR='%(?..[%F{red}%?%f] )%B%F{%(!.red.white)}%#%f%b '
+ typeset -g PROMPT_ADAM3_PROMPTCHAR=${PROMPT_ADAM3_PROMPTCHAR:-"%(?..[%F{red}%?%f] )%B%F{%(!.red.$color[char])}%#%f%b "}
# same as above, but with $ instead of % as promptchar for unprivileged users
#typeset -g PROMPT_ADAM3_PROMPTCHAR='%B%(!.%F{red}#.F{white}$)%f%b '
@@ -73,18 +101,20 @@ prompt_adam3_setup () {
zstyle ':vcs_info:*' formats '%s %F{green}%b%F{red}%u%c%f '
zstyle ':vcs_info:git*' actionformats '%s %r/%S %F{green}%b%F{red}%u%c%a%f '
+ local c # scope up a throwaway-variable
+
# Change color of host, based on hostname
if [[ $color[host] == 'multi' ]]; then
# Here we take the charset-number of each character in the hostname, and
# add them together.
local -i hostnum i
- local c
for i in {1..$#HOST}; do
c=$HOST[$i]
(( hostnum += #c ))
done
+ # color-combos. fg,bg
local -a colors=( red,black green,black yellow,black blue,black \
magenta,black cyan,black white,red yellow,red \
cyan,red black,green blue,green black,yellow \
@@ -112,7 +142,9 @@ prompt_adam3_setup () {
done
# Make each prompt-part global
- typeset -g PROMPT_ADAM3_PS1="$prom[user]$prom[host] "
+ typeset -g PROMPT_ADAM3_PS1
+ [[ -n $SSH_CLIENT || -n $SSH_TTY || -n $SSH_CONNECTION || -n $PROMPT_ADAM3_AOUH ]] \
+ && PROMPT_ADAM3_PS1="$prom[user]$prom[host] "
typeset -g PROMPT_ADAM3_SLM_DIR=$prom[dirS]
typeset -g PROMPT_ADAM3_DLM_DIR=$prom[dirD]
typeset -g PROMPT_ADAM3_RPS1=$prom[shlvl]$prom[time]
@@ -135,7 +167,8 @@ prompt_adam3_precmd () {
# Calculate prompt-length by first removing all zero-length characters. From
# prompt_bart_setup in zsh.
- local prompt_length=${#${(S%%)prom//\%([BSUbfksu]|[FK]\{*\})/}}
+ local zlchars='%([BSUbfksu]|[FK]{*})' # regex for zero-length chars
+ local prompt_length=${#${(S%%)prom//$~zlchars/}}
# If the prompt is over half the terminal, we go into multiline-mode.
if (( prompt_length > ( COLUMNS / 2 ) )); then
@@ -143,8 +176,8 @@ prompt_adam3_precmd () {
prom+=$PROMPT_ADAM3_DLM_DIR # double-line-mode dir
# We need to recalculate prompt_length to know where to put time
- prompt_length=${#${(S%%)prom//\%([BSUbfksu]|[FK]\{*\})/}}
- local rprompt_length=${#${(S%%)PROMPT_ADAM3_RPS1//\%([BSUbfksu]|[FK]\{*\})/}}
+ prompt_length=${#${(S%%)prom//$~zlchars/}}
+ local rprompt_length=${#${(S%%)PROMPT_ADAM3_RPS1//$~zlchars/}}
local timepadding=$((COLUMNS - prompt_length + $#PROMPT_ADAM3_RPS1 - rprompt_length - 3 ))
# Add time. Left-pad with spaces.