2014-12-02 21:07:00 +05:00
|
|
|
# pztrn prompt theme
|
|
|
|
autoload -U add-zsh-hook
|
|
|
|
|
2015-12-26 15:33:59 +05:00
|
|
|
# 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'
|
|
|
|
|
2014-12-13 23:36:32 +05:00
|
|
|
prompt pztrn
|
2014-12-02 21:07:00 +05:00
|
|
|
|
2014-12-13 23:36:32 +05:00
|
|
|
There is no colors to define
|
2014-12-02 21:07:00 +05:00
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
prompt_pztrn_setup () {
|
2015-12-26 15:33:59 +05:00
|
|
|
emulate -L zsh
|
|
|
|
precmd_functions=(${precmd_functions[@]} "prompt_pztrn_gitinfo" "prompt_pztrn_createprompt")
|
2014-12-02 21:07:00 +05:00
|
|
|
|
2014-12-13 23:36:32 +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%}"
|
2014-12-14 04:37:07 +05:00
|
|
|
vars['console']="$vars['brackets_start']SSH$vars['brackets_end']"
|
2014-12-13 23:36:32 +05:00
|
|
|
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
|
|
|
|
2014-12-13 23:36:32 +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
|
|
|
|
2014-12-13 23:36:32 +05:00
|
|
|
[[ -n "$WINDOW" ]] && p_win="$WINDOW"
|
2014-12-02 21:07:00 +05:00
|
|
|
|
2015-03-01 09:57:58 +05:00
|
|
|
if [[ "$USER" == "root" ]]; then
|
2014-12-13 23:36:32 +05:00
|
|
|
vars['usercolor']="%{$fg[red]%}"
|
2014-12-02 21:13:26 +05:00
|
|
|
else
|
2014-12-13 23:36:32 +05:00
|
|
|
vars['usercolor']="%{$fg[blue]%}"
|
2014-12-02 21:13:26 +05:00
|
|
|
fi
|
|
|
|
|
2014-12-13 23:36:32 +05:00
|
|
|
p_userpwd="$vars['brackets_start']$vars['usercolor']%n$reset_color@%{$fg[magenta]%}%M$vars['brackets_end']"
|
2014-12-02 21:07:00 +05:00
|
|
|
|
2014-12-13 23:36:32 +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'])"
|
2014-12-14 04:33:45 +05:00
|
|
|
p_end="$vars['usercolor']%#%{$reset_color%} "
|
2014-12-02 21:07:00 +05:00
|
|
|
|
2014-12-14 04:33:45 +05:00
|
|
|
p_path="$vars['brackets_start']$vars['default_color'] %d $vars['brackets_end']"
|
2014-12-02 21:07:00 +05:00
|
|
|
|
2015-12-26 15:33:59 +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
|
2015-02-07 20:30:16 +05:00
|
|
|
$vars['console']$p_path $p_end"
|
2015-12-26 15:33:59 +05:00
|
|
|
RPROMPT="$p_date$p_tty$p_plat$p_userpwd$p_shlvlhist$p_rc$p_gitinfo
|
2014-12-13 23:36:32 +05:00
|
|
|
$vars['console']$p_path $p_end"
|
|
|
|
PS2='%(4_.\.)%3_> %E'
|
2014-12-02 21:07:00 +05:00
|
|
|
|
2014-12-13 23:36:32 +05:00
|
|
|
watch=all
|
2014-12-14 04:33:45 +05:00
|
|
|
logcheck=5
|
|
|
|
WATCHFMT="$vars['default_color']%n$reset_color from $fg[magenta]%M$reset_color has $vars['default_color']%a$reset_color (%l) at %T %W"
|
2014-12-02 21:07:00 +05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-26 15:33:59 +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$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"
|
|
|
|
}
|
|
|
|
|
2015-03-12 20:09:24 +05:00
|
|
|
prompt_pztrn_setup
|