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 ++++ .zshrc | 10 +++++----- bin/update_aur_cnt | 4 ++++ bin/update_pac_cnt | 4 ++++ 9 files changed, 71 insertions(+), 11 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 create mode 100755 bin/update_aur_cnt create mode 100755 bin/update_pac_cnt 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]}%}" diff --git a/.zshrc b/.zshrc index 5d7adff..0ec4dbd 100644 --- a/.zshrc +++ b/.zshrc @@ -1,6 +1,6 @@ # -*- Mode: shell-script -*- # Setup variables -PATH="${PATH}:/usr/local/bin:${HOME}/bin" +PATH="${HOME}/bin:${PATH}:/usr/local/bin" HISTFILE=~/.zsh/histfile HISTSIZE=1000 @@ -62,14 +62,14 @@ typeset -ga precmd_functions typeset -ga chpwd_functions # 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_updates' chpwd_functions+='chpwd_update_git_vars' # Set the prompt. -PROMPT='%{${fg[black]}%}%B$(line "$(~/.rootname.scm)")%b%{${fg[default]}%} -(%{${fg[magenta]}%}%m%{${fg[default]}%} %{${fg[cyan]}%}%B%~%b%{${fg[default]}%}) %(?.%{${fg[green]}%}O.%{${fg[red]}%}X)%{${fg[default]}%} %# ' -RPROMPT='$(prompt_git_info)%{${fg[default]}%}' +PROMPT='$(prompt)' +RPROMPT='$(rprompt)' # Set terminal name to current runnign application case $TERM in diff --git a/bin/update_aur_cnt b/bin/update_aur_cnt new file mode 100755 index 0000000..f083c6b --- /dev/null +++ b/bin/update_aur_cnt @@ -0,0 +1,4 @@ +#!/bin/bash + +/usr/bin/cower -uq 2>/dev/null \ + | wc -l 2>/dev/null > ~/.local/share/aur.cnt diff --git a/bin/update_pac_cnt b/bin/update_pac_cnt new file mode 100755 index 0000000..320e8a9 --- /dev/null +++ b/bin/update_pac_cnt @@ -0,0 +1,4 @@ +#!/bin/bash + +/usr/bin/pacman -Qu 2>/dev/null \ + | wc -l 2>/dev/null > ~/.local/share/updates.cnt -- cgit v1.2.3-54-g00ecf