aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/prompt_adam3_setup
diff options
context:
space:
mode:
authorDennis Eriksen <dennis@eriksen.im>2015-06-29 16:39:10 +0200
committerDennis Eriksen <dennis@eriksen.im>2015-06-29 16:39:10 +0200
commit3c00ffddd4e803a503a11069e8ebf4fa5e12387b (patch)
treee1e27ccfa92616b27b0b1248662d446f7779bb0d /prompt_adam3_setup
parentrenaming to adam3, and adding a lincence (diff)
downloadadam3-3c00ffddd4e803a503a11069e8ebf4fa5e12387b.tar.gz
adding multicolouring based on hostname
Diffstat (limited to 'prompt_adam3_setup')
-rw-r--r--prompt_adam3_setup53
1 files changed, 35 insertions, 18 deletions
diff --git a/prompt_adam3_setup b/prompt_adam3_setup
index 3fafb51..94e430f 100644
--- a/prompt_adam3_setup
+++ b/prompt_adam3_setup
@@ -2,27 +2,41 @@
prompt_adam3_help () {
cat <<'EOF'
-This prompt is color-scheme-able. You can invoke it thus:
- prompt adam3 [<color1> [<color2> [<color3>]]]
+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).
-where the colors are for the user@host background, current working
-directory, and current working directory if the prompt is split over
-two lines respectively. The default colors are blue, cyan and green.
-This theme works best with a dark background.
-
-Recommended fonts for this theme: nexus or vga or similar. If you
-don't have any of these, then specify the `plain' option to use 7-bit
-replacements for the 8-bit characters.
EOF
}
prompt_adam3_setup () {
- prompt_adam3_color1=${1:-'blue'}
- prompt_adam3_color2=${2:-'cyan'}
- prompt_adam3_color3=${3:-'green'}
+ prompt_adam3_color1=${1:-'multi'}
+ prompt_adam3_color2=${2:-'blue'}
+ prompt_adam3_color3=${3:-'cyan'}
+ prompt_adam3_color4=${4:-'green'}
+
+ 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)}')
+
+ # hor testing purposes
+ #prompt_adam3_hostnamecolor=$(( ( $RANDOM % 24 ) + 1 ))
+ #prompt_adam3_hostnamebold=$(( $RANDOM % 2 ))
+
+ 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)
+
+ base_hostname_prompt="%K{${${prompt_adam3_hostnamecolors[$prompt_adam3_hostnamecolor]}%,*}}%F{${${prompt_adam3_hostnamecolors[$prompt_adam3_hostnamecolor]}##*,}}%m%f%k"
+
+ if [[ $prompt_adam3_hostnamebold -eq 1 ]]; then base_hostname_prompt="%B$base_hostname_prompt%b"; fi
- base_prompt="%K{$prompt_adam3_color1}%n@%m%k "
+ else
+
+ base_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"
setopt localoptions extendedglob
@@ -33,18 +47,21 @@ prompt_adam3_setup () {
}
prompt_adam3_precmd () {
- setopt noxtrace localoptions
+# setopt noxtrace localoptions
local base_prompt_expanded_no_color base_prompt_etc
local prompt_length space_left
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}
- if [[ $prompt_length -lt 40 ]]; then
- path_prompt="%B%F{$prompt_adam3_color2}%(4~|...|)%3~%F{white}"
+
+ # 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~%F{white}"
else
space_left=$(( $COLUMNS - $#base_prompt_expanded_no_color - 2 ))
- path_prompt="%B%F{$prompt_adam3_color3}%${space_left}<...<%~$prompt_newline%F{white}"
+ path_prompt="%B%F{$prompt_adam3_color4}%${space_left}<...<%~$prompt_newline%F{white}"
fi
PS1="$base_prompt$path_prompt %# $post_prompt"
PS2="$base_prompt$path_prompt %_> $post_prompt"