1
0
Fork 0

zsh: more prompt magic

This commit is contained in:
Von Random 2023-08-03 19:51:22 +03:00
parent 36925c573c
commit f127304069
2 changed files with 11 additions and 10 deletions

View file

@ -14,19 +14,20 @@ typeset -A prompt_symbols=(
git_staged $'\u2713' git_staged $'\u2713'
git_untracked '!' git_untracked '!'
git_unmerged '*' git_unmerged '*'
bang $'\n %F{10}\u266a%f' bang $'\u266a'
) )
typeset -A prompt_colors=( typeset -A prompt_colors=(
fg '15' # fg '15'
root '1' root '1'
ssh '0' ssh '15'
cwd '4' cwd '4'
git_branch '237' git_branch '241'
git_unstaged '3' git_unstaged '3'
git_staged '6' git_staged '6'
git_untracked '1' git_untracked '1'
git_unmerged '5' git_unmerged '5'
# bang '10'
) )
precmd.is_git_repo() { precmd.is_git_repo() {
@ -35,7 +36,7 @@ precmd.is_git_repo() {
[[ ! -e $prompt_git_dir/nozsh ]] [[ ! -e $prompt_git_dir/nozsh ]]
} }
precmd.prompt.add_plain() { precmd.prompt.add() {
(( $# < 1 )) && return 1 (( $# < 1 )) && return 1
typeset data=$1 color=$2 typeset data=$1 color=$2
[[ -n $prompt_string ]] && prompt_string+=" " [[ -n $prompt_string ]] && prompt_string+=" "
@ -46,7 +47,7 @@ precmd.prompt.add_plain() {
fi fi
} }
precmd.prompt.add() { precmd.prompt.add_pl() {
(( $# < 2 )) && return 1 (( $# < 2 )) && return 1
typeset data=$1 color=$2 typeset data=$1 color=$2
if [[ -z $prompt_string ]]; then if [[ -z $prompt_string ]]; then
@ -96,7 +97,7 @@ precmd.prompt.git() {
precmd.prompt() { precmd.prompt() {
typeset -g prompt_string= prev_color= typeset -g prompt_string= prev_color=
precmd.prompt.add \[ 7 precmd.prompt.add '['
(( UID )) \ (( UID )) \
|| precmd.prompt.add '#' $prompt_colors[root] || precmd.prompt.add '#' $prompt_colors[root]
[[ -n $SSH_CONNECTION ]]\ [[ -n $SSH_CONNECTION ]]\
@ -109,8 +110,8 @@ precmd.prompt() {
[[ $1 == git ]]\ [[ $1 == git ]]\
&& precmd.prompt.git && precmd.prompt.git
precmd.prompt.add \] 7 precmd.prompt.add $']\n'
prompt_string+="%F{$prev_color}%k$prompt_symbols[sep_a]%f$prompt_symbols[bang] " prompt_string+="%F{$prompt_colors[bang]}$prompt_symbols[bang]%f "
} }
precmd.git_update() { precmd.git_update() {

View file

@ -5,7 +5,7 @@ confdir=$HOME/.config/zsh
conflist=( conflist=(
env.zsh env.zsh
settings.zsh settings.zsh
powerline.zsh prompt.zsh
functions.zsh functions.zsh
local.zsh local.zsh
) )