dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/.config/zsh/conf/00_prompt.zsh

71 lines
1.8 KiB
Bash

# Set PS1 and RPS1
precmd() {
local cwd git_branch git_toplvl suffix newline
# -- Add a line before the prompt
[[ -v PS1_NL ]] && echo || PS1_NL=
newline=$'\n'
# -- PS1 (in precmd, avoid tools updating PS1)
if [[ $EUID == 0 ]]; then
suffix='%(?,%F{yellow},%F{red})%n%f:'
else
suffix='%(?,%F{yellow},%F{red})>%f'
fi
if [[ -n $SSH_CONNECTION ]]; then
PS1="%F{231}${SSH_TTY:+[%n@%m]}%f%B${SSH_TTY:+:}${newline}${suffix}%b "
else
PS1="%B${suffix}%b "
fi
# -- RPS1
# Error code if != 0
RPS1='%B%(?..%{%F{red}%}(%?%)%{%f%}) '
# if in git repo, print <branch>·<name>/<path>
if git_branch="$( git rev-parse --abbrev-ref HEAD 2>/dev/null )"; then
[[ -z "$(git status --porcelain 2>/dev/null)" ]] \
&& RPS1+="%F{green}${git_branch}%F{231} " \
|| RPS1+="%F{166}${git_branch}%F{231} "
git_toplvl="$( git rev-parse --show-toplevel 2>/dev/null )"
cwd="${${PWD##${git_toplvl}}:-/}"
RPS1+="%F{240}[%F{12}${git_toplvl##*/}%F{240}]%f%b"
else
RPS1+='%F{12}%2~%f%b'
fi
}
export SPROMPT="zsh: correct %F{red}'%R'%f to %F{green}'%r'%f [%B%Uy%u%bes, %B%Un%u%bo, %B%Ue%u%bdit, %B%Ua%u%bbort]? "
function zle-keymap-select {
if [[ ${KEYMAP} == vicmd ]] ||
[[ $1 = 'block' ]]; then
echo -ne '\e[2 q'
elif [[ ${KEYMAP} == main ]] ||
[[ ${KEYMAP} == viins ]] ||
[[ ${KEYMAP} = '' ]] ||
[[ $1 = 'beam' ]]; then
echo -ne '\e[6 q'
fi
}
zle -N zle-keymap-select
zle-line-init() {
echo -ne "\e[6 q"
}
zle -N zle-line-init
echo -ne '\e[5 q'
preexec() { echo -ne '\e[6 q' ;}
# (Un)set (r)prompts
PS2='%F{245}> %f'
PS3='%F{245}> %f'
PS4='%F{245}> %f'
unset RPS2 RPS3 RPS4
# Clear previous rprompts
setopt TRANSIENT_RPROMPT