From 17a3040fb730b71414f97d33474e995a3f80eb14 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Thu, 18 Nov 1999 15:15:27 +0000 Subject: manual/8668 --- Functions/Prompts/prompt_adam1_setup | 29 ++++++++-- Functions/Prompts/prompt_adam2_setup | 69 +++++++++++------------- Functions/Prompts/prompt_bigfade_setup | 50 +++++++++++++++++ Functions/Prompts/prompt_elite2_setup | 60 +++++++++++++++++---- Functions/Prompts/prompt_elite_setup | 45 ++++++++++++---- Functions/Prompts/prompt_fade_setup | 58 ++++++++++++++++++++ Functions/Prompts/prompt_fire_setup | 71 +++++++++++++++++------- Functions/Prompts/prompt_off_setup | 2 +- Functions/Prompts/prompt_oliver_setup | 12 +++-- Functions/Prompts/prompt_suse_setup | 2 +- Functions/Prompts/prompt_zefram_setup | 17 ++++++ Functions/Prompts/promptinit | 98 +++++++++++++++++++++++++--------- 12 files changed, 405 insertions(+), 108 deletions(-) create mode 100644 Functions/Prompts/prompt_bigfade_setup create mode 100644 Functions/Prompts/prompt_fade_setup create mode 100644 Functions/Prompts/prompt_zefram_setup (limited to 'Functions/Prompts') diff --git a/Functions/Prompts/prompt_adam1_setup b/Functions/Prompts/prompt_adam1_setup index 65d1b68c0..19b7737eb 100644 --- a/Functions/Prompts/prompt_adam1_setup +++ b/Functions/Prompts/prompt_adam1_setup @@ -1,7 +1,30 @@ # adam1 prompt theme +prompt_adam1_help () { + cat <<'EOF' +This prompt is color-scheme-able. You can invoke it thus: + + prompt adam1 [ [ []]] + +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. + +And you probably thought adam1 was overkill. +EOF +} + prompt_adam1_setup () { - base_prompt="%{$bg_no_bold_blue%}%n@%m%{$reset_color%} " + prompt_adam1_color1=${1:-'blue'} + prompt_adam1_color2=${2:-'cyan'} + prompt_adam1_color3=${3:-'green'} + + base_prompt="%{$bg_no_bold[$prompt_adam1_color1]%}%n@%m%{$reset_color%} " post_prompt="%{$reset_color%}" base_prompt_no_color=$(echo "$base_prompt" | perl -pe "s/%{.*?%}//g") @@ -20,10 +43,10 @@ prompt_adam1_precmd () { base_prompt_etc=$(print -P "$base_prompt%(4~|...|)%3~") prompt_length=${#base_prompt_etc} if [[ $prompt_length -lt 40 ]]; then - path_prompt="%{$fg_bold_cyan%}%(4~|...|)%3~%{$fg_bold_white%}" + path_prompt="%{$fg_bold[$prompt_adam1_color2]%}%(4~|...|)%3~%{$fg_bold[white]%}" else space_left=$(( $COLUMNS - $#base_prompt_expanded_no_color - 2 )) - path_prompt="%{$fg_bold_green%}%${space_left}<...<%~$prompt_newline%{$fg_bold_white%}" + path_prompt="%{$fg_bold[$prompt_adam1_color3]%}%${space_left}<...<%~$prompt_newline%{$fg_bold_white%}" fi PS1="$base_prompt$path_prompt %# $post_prompt" PS2="$base_prompt$path_prompt %_> $post_prompt" diff --git a/Functions/Prompts/prompt_adam2_setup b/Functions/Prompts/prompt_adam2_setup index 9aa4f75cf..7bac0854d 100644 --- a/Functions/Prompts/prompt_adam2_setup +++ b/Functions/Prompts/prompt_adam2_setup @@ -2,17 +2,19 @@ prompt_adam2_help () { cat <<'EOF' -This prompt is color-theme-able. You can invoke it thus: +This prompt is color-scheme-able. You can invoke it thus: - prompt adam2 [ plain ] + prompt adam2 [ plain ] [ [ []]] where the colors are for the hyphens, current directory, and user@host -bits respectively. +bits respectively. The default colors are cyan, green, and cyan. +This theme works best with a dark background. -And you probably thought adam1 was overkill. If you've ever seen a -more complex prompt in your whole life, please e-mail it to me at -; I'd love to know that I'm not the saddest person -on the planet. +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. + +And you probably thought adam1 was overkill. EOF } @@ -27,46 +29,39 @@ prompt_adam2_setup () { prompt_gfx_blc='\`' prompt_gfx_hyphen='-' else - prompt_gfx_tlc=$(echo "\xda") - prompt_gfx_mlc=$(echo "\xc3") - prompt_gfx_blc=$(echo "\xc0") - prompt_gfx_hyphen=$(echo "\xc4") + prompt_gfx_tlc=$'\xda' + prompt_gfx_mlc=$'\xc3' + prompt_gfx_blc=$'\xc0' + prompt_gfx_hyphen=$'\xc4' fi # Colour scheme - prompt_scheme_color1=${1:-'cyan'} # hyphens - prompt_scheme_color2=${2:-'green'} # current directory - prompt_scheme_color3=${3:-'cyan'} # user@host - - local num - for num in 1 2 3; do - # Grok this! - eval "prompt_color$num="'${(P)$(echo "fg_no_bold_$prompt_scheme_color'"$num\")}" - eval "prompt_bold_color$num="'${(P)$(echo "fg_bold_$prompt_scheme_color'"$num\")}" - done + prompt_adam2_color1=${1:-'cyan'} # hyphens + prompt_adam2_color2=${2:-'green'} # current directory + prompt_adam2_color3=${3:-'cyan'} # user@host - prompt_gfx_tbox=$(echo "%{$prompt_bold_color1%}${prompt_gfx_tlc}%{$prompt_color1%}${prompt_gfx_hyphen}") - prompt_gfx_bbox=$(echo "%{$prompt_bold_color1%}${prompt_gfx_blc}${prompt_gfx_hyphen}%{$prompt_color1%}") + prompt_gfx_tbox="%{$fg_bold[$prompt_adam2_color1]%}${prompt_gfx_tlc}%{$fg_no_bold[$prompt_adam2_color1]%}${prompt_gfx_hyphen}" + prompt_gfx_bbox="%{$fg_bold[$prompt_adam2_color1]%}${prompt_gfx_blc}${prompt_gfx_hyphen}%{$fg_no_bold[$prompt_adam2_color1]%}" # This is a cute hack. Well I like it, anyway. - prompt_gfx_bbox_to_mbox=$(echo "%{\e[A\r$prompt_bold_color1${prompt_gfx_mlc}$prompt_color1${prompt_gfx_hyphen}\e[B%}") + prompt_gfx_bbox_to_mbox=$(print -n "%{\e[A\r$fg_bold[$prompt_adam2_color1]${prompt_gfx_mlc}$fg_no_bold[$prompt_adam2_color1]${prompt_gfx_hyphen}\e[B%}") - prompt_l_paren=$(echo "%{$fg_bold_grey%}(") - prompt_r_paren=$(echo "%{$fg_bold_grey%})") + prompt_l_paren=$'%{$fg_bold[grey]%}(' + prompt_r_paren=$'%{$fg_bold[grey]%})' - prompt_l_bracket=$(echo "%{$fg_bold_grey%}[") - prompt_r_bracket=$(echo "%{$fg_bold_grey%}]") + prompt_l_bracket=$'%{$fg_bold[grey]%}[' + prompt_r_bracket=$'%{$fg_bold[grey]%}]' - prompt_machine=$(echo "%{$prompt_color3%}%n%{$prompt_bold_color3%}@%{$prompt_color3%}%m") + prompt_machine="%{$fg_no_bold[$prompt_adam2_color3]%}%n%{$fg_bold[$prompt_adam2_color3]%}@%{$fg_no_bold[$prompt_adam2_color3]%}%m" prompt_padding_text=`perl -e "print qq{${prompt_gfx_hyphen}} x 200"` - prompt_line_1a="$prompt_gfx_tbox$prompt_l_paren%{$prompt_bold_color2%}%~$prompt_r_paren%{$prompt_color1%}" + prompt_line_1a="$prompt_gfx_tbox$prompt_l_paren%{$fg_bold[$prompt_adam2_color2]%}%~$prompt_r_paren%{$fg_no_bold[$prompt_adam2_color1]%}" prompt_line_1a_no_color=$(echo "$prompt_line_1a" | perl -pe "s/%{.*?%}//g") - prompt_line_1b=$(echo "$prompt_l_paren$prompt_machine$prompt_r_paren%{$prompt_color1%}${prompt_gfx_hyphen}") + prompt_line_1b="$prompt_l_paren$prompt_machine$prompt_r_paren%{$fg_no_bold[$prompt_adam2_color1]%}${prompt_gfx_hyphen}" prompt_line_1b_no_color=$(echo "$prompt_line_1b" | perl -pe "s/%{.*?%}//g") - prompt_line_2="$prompt_gfx_bbox${prompt_gfx_hyphen}%{$fg_bold_white%}" + prompt_line_2="$prompt_gfx_bbox${prompt_gfx_hyphen}%{$fg_bold[white]%}" prompt_char="%(!.#.>)" @@ -98,19 +93,19 @@ prompt_adam2_precmd () { prompt_line_1="$prompt_line_1a$prompt_padding" else prompt_pwd_size=$(( $COLUMNS - 5 )) - prompt_line_1="$prompt_gfx_tbox$prompt_l_paren%{$prompt_bold_color2%}%$prompt_pwd_size<...<%~%<<$prompt_r_paren%{$prompt_color1$prompt_gfx_hyphen%}" + prompt_line_1="$prompt_gfx_tbox$prompt_l_paren%{$fg_bold[$prompt_adam2_color2]%}%$prompt_pwd_size<...<%~%<<$prompt_r_paren%{$fg_no_bold[$prompt_adam2_color1]$prompt_gfx_hyphen%}" fi fi pre_prompt="$prompt_line_1$prompt_newline$prompt_line_2" - PS1="$pre_prompt%{$fg_bold_white%}$prompt_char " - PS2="$prompt_line_2%{$prompt_gfx_bbox_to_mbox$fg_bold_white%}%_> " - PS3="$prompt_line_2%{$prompt_gfx_bbox_to_mbox$fg_bold_white%}?# " + PS1="$pre_prompt%{$fg_bold[white]%}$prompt_char " + PS2="$prompt_line_2%{$prompt_gfx_bbox_to_mbox$fg_bold[white]%}%_> " + PS3="$prompt_line_2%{$prompt_gfx_bbox_to_mbox$fg_bold[white]%}?# " } prompt_adam2_preexec () { - print -n "$fg_no_bold_white" + print -n "$fg_no_bold[white]" } prompt_adam2_setup "$@" diff --git a/Functions/Prompts/prompt_bigfade_setup b/Functions/Prompts/prompt_bigfade_setup new file mode 100644 index 000000000..260c0ddf0 --- /dev/null +++ b/Functions/Prompts/prompt_bigfade_setup @@ -0,0 +1,50 @@ +# Generic large colour fade-bar prompt theme from bashprompt +# Created by James Manning +# Changed by Spidey 08/06 +# Converted to zsh prompt theme by + +prompt_bigfade_help () { + cat < [ [ []]]] + +where the parameters are the colors for the fade-bar, user@host text, +date text, and current working directory respectively. The default +colors are blue, white, white, and yellow. 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, the 8-bit characters will probably look stupid. +EOH +} + +prompt_bigfade_setup () { + local fadebar=${1:-'blue'} + local userhost=${2:-'white'} + local date=${3:-'white'} + local cwd=${4:-'yellow'} + + for code in 333 262 261 260 260 261 262 333 333 262 261 260 333 262 261 260 260 261 262 333 333 262 261 260; do + local varname=char_$code + : ${(P)varname=$(echo -n "\\0$code")} + done + + PS1="%{$bold_color$fg[$fadebar]$bold_color%}$char_333$char_262$char_261$char_260%{$bold_color$fg[$userhost]$bg[$fadebar]%}%n@%m%{$reset_color$fg[$fadebar]$bg[grey]%}$char_260$char_261$char_262$char_333%{$reset_color$fg[$fadebar]$bg[grey]%}$char_333$char_262$char_261$char_260%{$bold_color$fg[$date]$bg[grey]%} %D{%a %b %d} %D{%I:%M:%S%P}$prompt_newline%{$bold_color$fg[$cwd]$bg[grey]%}$PWD>%{$reset_color%} " + PS2="%{$bold_color$fg[$fadebar]$bold_color%}$char_333$char_262$char_261$char_260%{$reset_color$fg[$fadebar]$bg[grey]%}$char_260$char_261$char_262$char_333%{$reset_color$fg[$fadebar]$bg[grey]%}$char_333$char_262$char_261$char_260%{$bold_color$bold_color$fg[$fadebar]%}>%{$reset_color%} " + + precmd () { setopt promptsubst } + preexec () { } +} + +prompt_bigfade_preview () { + if (( ! $#* )); then + prompt_preview_theme bigfade + print + prompt_preview_theme bigfade red white grey white + else + prompt_preview_theme bigfade "$@" + fi +} + +prompt_bigfade_setup "$@" diff --git a/Functions/Prompts/prompt_elite2_setup b/Functions/Prompts/prompt_elite2_setup index 58a151e9c..81107748a 100644 --- a/Functions/Prompts/prompt_elite2_setup +++ b/Functions/Prompts/prompt_elite2_setup @@ -1,17 +1,57 @@ -# Converted to zsh prompt theme by bash2zshprompt, written by # Created by icetrey # Added by Spidey 08/06 +# Converted to zsh prompt theme by + +prompt_elite2_help () { + cat < []] + +The default colors are both cyan. 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, the 8-bit characters will probably look stupid. +EOH +} + prompt_elite2_setup () { - local GRAD1=`tty|cut -d/ -f3` - local COLOR1="%{$reset_color$fg_cyan%}" - local COLOR2="%{$bold_color$fg_cyan%}" - local COLOR3="%{$bold_color$fg_grey%}" - local COLOR4="%{$reset_color%}" - PS1="$COLOR3Ú$COLOR1Ä$COLOR2($COLOR1%n$COLOR3@$COLOR1%m$COLOR2)$COLOR1Ä$COLOR2($COLOR1%!$COLOR3/$COLOR1$GRAD1$COLOR2)$COLOR1Ä$COLOR2($COLOR1%D{%I:%M%P}$COLOR3:$COLOR1%D{%m/%d/%y}$COLOR2)$COLOR1Ä$COLOR3-$COLOR4$prompt_newline$COLOR3À$COLOR1Ä$COLOR2($COLOR1%#$COLOR3:$COLOR1%~$COLOR2)$COLOR1Ä$COLOR3-$COLOR4 " - PS2="$COLOR2Ä$COLOR1Ä$COLOR3-$COLOR4 " - - precmd () { } + local text_col=${1:-'cyan'} + local parens_col=${2:-$text_col} + + for code in 332 304 304 371 371 371 372 300 304 304 371 372; do + local varname=char_$code + : ${(P)varname=$(echo -n "\\0$code")} + done + + local tty=`tty|cut -d/ -f3` + local text="%{$fg_no_bold[$text_col]%}" + local parens="%{$fg_bold[$parens_col]%}" + local punctuation_color="%{$fg_bold[grey]%}" + local reset="%{$reset_color%}" + + PS1="$punctuation_colorÚ$textÄ$parens($text%n$punctuation_color@$text%m$parens)$textÄ$parens($text%!$punctuation_color/$text$tty$parens)$textÄ$parens($text%D{%I:%M%P}$punctuation_color:$text%D{%m/%d/%y}$parens)$textÄ$punctuation_color-$reset$prompt_newline$punctuation_colorÀ$textÄ$parens($text%#$punctuation_color:$text%~$parens)$textÄ$punctuation_color-$reset " + + PS2="$parensÄ$textÄ$punctuation_color-$reset " + + precmd () { setopt promptsubst } preexec () { } } +prompt_elite2_preview () { + local color colors + colors=(red yellow green blue magenta) + + if (( ! $#* )); then + for (( i = 1; i <= $#colors; i++ )); do + color=$colors[$i] + prompt_preview_theme elite2 $color + (( i < $#colors )) && print + done + else + prompt_preview_theme elite2 "$@" + fi +} + prompt_elite2_setup "$@" diff --git a/Functions/Prompts/prompt_elite_setup b/Functions/Prompts/prompt_elite_setup index e5b43fc84..344da3341 100644 --- a/Functions/Prompts/prompt_elite_setup +++ b/Functions/Prompts/prompt_elite_setup @@ -1,18 +1,45 @@ -# Converted to zsh prompt theme by bash2zshprompt, written by - -for code in 332 304 304 371 371 371 372 300 304 304 371 372; do - local varname=char_$code - : ${(P)varname=$(echo -n "\\0$code")} -done - # Created by KrON from windowmaker on IRC # Changed by Spidey 08/06 +# Converted to zsh prompt theme by + +prompt_elite_help () { + cat < []] + +The default colors are red and blue respectively. This theme is +intended for use with a black background. + +Recommended fonts for this theme: nexus or vga or similar. If you +don't have any of these, the 8-bit characters will probably look stupid. +EOH +} + prompt_elite_setup () { - PS1="%{$fg_red%}$char_332$char_304%{$fg_blue%}(%{$fg_red%}%n%{$fg_blue%}@%{$fg_red%}%m%{$fg_blue%})%{$fg_red%}-%{$fg_blue%}(%{$fg_red%}%D{%I:%M%P}%{$fg_blue%}-:-%{$fg_red%}%D{%m}%{$fg_blue$fg_red%}/%D{%d}%{$fg_blue%})%{$fg_red%}$char_304-%{$fg_blue]%}$char_371%{$fg_red%}-$char_371$char_371%{$fg_blue%}$char_372$prompt_newline%{$fg_red%}$char_300$char_304%{$fg_blue%}(%{$fg_red%}%1~%{$fg_blue%})%{$fg_red%}$char_304$char_371%{$fg_blue%}$char_372%{$reset_color%}" + local text=${1:-'red'} + local punctuation=${2:-'blue'} + + for code in 332 304 304 371 371 371 372 300 304 304 371 372; do + local varname=char_$code + : ${(P)varname=$(echo -n "\\0$code")} + done + + PS1="%{$fg[$text]%}$char_332$char_304%{$fg[$punctuation]%}(%{$fg[$text]%}%n%{$fg[$punctuation]%}@%{$fg[$text]%}%m%{$fg[$punctuation]%})%{$fg[$text]%}-%{$fg[$punctuation]%}(%{$fg[$text]%}%D{%I:%M%P}%{$fg[$punctuation]%}-:-%{$fg[$text]%}%D{%m}%{$fg[$punctuation]$fg[$text]%}/%D{%d}%{$fg[$punctuation]%})%{$fg[$text]%}$char_304-%{$fg[$punctuation]]%}$char_371%{$fg[$text]%}-$char_371$char_371%{$fg[$punctuation]%}$char_372$prompt_newline%{$fg[$text]%}$char_300$char_304%{$fg[$punctuation]%}(%{$fg[$text]%}%1~%{$fg[$punctuation]%})%{$fg[$text]%}$char_304$char_371%{$fg[$punctuation]%}$char_372%{$reset_color%}" PS2="> " - precmd () { } + precmd () { setopt promptsubst } preexec () { } } +prompt_elite_preview () { + if (( ! $#* )); then + prompt_preview_theme elite + print + prompt_preview_theme elite green yellow + else + prompt_preview_theme elite "$@" + fi +} + prompt_elite_setup "$@" diff --git a/Functions/Prompts/prompt_fade_setup b/Functions/Prompts/prompt_fade_setup new file mode 100644 index 000000000..5b49f6105 --- /dev/null +++ b/Functions/Prompts/prompt_fade_setup @@ -0,0 +1,58 @@ +# Generic colour fade-bar prompt theme from bashprompt +# Created by Jim Foltz +# Changed by Spidey 08/06 +# Converted to zsh prompt theme by + +prompt_fade_help () { + cat < [ []]] + +where the parameters are the colors for the fade-bar and current +working directory, user@host text, and date text respectively. The +default colors are green, white, and white. 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, the 8-bit characters will probably look +stupid. +EOH +} + +# emacs shell-script mode gets confused with ' in heredoc above + +prompt_fade_setup () { + local fadebar_cwd=${1:-'green'} + local userhost=${2:-'white'} + local date=${3:-'white'} + + for code in 333 262 261 260 333 262 261 260 333 262 261 260; do + local varname=char_$code + : ${(P)varname=$(echo -n "\\0$code")} + done + + PS1="%{$fg[$fadebar_cwd]$bg[$fadebar_cwd]$bold_color%}$char_333$char_262$char_261$char_260%{$fg[$userhost]$bg[$fadebar_cwd]$bold_color%}%n@%m%{$reset_color$fg[$fadebar_cwd]$bg[grey]%}$char_333$char_262$char_261$char_260%{$fg[$date]$bg[grey]$bold_color%} %D{%a %b %d} %D{%I:%M:%S%P} $prompt_newline%{$fg[$fadebar_cwd]$bg[grey]$bold_color%}%~/%{$reset_color%} " + PS2="%{$fg[$fadebar_cwd]$bg[grey]%}$char_333$char_262$char_261$char_260%{$reset_color%}>" + + precmd () { setopt promptsubst } + preexec () { } +} + +prompt_fade_preview () { + local color colors + colors=(red yellow green blue magenta) + + if (( ! $#* )); then + for (( i = 1; i <= $#colors; i++ )); do + color=$colors[$i] + prompt_preview_theme fade $color + print + done + prompt_preview_theme fade white grey blue + else + prompt_preview_theme fade "$@" + fi +} + +prompt_fade_setup "$@" diff --git a/Functions/Prompts/prompt_fire_setup b/Functions/Prompts/prompt_fire_setup index 93f92e590..1bf72531f 100644 --- a/Functions/Prompts/prompt_fire_setup +++ b/Functions/Prompts/prompt_fire_setup @@ -1,28 +1,63 @@ -# Converted to zsh prompt theme by bash2zshprompt, written by - -for code in 333 262 261 260 260 261 262 333; do - local varname=char_$code - : ${(P)varname=$(echo -n "\\0$code")} -done - +# Fire prompt theme from bashprompt # Inspired by Raster (Carsten Haitzler of Red Hat Advanced Development Labs) # Created by BadlandZ # Changed by Spidey 08/06 +# Converted to zsh prompt theme by + +prompt_fire_help () { + cat < [ [ [ [ []]]]]] + +where the parameters are the three fire colors, and the colors for the +user@host text, date text, and current working directory respectively. +The default colors are yellow, yellow, red, white, white, and yellow. +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, the 8-bit characters will probably look stupid. +EOH +} + prompt_fire_setup () { - local GRAD1='%{$char_333$char_262$char_261$char_260%}' - local GRAD2='%{$char_260$char_261$char_262$char_333%}' - local COLOR1='%{$bold_color$fg_yellow$bg_yellow%}' - local COLOR2='%{$bold_color$fg_white$bg_yellow%}' - local COLOR3='%{$reset_color$fg_red$bg_yellow%}' - local COLOR4='%{$reset_color$fg_red$bg_grey%}' - local COLOR5='%{$bold_color$fg_yellow$bg_grey%}' - local COLOR6='%{$bold_color$fg_white$bg_grey%}' - local GRAD0='%{$reset_color%}' - PS1=$COLOR1$GRAD1$COLOR2'%n@%m'$COLOR3$GRAD2$COLOR4$GRAD1$COLOR6' %D{%a %b %d} %D{%I:%M:%S%P} '$NONE'$prompt_newline'$COLOR5'%~/'$GRAD0' ' - PS2=$COLOR1$GRAD1$COLOR3$GRAD2$COLOR4$GRAD1$COLOR5'>'$GRAD0' ' + local fire1=${1:-'yellow'} + local fire2=${2:-'yellow'} + local fire3=${3:-'red'} + local userhost=${4:-'white'} + local date=${5:-'white'} + local cwd=${6:-'yellow'} + + for code in 333 262 261 260 260 261 262 333; do + local varname=char_$code + : ${(P)varname=$(echo -n "\\0$code")} + done + + local GRAD1="%{$char_333$char_262$char_261$char_260%}" + local GRAD2="%{$char_260$char_261$char_262$char_333%}" + local COLOR1="%{$bold_color$fg[$fire1]$bg[$fire2]%}" + local COLOR2="%{$bold_color$fg[$userhost]$bg[$fire2]%}" + local COLOR3="%{$reset_color$fg[$fire3]$bg[$fire2]%}" + local COLOR4="%{$reset_color$fg[$fire3]$bg[grey]%}" + local COLOR5="%{$bold_color$fg[$cwd]$bg[grey]%}" + local COLOR6="%{$bold_color$fg[$date]$bg[grey]%}" + local GRAD0="%{$reset_color%}" + + PS1=$COLOR1$GRAD1$COLOR2'%n@%m'$COLOR3$GRAD2$COLOR4$GRAD1$COLOR6' %D{%a %b %d} %D{%I:%M:%S%P} '$NONE'$prompt_newline'$COLOR5'%~/'$GRAD0' ' + PS2=$COLOR1$GRAD1$COLOR3$GRAD2$COLOR4$GRAD1$COLOR5'>'$GRAD0' ' precmd () { setopt promptsubst } preexec () { } } +prompt_fire_preview () { + if (( ! $#* )); then + prompt_preview_theme fire + print + prompt_preview_theme fire red magenta blue white white white + else + prompt_preview_theme fire "$@" + fi +} + prompt_fire_setup "$@" diff --git a/Functions/Prompts/prompt_off_setup b/Functions/Prompts/prompt_off_setup index 318060e88..c5820007e 100644 --- a/Functions/Prompts/prompt_off_setup +++ b/Functions/Prompts/prompt_off_setup @@ -4,7 +4,7 @@ prompt_off_setup () { PS1="%# " PS2="> " - precmd () { } + precmd () { setopt promptsubst } preexec () { } } diff --git a/Functions/Prompts/prompt_oliver_setup b/Functions/Prompts/prompt_oliver_setup index 970991bed..a1bce3da2 100644 --- a/Functions/Prompts/prompt_oliver_setup +++ b/Functions/Prompts/prompt_oliver_setup @@ -1,24 +1,26 @@ # oliver prompt theme prompt_oliver_help() { - cat - </dev/null 2>&1 && psvar[2]= +} + +function prompt_zefram_setup { + PS1='[%(2L.%L/.)'$ZSH_VERSION']%(?..%B{%v}%b)%n%(2v.%B@%b.@)%m:%B%~%b%(!.#.>) ' + PS2='%(4_:... :)%3_> ' + + precmd () { prompt_zefram_precmd; setopt promptsubst } + preexec () { } +} + +prompt_zefram_setup "$@" diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index c249412cf..2786f9ac7 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -1,6 +1,10 @@ -# zsh prompt themes extension -# -# Load with `autoload -U promptinit; promptinit'. +## +## zsh prompt themes extension +## by Adam Spiers +## +## Load with `autoload -U promptinit; promptinit'. +## Type `prompt -h' for help. +## prompt_themes=() typeset -gU prompt_themes @@ -19,10 +23,10 @@ promptinit () { prompt_themes=($name $prompt_themes) autoload -U prompt_${name}_setup else - print "Couldn't find theme $theme" + print "Couldn't read file $theme containing theme $name." fi else - print "eh?" + print "Eh? Mismatch between glob patterns in promptinit." fi done @@ -31,7 +35,7 @@ promptinit () { colors # Variables common to all prompt styles - prompt_newline=$(echo -ne "\n%{\r%}") + prompt_newline=$'\n%{\r%}' } set_prompt() { @@ -40,21 +44,35 @@ set_prompt() { usage='Usage: prompt Options: + -c Show currently selected theme and parameters -l List currently available prompt themes -p [] Preview given themes (defaults to all) -h [] Display help (for given theme) -s Set and save theme - Switch to new theme immediately (changes not saved)' + Switch to new theme immediately (changes not saved) - getopts "hlps" opt +Use prompt -h for help on specific themes.' + + getopts "chlps" opt case "$opt" in + c) if (( $+prompt_theme )); then + print -n "Current prompt theme" + (( $#prompt_theme > 1 )) && print -n " with parameters" + print " is:\n $prompt_theme" + else + print "Current prompt is not a theme." + fi + return + ;; h) if [[ -n "$2" && -n $prompt_themes[(r)$2] ]]; then if functions prompt_$2_help >/dev/null; then - print "Help for $2 theme:\n" + print "Help for $2 theme:\n" prompt_$2_help else - print "No help available for $2 theme" + print "No help available for $2 theme." fi + print "\nType \`prompt -p $2' to preview the theme, \`prompt $2'" + print "to try it out, and \`prompt -s $2' to use it in future sessions." else print "$usage" fi @@ -65,22 +83,33 @@ Options: ;; p) if (( ! $+prompt_theme )); then print "Cannot preview; current prompt is non-themeable and would" - print "be destroyed." - return + print "be destroyed." + return fi preview=( $prompt_themes ) - [[ -n "$2" && -n $prompt_themes[(r)$2] ]] && preview=( $*[2,-1] ) + (( $#* > 1 )) && preview=( "$@[2,-1]" ) for theme in $preview; do - [[ $theme == $prompt_theme[1] ]] && continue - print "\nTheme: $theme" - prompt_${theme}_setup - precmd - print -n -P "${PS1}" - preexec - print "command arg1 arg2 ... argn" + theme_args=( "$=theme" ) + [[ "$theme" == "$prompt_theme[*]" ]] && continue + if [[ -z "$prompt_themes[(r)$theme_args[1]]" ]]; then + print "\nUnknown theme: $theme_args[1]" + continue + fi + print + + # The next line is a bit ugly. It (perhaps unnecessarily) + # runs the prompt theme setup function to ensure that if + # the theme has a _preview function that it's been autoloaded. + prompt_${theme_args[1]}_setup + + if functions prompt_${theme_args[1]}_preview >&/dev/null; then + prompt_${theme_args[1]}_preview "${(@)theme_args[2,-1]}" + else + prompt_preview_theme "${(@)theme_args}" + fi done print - prompt_${prompt_theme}_setup + prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}" ;; s) print "Set and save not yet implemented. Please ensure your ~/.zshrc" print "contains something similar to the following:\n" @@ -88,12 +117,22 @@ Options: print " promptinit" print " prompt $*[2,-1]" ;; - *) if [[ -z "$1" || -z $prompt_themes[(r)$1] ]]; then + *) if [[ "$1" == 'random' ]]; then + local random_themes + if (( $#* == 1 )); then + random_themes=( $prompt_themes ) + else + random_themes=( "$@[2,-1]" ) + fi + local i=$(( ( $RANDOM % $#random_themes ) + 1 )) + argv=( "${=random_themes[$i]}" ) + fi + if [[ -z "$1" || -z $prompt_themes[(r)$1] ]]; then print "$usage" return fi - prompt_$1_setup $*[2,-1] - prompt_theme=( $* ) + prompt_$1_setup "$@[2,-1]" + prompt_theme=( "$@" ) # Avoid screwing up the environment listing PSZZZZ=$reset_color @@ -114,4 +153,15 @@ prompt () { setopt noprompt{bang,cr,percent,subst} prompt${^prompt_opts[@]} } +prompt_preview_theme () { + print -n "$1 theme" + (( $#* > 1 )) && print -n " with parameters \`$*[2,-1]'" + print ":" + prompt_${1}_setup "$@[2,-1]" + precmd + print -n -P "${PS1}" + preexec + print "command arg1 arg2 ... argn" +} + promptinit "$@" -- cgit 1.4.1