From 3c00ffddd4e803a503a11069e8ebf4fa5e12387b Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Mon, 29 Jun 2015 16:39:10 +0200 Subject: adding multicolouring based on hostname --- prompt_adam3_setup | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file 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 [ [ []]] +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" -- cgit v1.2.3 From 8b6f0c91ff838bdde8d4acb26073ec28eca389e5 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Mon, 29 Jun 2015 22:00:40 +0200 Subject: adding some comments --- prompt_adam3_setup | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/prompt_adam3_setup b/prompt_adam3_setup index 94e430f..10fd35e 100644 --- a/prompt_adam3_setup +++ b/prompt_adam3_setup @@ -17,21 +17,26 @@ prompt_adam3_setup () { 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)}') + #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 )) + # 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) + # 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" + + # 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 else + # If one wants a specific color, just set ut, plain and simple base_hostname_prompt="%K{$prompt_adam3_color1}%m%k" fi -- cgit v1.2.3 From 2848795908f3a06d59acd50a0497eefd73157055 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Mon, 29 Jun 2015 22:29:44 +0200 Subject: adding some readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index e69de29..7c6d129 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,6 @@ +A prompt which gives you different colors depending on the hostname of your +current host. This might be useful if you visit a large number of hosts, and +want some way to quickly and easily determine that you might be on the wrong +host. + +This project is still in very early development. -- cgit v1.2.3 From dc8c2290fb3d5ceaafdfc213cfc39fc0069d6312 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Mon, 29 Jun 2015 22:36:31 +0200 Subject: added how you can test the prompt --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7c6d129..d6ad081 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,6 @@ want some way to quickly and easily determine that you might be on the wrong host. This project is still in very early development. + +If you wish to test this, plase prompt_adam3_setup in your ``$fpath``, and run +``prompt adam3``. -- cgit v1.2.3 From bb2fc9ae354af601374ea4ea8e481f727eaed201 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Mon, 29 Jun 2015 23:37:56 +0200 Subject: make promptchar bold red if root --- prompt_adam3_setup | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/prompt_adam3_setup b/prompt_adam3_setup index 10fd35e..927955a 100644 --- a/prompt_adam3_setup +++ b/prompt_adam3_setup @@ -54,7 +54,7 @@ prompt_adam3_setup () { prompt_adam3_precmd () { # setopt noxtrace localoptions local base_prompt_expanded_no_color base_prompt_etc - local prompt_length space_left + local prompt_length space_left promptchar base_prompt_expanded_no_color=$(print -P "$base_prompt_no_color") base_prompt_etc=$(print -P "$base_prompt%(4~|...|)%3~") @@ -68,7 +68,12 @@ prompt_adam3_precmd () { space_left=$(( $COLUMNS - $#base_prompt_expanded_no_color - 2 )) path_prompt="%B%F{$prompt_adam3_color4}%${space_left}<...<%~$prompt_newline%F{white}" fi - PS1="$base_prompt$path_prompt %# $post_prompt" + + # make promptchar bold red if root + if [[ $EUID == 0 ]]; then promptchar="%F{red}%B%#%b%f"; else promptchar="%#"; fi + + + PS1="$base_prompt$path_prompt $promptchar $post_prompt" PS2="$base_prompt$path_prompt %_> $post_prompt" PS3="$base_prompt$path_prompt ?# $post_prompt" } -- cgit v1.2.3 From 54c0d66f8cef119b8bde39d5ad44c4f91436d350 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Fri, 20 May 2016 10:10:55 +0200 Subject: just adding a comment --- prompt_adam3_setup | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/prompt_adam3_setup b/prompt_adam3_setup index 927955a..d0b160f 100644 --- a/prompt_adam3_setup +++ b/prompt_adam3_setup @@ -16,13 +16,14 @@ prompt_adam3_setup () { prompt_adam3_color3=${3:-'cyan'} prompt_adam3_color4=${4:-'green'} + # 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)}') + 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)}') # for testing purposes - prompt_adam3_hostnamecolor=$(( ( $RANDOM % 24 ) + 1 )) - prompt_adam3_hostnamebold=$(( $RANDOM % 2 )) + #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) -- cgit v1.2.3 From a37525a89130deef103d83e49b26751f9e3f54c1 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Fri, 20 May 2016 10:42:59 +0200 Subject: just adding more comments --- prompt_adam3_setup | 3 +++ 1 file changed, 3 insertions(+) diff --git a/prompt_adam3_setup b/prompt_adam3_setup index d0b160f..77ed90e 100644 --- a/prompt_adam3_setup +++ b/prompt_adam3_setup @@ -11,6 +11,8 @@ EOF } prompt_adam3_setup () { + + # colors prompt_adam3_color1=${1:-'multi'} prompt_adam3_color2=${2:-'blue'} prompt_adam3_color3=${3:-'cyan'} @@ -45,6 +47,7 @@ prompt_adam3_setup () { 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)/}" -- cgit v1.2.3 From cd7ec7da952466e0ee834f5842e983d0f636bd21 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Fri, 20 May 2016 11:23:59 +0200 Subject: lets add some VCS info --- prompt_adam3_setup | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/prompt_adam3_setup b/prompt_adam3_setup index 77ed90e..5f7fa67 100644 --- a/prompt_adam3_setup +++ b/prompt_adam3_setup @@ -12,6 +12,8 @@ EOF prompt_adam3_setup () { + autoload -Uz vcs_info + # colors prompt_adam3_color1=${1:-'multi'} prompt_adam3_color2=${2:-'blue'} @@ -57,6 +59,11 @@ prompt_adam3_setup () { prompt_adam3_precmd () { # setopt noxtrace localoptions + zstyle ':vcs_info:*' enable git svn + zstyle ':vcs_info:*' check-for-changes true + zstyle ':vcs_info:*' formats "%F{grey}%s %F{green}%b%{$reset_color%} %F{red}%m%u%c%f" + #zstyle ':vcs_info:git*' actionformats "%s %r/%S %b %m%u%c " + vcs_info local base_prompt_expanded_no_color base_prompt_etc local prompt_length space_left promptchar @@ -67,19 +74,18 @@ prompt_adam3_precmd () { # 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}" + path_prompt="%B%F{$prompt_adam3_color3}%(4~|...|)%3~%F{white}%b" else space_left=$(( $COLUMNS - $#base_prompt_expanded_no_color - 2 )) - path_prompt="%B%F{$prompt_adam3_color4}%${space_left}<...<%~$prompt_newline%F{white}" + path_prompt="%B%F{$prompt_adam3_color4}%${space_left}<...<%~$prompt_newline%F{white}%b" fi # make promptchar bold red if root - if [[ $EUID == 0 ]]; then promptchar="%F{red}%B%#%b%f"; else promptchar="%#"; fi - + if [[ $EUID == 0 ]]; then promptchar="%F{red}%B%#%b%f"; else promptchar="%B%#%b"; fi - PS1="$base_prompt$path_prompt $promptchar $post_prompt" - PS2="$base_prompt$path_prompt %_> $post_prompt" - PS3="$base_prompt$path_prompt ?# $post_prompt" + PS1="$base_prompt$path_prompt${vcs_info_msg_0_} $promptchar $post_prompt" + PS2="$base_prompt$path_prompt${vcs_info_msg_0_} %_> $post_prompt" + PS3="$base_prompt$path_prompt${vcs_info_msg_0_} ?# $post_prompt" } prompt_adam3_setup "$@" -- cgit v1.2.3