From 63bbc2e2ea8c0a5a26571b95f6b61e6f6a39b0ab Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Fri, 6 Jan 2012 16:02:15 +0100 Subject: ZSH: Change prompt again Change the prompt and divide into extra files. --- .zsh/functions/get_cnt | 15 +++++++++++++++ .zsh/functions/precmd_update_updates | 11 +++++++++++ .zsh/functions/preexec_update_git_vars | 6 ------ .zsh/functions/preexec_update_vars | 12 ++++++++++++ .zsh/functions/prompt | 16 ++++++++++++++++ .zsh/functions/rprompt | 4 ++++ 6 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 .zsh/functions/get_cnt create mode 100644 .zsh/functions/precmd_update_updates delete mode 100755 .zsh/functions/preexec_update_git_vars create mode 100644 .zsh/functions/preexec_update_vars create mode 100644 .zsh/functions/prompt create mode 100644 .zsh/functions/rprompt (limited to '.zsh/functions') diff --git a/.zsh/functions/get_cnt b/.zsh/functions/get_cnt new file mode 100644 index 0000000..5b06e00 --- /dev/null +++ b/.zsh/functions/get_cnt @@ -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 diff --git a/.zsh/functions/precmd_update_updates b/.zsh/functions/precmd_update_updates new file mode 100644 index 0000000..639fd5c --- /dev/null +++ b/.zsh/functions/precmd_update_updates @@ -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 diff --git a/.zsh/functions/preexec_update_git_vars b/.zsh/functions/preexec_update_git_vars deleted file mode 100755 index 9d229a9..0000000 --- a/.zsh/functions/preexec_update_git_vars +++ /dev/null @@ -1,6 +0,0 @@ -# -*- mode: shell-script -*- -case "$1" in - git*) - __EXECUTED_GIT_COMMAND=1 - ;; -esac diff --git a/.zsh/functions/preexec_update_vars b/.zsh/functions/preexec_update_vars new file mode 100644 index 0000000..70f3d68 --- /dev/null +++ b/.zsh/functions/preexec_update_vars @@ -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 diff --git a/.zsh/functions/prompt b/.zsh/functions/prompt new file mode 100644 index 0000000..af15976 --- /dev/null +++ b/.zsh/functions/prompt @@ -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]}%}" diff --git a/.zsh/functions/rprompt b/.zsh/functions/rprompt new file mode 100644 index 0000000..3392379 --- /dev/null +++ b/.zsh/functions/rprompt @@ -0,0 +1,4 @@ +# -*- mode: shell-script -*- + +local git_info="$(prompt_git_info)" +printf '%s%s' $git_info "%{${fg[default]}%}" -- cgit v1.2.3-54-g00ecf