ZSH: Change prompt again

Change the prompt and divide into extra files.
This commit is contained in:
Tom Willemsen 2012-01-06 16:02:15 +01:00
parent 21eb3b9ec8
commit 63bbc2e2ea
9 changed files with 71 additions and 11 deletions

15
.zsh/functions/get_cnt Normal file
View file

@ -0,0 +1,15 @@
# -*- mode: shell-script -*-
if [ -n "$1" ]; then
if [ -e "~/.local/share/$1.cnt" ]; then
cnt=$(/bin/cat "~/.local/share/$1.cnt")
fi
if [ -z "$cnt" ]; then
cnt=0
fi
echo $cnt
else
echo "No count name specified" >&2
fi

View file

@ -0,0 +1,11 @@
# -*- mode: shell-script -*-
if [ -n "$__EXECUTED_PACMAN_COMMAND" ]; then
update_pac_cnt
unset __EXECUTED_PACMAN_COMMAND
fi
if [ -n "$__EXECUTED_COWER_COMMAND" ]; then
update_aur_cnt
unset __EXECUTED_COWER_COMMAND
fi

View file

@ -1,6 +0,0 @@
# -*- mode: shell-script -*-
case "$1" in
git*)
__EXECUTED_GIT_COMMAND=1
;;
esac

View file

@ -0,0 +1,12 @@
# -*- mode: shell-script -*-
case "$1" in
git*)
__EXECUTED_GIT_COMMAND=1
;;
cower)
__EXECUTED_COWER_COMMAND=1
;;
pacman)
__EXECUTED_PACMAN_COMMAND=1
;;
esac

16
.zsh/functions/prompt Normal file
View file

@ -0,0 +1,16 @@
# -*- mode: shell-script -*-
local pac_cnt=$(get_cnt updates)
local aur_cnt=$(get_cnt aur)
local hostname=$(hostname | cut -d . -f 1)
if [ $pac_cnt -gt 0 -o $aur_cnt -gt 0 ]; then
printf "%s%d%s/%s%d%s:" \
"%{${fg[cyan]}%}" $pac_cnt "%{${fg[default]}%}" \
"%{${fg[cyan]}%}" $aur_cnt "%{${fg[default]}%}"
fi
printf '%s%s%s:%s%s%s%s>%s ' \
"%{${fg[magenta]}%}" $hostname "%{${fg[default]}%}" \
"%{${fg[green]}%}" "%~" "%{${fg[default]}%}" \
"%(?.%{${fg[green]}%}.%{${fg[red]}%})%B" "%b%{${fg[default]}%}"

4
.zsh/functions/rprompt Normal file
View file

@ -0,0 +1,4 @@
# -*- mode: shell-script -*-
local git_info="$(prompt_git_info)"
printf '%s%s' $git_info "%{${fg[default]}%}"

10
.zshrc
View file

@ -1,6 +1,6 @@
# -*- Mode: shell-script -*- # -*- Mode: shell-script -*-
# Setup variables # Setup variables
PATH="${PATH}:/usr/local/bin:${HOME}/bin" PATH="${HOME}/bin:${PATH}:/usr/local/bin"
HISTFILE=~/.zsh/histfile HISTFILE=~/.zsh/histfile
HISTSIZE=1000 HISTSIZE=1000
@ -62,14 +62,14 @@ typeset -ga precmd_functions
typeset -ga chpwd_functions typeset -ga chpwd_functions
# Append git functions needed for prompt. # Append git functions needed for prompt.
preexec_functions+='preexec_update_git_vars' preexec_functions+='preexec_update_vars'
precmd_functions+='precmd_update_git_vars' precmd_functions+='precmd_update_git_vars'
precmd_functions+='precmd_update_updates'
chpwd_functions+='chpwd_update_git_vars' chpwd_functions+='chpwd_update_git_vars'
# Set the prompt. # Set the prompt.
PROMPT='%{${fg[black]}%}%B$(line "$(~/.rootname.scm)")%b%{${fg[default]}%} PROMPT='$(prompt)'
(%{${fg[magenta]}%}%m%{${fg[default]}%} %{${fg[cyan]}%}%B%~%b%{${fg[default]}%}) %(?.%{${fg[green]}%}O.%{${fg[red]}%}X)%{${fg[default]}%} %# ' RPROMPT='$(rprompt)'
RPROMPT='$(prompt_git_info)%{${fg[default]}%}'
# Set terminal name to current runnign application # Set terminal name to current runnign application
case $TERM in case $TERM in

4
bin/update_aur_cnt Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
/usr/bin/cower -uq 2>/dev/null \
| wc -l 2>/dev/null > ~/.local/share/aur.cnt

4
bin/update_pac_cnt Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
/usr/bin/pacman -Qu 2>/dev/null \
| wc -l 2>/dev/null > ~/.local/share/updates.cnt