zsh-config/zsh/prompts/pztrn.zsh

101 lines
3.7 KiB
Bash
Raw Normal View History

2014-12-02 21:07:00 +05:00
# pztrn prompt theme
autoload -U add-zsh-hook
# Common vars array.
declare -A vars
# Prompt parts.
declare p_date p_tty p_plat p_userpwd p_shlvlhist p_rc p_end p_win p_path p_gitinfo
2014-12-02 21:07:00 +05:00
prompt_pztrn_help () {
cat <<'EOF'
prompt pztrn
2014-12-02 21:07:00 +05:00
There is no colors to define
2014-12-02 21:07:00 +05:00
EOF
}
prompt_pztrn_setup () {
emulate -L zsh
precmd_functions=(${precmd_functions[@]} "prompt_pztrn_gitinfo" "prompt_pztrn_createprompt")
2014-12-02 21:07:00 +05:00
# Session-dependend colorizing.
# Local will be black, remote - yellow.
if [[ -n $SSH_TTY ]]; then
vars['brackets_start']="%{$fg[yellow]%}[%{$reset_color%}"
vars['brackets_end']="%{$fg[yellow]%}]%{$reset_color%}"
vars['console']="$vars['brackets_start']SSH$vars['brackets_end']"
vars['default_color']="%{$fg[cyan]%}"
else
vars['brackets_start']="%{$fg[black]%}[%{$reset_color%}"
vars['brackets_end']="%{$fg[black]%}]%{$reset_color%}"
vars['console']=""
vars['default_color']="%{$fg[green]%}"
fi
2014-12-02 21:07:00 +05:00
p_date="$vars['brackets_start']$vars['default_color']%D{%a %Y/%m/%d %R}$vars['brackets_end']"
p_tty="$vars['brackets_start']$vars['default_color']%l$vars['brackets_end']"
p_plat="$vars['brackets_start']$vars['default_color']$(uname -r)$vars['brackets_end']"
2014-12-02 21:07:00 +05:00
[[ -n "$WINDOW" ]] && p_win="$WINDOW"
2014-12-02 21:07:00 +05:00
if [[ "$USER" == "root" ]]; then
vars['usercolor']="%{$fg[red]%}"
2014-12-02 21:13:26 +05:00
else
vars['usercolor']="%{$fg[blue]%}"
2014-12-02 21:13:26 +05:00
fi
p_hostname=$(hostname -f)
p_userpwd="$vars['brackets_start']$vars['usercolor']%n$reset_color@%{$fg[magenta]%}$p_hostname$vars['brackets_end']"
2014-12-02 21:07:00 +05:00
p_shlvlhist="$vars['brackets_start']$vars['default_color']%B%h%b$vars['brackets_end']"
p_rc="%(?..$vars['brackets_start']$fg[red]%?%1v$vars['brackets_end'])"
p_end="$vars['usercolor']%#%{$reset_color%} "
2014-12-02 21:07:00 +05:00
p_path="$vars['brackets_start']$vars['default_color'] %d $vars['brackets_end']"
2014-12-02 21:07:00 +05:00
# Initial prompt creation. On every cd it will be recreated with
# prompt_pztrn_createprompt function.
PROMPT="$p_date$p_tty$p_plat$p_userpwd$p_shlvlhist$p_rc$p_gitinfo
$vars['console']$p_path $p_end"
RPROMPT="$p_date$p_tty$p_plat$p_userpwd$p_shlvlhist$p_rc$p_gitinfo
$vars['console']$p_path $p_end"
PS2='%(4_.\.)%3_> %E'
2014-12-02 21:07:00 +05:00
watch=all
logcheck=5
2015-12-30 10:42:17 +05:00
WATCHFMT="$fg[green]%n$reset_color from $fg[magenta]%M$reset_color has $fg[green]%a$reset_color (%l) at %T %W"
2014-12-02 21:07:00 +05:00
}
prompt_pztrn_gitinfo()
{
# Git repository information.
# Depends on 'gitinfo' application.
gitinfo_present=`declare -f gitinfo_check`
if [ $gitinfo_present ]; then
gitinfo_check
#echo $?
if [[ $? -eq 0 ]]; then
p_gitinfo_branch="$vars['brackets_start']$vars['usercolor']${GITINFO_BRANCH}$reset_color$vars['brackets_end']"
p_gitinfo_commit="$vars['brackets_start']%{$fg[magenta]%}${GITINFO_COMMIT_SHORTID}$reset_color (%{$fg[cyan]%}${GITINFO_COMMIT_COUNT}$reset_color)$vars['brackets_end']"
p_gitinfo_remotes="$vars['brackets_start']%{$fg[green]%}${GITINFO_REMOTES} remote(s)$reset_color$vars['brackets_end']"
p_gitinfo_files="$vars['brackets_start']%{$fg[green]%}${GITINFO_NEW_FILES}$reset_color new, %{$fg[yellow]%}${GITINFO_MODIFIED_FILES}$reset_color modified, %{$fg[red]%}${GITINFO_DELETED_FILES}$reset_color deleted, %{$fg[gray]%}${GITINFO_UNTRACKED_COUNT}$reset_color untracked$vars['brackets_end']"
p_gitinfo=$'\n'"$p_gitinfo_branch$p_gitinfo_commit$p_gitinfo_files$p_gitinfo_remotes"
else
p_gitinfo=""
fi
fi
}
prompt_pztrn_createprompt()
{
PROMPT="$p_date$p_tty$p_plat$p_userpwd$p_shlvlhist$p_rc$p_gitinfo
$vars['console']$p_path $p_end"
RPROMPT="$p_date$p_tty$p_plat$p_userpwd$p_shlvlhist$p_rc$p_gitinfo
$vars['console']$p_path $p_end"
}
prompt_pztrn_setup