Move prompt to partial
This commit is contained in:
parent
e56ca195f7
commit
c391bf9589
144
zsh.d/prompt.zsh
Normal file
144
zsh.d/prompt.zsh
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
# vim: ft=zsh
|
||||||
|
|
||||||
|
# Based on agnoster's Theme - https://gist.github.com/3712874
|
||||||
|
|
||||||
|
CURRENT_BG='NONE'
|
||||||
|
|
||||||
|
prompt_segment() {
|
||||||
|
local direction newbg newfg text
|
||||||
|
direction="$1"
|
||||||
|
newbg="$2"
|
||||||
|
newfg="$3"
|
||||||
|
text="$4"
|
||||||
|
if [[ -z $text ]]; then return; fi
|
||||||
|
if [[ $newbg != $CURRENT_BG ]]; then
|
||||||
|
if [[ "$direction" == 'forward' ]]; then
|
||||||
|
if [[ $CURRENT_BG != 'NONE' ]]; then
|
||||||
|
print -n "%{%K{$newbg}%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_FORWARD%{%F{$newfg}%}"
|
||||||
|
else
|
||||||
|
print -n "%{%K{$newbg}%F{$newfg}%}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print -n "%{%F{$newbg}%}$SEGMENT_SEPARATOR_BACKWARD%{%F{$newfg}%K{$newbg}%}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
print -n " $text "
|
||||||
|
CURRENT_BG=$newbg
|
||||||
|
}
|
||||||
|
|
||||||
|
# End the prompt, closing any open segments
|
||||||
|
prompt_end() {
|
||||||
|
if [[ -n $CURRENT_BG ]]; then
|
||||||
|
print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_FORWARD"
|
||||||
|
fi
|
||||||
|
CURRENT_BG=''
|
||||||
|
}
|
||||||
|
|
||||||
|
prompt_clear() {
|
||||||
|
print -n "%{%k%f%}"
|
||||||
|
CURRENT_BG=''
|
||||||
|
}
|
||||||
|
|
||||||
|
### Prompt components
|
||||||
|
# Each component will draw itself, and hide itself if no information needs to be shown
|
||||||
|
|
||||||
|
# Root privileges
|
||||||
|
prompt_root() {
|
||||||
|
if [[ $UID -eq 0 ]]; then
|
||||||
|
print -n $SUPERUSER_CHARACTER
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Different username
|
||||||
|
prompt_user() {
|
||||||
|
local user=$USER
|
||||||
|
if command-exists whoami && [[ -z $user ]]; then
|
||||||
|
user=$(whoami)
|
||||||
|
fi
|
||||||
|
if [[ "$user" != "$DEFAULT_USER" && $UID -ne 0 ]]; then
|
||||||
|
print -n $user
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Different host
|
||||||
|
prompt_host() {
|
||||||
|
if [[ -n "$SSH_CONNECTION" ]]; then
|
||||||
|
print -n "%m"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Makefile exists
|
||||||
|
prompt_makefile() {
|
||||||
|
if [[ -f Makefile ]]; then
|
||||||
|
print -n "make"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Status:
|
||||||
|
# - was there an error
|
||||||
|
# - are there background jobs?
|
||||||
|
prompt_status() {
|
||||||
|
local symbols
|
||||||
|
symbols=()
|
||||||
|
if [[ $LAST_RETURN_VALUE -ne 0 ]]; then
|
||||||
|
symbols+="%{%F{red}%}$FAILED_CHARACTER%{%f%}"
|
||||||
|
else
|
||||||
|
symbols+="%{%F{green}%}$SUCCESS_CHARACTER%{%f%}"
|
||||||
|
fi
|
||||||
|
if [[ $(jobs -l) ]]; then
|
||||||
|
symbols+="%{%F{cyan}%}$JOBS_CHARACTER%{%f%}"
|
||||||
|
else
|
||||||
|
symbols+="%{%F{white}%}$NO_JOBS_CHARACTER%{%f%}"
|
||||||
|
fi
|
||||||
|
echo "$symbols"
|
||||||
|
}
|
||||||
|
|
||||||
|
## Main prompt
|
||||||
|
prompt_forward() {
|
||||||
|
CURRENT_BG='NONE'
|
||||||
|
prompt_segment forward black default "$(prompt_status)"
|
||||||
|
prompt_segment forward red yellow "$(prompt_root)"
|
||||||
|
prompt_segment forward magenta black "$(prompt_user)"
|
||||||
|
prompt_segment forward cyan black "$(prompt_host)"
|
||||||
|
prompt_segment forward blue black '%~' # prompt directory
|
||||||
|
prompt_end
|
||||||
|
prompt_clear
|
||||||
|
}
|
||||||
|
|
||||||
|
## Reverse prompt
|
||||||
|
prompt_backward() {
|
||||||
|
CURRENT_BG='NONE'
|
||||||
|
prompt_segment backward magenta black "$MAVEN_PROJECT" # prompt maven project
|
||||||
|
prompt_segment backward cyan black "$PACKAGE_JSON_PROJECT" # prompt package.json project
|
||||||
|
prompt_segment backward cyan black "$(prompt_makefile)"
|
||||||
|
prompt_segment backward yellow black "$vcs_info_msg_0_" # prompt vcs
|
||||||
|
prompt_segment backward green black "%T" # prompt time
|
||||||
|
prompt_clear
|
||||||
|
}
|
||||||
|
|
||||||
|
prompt2_forward() {
|
||||||
|
CURRENT_BG='NONE'
|
||||||
|
prompt_segment forward black default "$(prompt_status)"
|
||||||
|
prompt_segment forward red yellow "$(prompt_root)"
|
||||||
|
prompt_segment forward magenta black "$(prompt_user)"
|
||||||
|
prompt_segment forward cyan black "$(prompt_host)"
|
||||||
|
prompt_segment forward blue black '%~' # prompt directory
|
||||||
|
prompt_segment forward red black '%_' # unmatched quote
|
||||||
|
prompt_end
|
||||||
|
prompt_clear
|
||||||
|
}
|
||||||
|
|
||||||
|
prompt_precmd() {
|
||||||
|
vcs_info
|
||||||
|
PROMPT="%{%f%b%k%}$(prompt_forward) "
|
||||||
|
PS="$PROMPT"
|
||||||
|
PS2="%{%f%b%k%}$(prompt2_forward) "
|
||||||
|
RPROMPT="%{%f%b%k%}$(prompt_backward)"
|
||||||
|
PRS="$RPROMPT"
|
||||||
|
SPROMPT="Correct %{%F{red}%}%R%{%f%} to %{%F{green}%}%r%f? [%Uy%ues|%Un%uo|%Ua%ubort|%Ue%udit] "
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLE_RPROMPT_INDENT=1
|
||||||
|
prompt_opts=(cr subst percent)
|
||||||
|
|
||||||
|
add-zsh-hook precmd prompt_precmd
|
||||||
145
zshrc
145
zshrc
@ -190,151 +190,6 @@ export HISTFILE=~/.zsh_history
|
|||||||
export HISTSIZE=1000000
|
export HISTSIZE=1000000
|
||||||
export SAVEHIST=1000000
|
export SAVEHIST=1000000
|
||||||
|
|
||||||
#---------------------------------- Prompt ------------------------------------
|
|
||||||
|
|
||||||
# Based on agnoster's Theme - https://gist.github.com/3712874
|
|
||||||
|
|
||||||
CURRENT_BG='NONE'
|
|
||||||
|
|
||||||
prompt_segment() {
|
|
||||||
local direction newbg newfg text
|
|
||||||
direction="$1"
|
|
||||||
newbg="$2"
|
|
||||||
newfg="$3"
|
|
||||||
text="$4"
|
|
||||||
if [[ -z $text ]]; then return; fi
|
|
||||||
if [[ $newbg != $CURRENT_BG ]]; then
|
|
||||||
if [[ "$direction" == 'forward' ]]; then
|
|
||||||
if [[ $CURRENT_BG != 'NONE' ]]; then
|
|
||||||
print -n "%{%K{$newbg}%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_FORWARD%{%F{$newfg}%}"
|
|
||||||
else
|
|
||||||
print -n "%{%K{$newbg}%F{$newfg}%}"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
print -n "%{%F{$newbg}%}$SEGMENT_SEPARATOR_BACKWARD%{%F{$newfg}%K{$newbg}%}"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
print -n " $text "
|
|
||||||
CURRENT_BG=$newbg
|
|
||||||
}
|
|
||||||
|
|
||||||
# End the prompt, closing any open segments
|
|
||||||
prompt_end() {
|
|
||||||
if [[ -n $CURRENT_BG ]]; then
|
|
||||||
print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_FORWARD"
|
|
||||||
fi
|
|
||||||
CURRENT_BG=''
|
|
||||||
}
|
|
||||||
|
|
||||||
prompt_clear() {
|
|
||||||
print -n "%{%k%f%}"
|
|
||||||
CURRENT_BG=''
|
|
||||||
}
|
|
||||||
|
|
||||||
### Prompt components
|
|
||||||
# Each component will draw itself, and hide itself if no information needs to be shown
|
|
||||||
|
|
||||||
# Root privileges
|
|
||||||
prompt_root() {
|
|
||||||
if [[ $UID -eq 0 ]]; then
|
|
||||||
print -n $SUPERUSER_CHARACTER
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Different username
|
|
||||||
prompt_user() {
|
|
||||||
local user=$USER
|
|
||||||
if command-exists whoami && [[ -z $user ]]; then
|
|
||||||
user=$(whoami)
|
|
||||||
fi
|
|
||||||
if [[ "$user" != "$DEFAULT_USER" && $UID -ne 0 ]]; then
|
|
||||||
print -n $user
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Different host
|
|
||||||
prompt_host() {
|
|
||||||
if [[ -n "$SSH_CONNECTION" ]]; then
|
|
||||||
print -n "%m"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Makefile exists
|
|
||||||
prompt_makefile() {
|
|
||||||
if [[ -f Makefile ]]; then
|
|
||||||
print -n "make"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Status:
|
|
||||||
# - was there an error
|
|
||||||
# - are there background jobs?
|
|
||||||
prompt_status() {
|
|
||||||
local symbols
|
|
||||||
symbols=()
|
|
||||||
if [[ $LAST_RETURN_VALUE -ne 0 ]]; then
|
|
||||||
symbols+="%{%F{red}%}$FAILED_CHARACTER%{%f%}"
|
|
||||||
else
|
|
||||||
symbols+="%{%F{green}%}$SUCCESS_CHARACTER%{%f%}"
|
|
||||||
fi
|
|
||||||
if [[ $(jobs -l) ]]; then
|
|
||||||
symbols+="%{%F{cyan}%}$JOBS_CHARACTER%{%f%}"
|
|
||||||
else
|
|
||||||
symbols+="%{%F{white}%}$NO_JOBS_CHARACTER%{%f%}"
|
|
||||||
fi
|
|
||||||
echo "$symbols"
|
|
||||||
}
|
|
||||||
|
|
||||||
## Main prompt
|
|
||||||
prompt_forward() {
|
|
||||||
CURRENT_BG='NONE'
|
|
||||||
prompt_segment forward black default "$(prompt_status)"
|
|
||||||
prompt_segment forward red yellow "$(prompt_root)"
|
|
||||||
prompt_segment forward magenta black "$(prompt_user)"
|
|
||||||
prompt_segment forward cyan black "$(prompt_host)"
|
|
||||||
prompt_segment forward blue black '%~' # prompt directory
|
|
||||||
prompt_end
|
|
||||||
prompt_clear
|
|
||||||
}
|
|
||||||
|
|
||||||
## Reverse prompt
|
|
||||||
prompt_backward() {
|
|
||||||
CURRENT_BG='NONE'
|
|
||||||
prompt_segment backward magenta black "$MAVEN_PROJECT" # prompt maven project
|
|
||||||
prompt_segment backward cyan black "$PACKAGE_JSON_PROJECT" # prompt package.json project
|
|
||||||
prompt_segment backward cyan black "$(prompt_makefile)"
|
|
||||||
prompt_segment backward yellow black "$vcs_info_msg_0_" # prompt vcs
|
|
||||||
prompt_segment backward green black "%T" # prompt time
|
|
||||||
prompt_clear
|
|
||||||
}
|
|
||||||
|
|
||||||
prompt2_forward() {
|
|
||||||
CURRENT_BG='NONE'
|
|
||||||
prompt_segment forward black default "$(prompt_status)"
|
|
||||||
prompt_segment forward red yellow "$(prompt_root)"
|
|
||||||
prompt_segment forward magenta black "$(prompt_user)"
|
|
||||||
prompt_segment forward cyan black "$(prompt_host)"
|
|
||||||
prompt_segment forward blue black '%~' # prompt directory
|
|
||||||
prompt_segment forward red black '%_' # unmatched quote
|
|
||||||
prompt_end
|
|
||||||
prompt_clear
|
|
||||||
}
|
|
||||||
|
|
||||||
prompt_precmd() {
|
|
||||||
vcs_info
|
|
||||||
PROMPT="%{%f%b%k%}$(prompt_forward) "
|
|
||||||
PS="$PROMPT"
|
|
||||||
PS2="%{%f%b%k%}$(prompt2_forward) "
|
|
||||||
RPROMPT="%{%f%b%k%}$(prompt_backward)"
|
|
||||||
PRS="$RPROMPT"
|
|
||||||
SPROMPT="Correct %{%F{red}%}%R%{%f%} to %{%F{green}%}%r%f? [%Uy%ues|%Un%uo|%Ua%ubort|%Ue%udit] "
|
|
||||||
}
|
|
||||||
|
|
||||||
ZLE_RPROMPT_INDENT=1
|
|
||||||
prompt_opts=(cr subst percent)
|
|
||||||
|
|
||||||
add-zsh-hook precmd prompt_precmd
|
|
||||||
|
|
||||||
#---------------------------------- VCS ---------------------------------------
|
#---------------------------------- VCS ---------------------------------------
|
||||||
|
|
||||||
autoload -Uz vcs_info
|
autoload -Uz vcs_info
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user