Prompt configuration to a prompt theme
Move my prompt configuration to a prompt theme function in my $fpath. I call it 'loquacious'. The prompt is configured by the prompt_loquacious_setup function. This change also necessitated a new function called prompt_colorize to generate a string with the correct set of color escapes for the prompt.
This commit is contained in:
parent
b80715ccea
commit
66438f666c
3 changed files with 213 additions and 90 deletions
38
zsh/func/prompt_colorize
Normal file
38
zsh/func/prompt_colorize
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/zsh
|
||||
# Return a prompt string with appropriate color escapes
|
||||
# Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
local bold=0
|
||||
local foreground=''
|
||||
local background=''
|
||||
|
||||
while getopts 'bf:k:' opt; do
|
||||
case $opt in
|
||||
b) bold=1;;
|
||||
f) foreground=$OPTARG;;
|
||||
k) background=$OPTARG;;
|
||||
*) echo "Unknown option: $opt" 1>&2; return -1;;
|
||||
esac
|
||||
done
|
||||
|
||||
local str=$@[$OPTIND,${#@}]
|
||||
|
||||
autoload -U is-at-least
|
||||
if is-at-least '4.3.7'; then
|
||||
[[ -n "$foreground" ]] && str="%F{$foreground}$str%f"
|
||||
[[ -n "$background" ]] && str="%K{$background}$str%k"
|
||||
[[ $bold -eq 1 ]] && str="%B$str%b"
|
||||
else
|
||||
local fg_hash bg_hash
|
||||
if [[ $bold -eq 1 ]]; then
|
||||
fg_hash='fg_bold'
|
||||
bg_hash='bg_bold'
|
||||
else
|
||||
fg_hash='fg_no_bold'
|
||||
bg_hash='bg_no_bold'
|
||||
fi
|
||||
[[ -n "$foreground" ]] && str="%{\$${fg_hash}[$foreground]%}$str%{\$reset_color%}"
|
||||
[[ -n "$background" ]] && str="%%{\$${bg_hash}[$background]%}$str%{\$reset_color%}"
|
||||
fi
|
||||
|
||||
print $str
|
Loading…
Add table
Add a link
Reference in a new issue