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.
|
2024-07-24 15:49:35 +05:00
|
|
|
# Local will be black, remote and Distrobox - yellow.
|
2014-12-13 23:36:32 +05:00
|
|
|
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]%}"
|
2024-07-24 15:49:35 +05:00
|
|
|
elif [[ test -e /run/.containerenv -o -e /.dockerenv ]]; then
|
|
|
|
vars['brackets_start']="%{$fg[yellow]%}[%{$reset_color%}"
|
|
|
|
vars['brackets_end']="%{$fg[yellow]%}]%{$reset_color%}"
|
|
|
|
vars['console']="$vars['brackets_start']Distrobox$vars['brackets_end']"
|
|
|
|
vars['default_color']="%{$fg[cyan]%}"
|
2014-12-13 23:36:32 +05:00
|
|
|
else
|
2021-04-11 00:46:34 +05:00
|
|
|
vars['brackets_start']="%{$reset_color%}%{$fg[gray]%}[%{$reset_color%}"
|
|
|
|
vars['brackets_end']="%{$reset_color%}%{$fg[gray]%}]%{$reset_color%}"
|
2014-12-13 23:36:32 +05:00
|
|
|
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
|
|
|
|
|
2017-01-15 11:55:46 +05:00
|
|
|
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
|
|
|
|
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
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
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']"
|
2016-01-04 20:50:31 +05:00
|
|
|
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']"
|
2015-12-26 15:33:59 +05:00
|
|
|
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
|