.shincludes/source/prompt
2024-06-27 16:21:31 +03:00

73 lines
1.7 KiB
Text

# depends: grml-zsh-config
# virtualenv prompt prompt
HOSTNAME=$(</proc/sys/kernel/hostname)
function virtual_env_prompt () {
REPLY=${VIRTUAL_ENV+(${VIRTUAL_ENV:t}) }
}
grml_theme_add_token virtual-env -f virtual_env_prompt '%F{magenta}' '%f'
# show hostname when ssh'd in
function ssh_conn_prompt () {
REPLY=${SSH_CONNECTION+@${HOSTNAME:t} }
}
grml_theme_add_token ssh-conn -f ssh_conn_prompt '%F{white}' '%f'
# render root as red
function root_red_prompt () {
REPLY='%(!.%F{red}#%f.$) '
}
grml_theme_add_token root-red -f root_red_prompt
zstyle ':prompt:grml:left:setup' items rc ssh-conn virtual-env change-root path root-red
zstyle ':prompt:grml:right:setup' use-rprompt false
RPS1=''
function set_title_precmd () {
set_title ${(%):-"%~"}
}
# Sets the title as name of program currently running
function set_title_preexec () {
set_title "${(%):-}" "$2"
}
function emit_osc_seq_precmd() {
print -n "\e]133;A\e\\"
if ! builtin zle; then
print -n "\e]133;D\e\\"
fi
}
function emit_osc_seq_preexec() {
print -n "\e]133;C\e\\"
}
function osc7_pwd() {
emulate -L zsh # also sets localoptions for us
setopt extendedglob
local LC_ALL=C
printf '\e]7;file://%s%s\e\' $HOST ${PWD//(#m)([^@-Za-z&-;_~])/%${(l:2::0:)$(([##16]#MATCH))}}
}
function chpwd_osc7_pwd() {
(( ZSH_SUBSHELL )) || osc7_pwd
}
if [[ "$TERM" == (alacritty*|gnome*|konsole*|putty*|rxvt*|screen*|tmux*|xterm*|foot*) ]]; then
autoload -Uz add-zsh-hook
add-zsh-hook -Uz precmd set_title_precmd
add-zsh-hook -Uz preexec set_title_preexec
add-zsh-hook -Uz precmd emit_osc_seq_precmd
add-zsh-hook -Uz preexec emit_osc_seq_preexec
add-zsh-hook -Uz chpwd chpwd_osc7_pwd
fi
setopt nocorrect