prompt: improve tmux compatibility (3/3)

This commit is contained in:
Martin Sekera 2022-02-01 20:17:42 +01:00
parent 4490d2690d
commit 5170fda321
2 changed files with 21 additions and 12 deletions

View file

@ -11,3 +11,6 @@
# Indicators of free space (storage, memory and swap) will turn red when there's at most this fraction of free space left.
#OVER_PROMPT_FREESPACE_YELL=0.05
# Bell when a command completes (0 to disable)
#OVER_PROMPT_BELL=1

View file

@ -3,33 +3,39 @@
zmodload zsh/datetime
OVER_PROMPT_CFG="/etc/over/env/prompt.cfg"
OVER_PROMPT_TITLE=""
if [[ -a "$OVER_PROMPT_CFG" ]]; then
source "$OVER_PROMPT_CFG"
fi
# emits garbage on tmux, where it's not really needed anyway
if [[ -n "$TMUX" ]]; then
function __over_prompt_set_title {
if [[ ${TERM} =~ "screen" ]]; then
print -Pn "\033k\033${@}\033\134"
fi
}
else
function __over_prompt_set_title { }
fi
function __over_prompt_set_title {
if [[ -n "${OVER_PROMPT_TITLE}" ]]; then
print -Pn "\033k${OVER_PROMPT_TITLE}\033\134"
else
print -Pn "\033k${@}\033\134"
fi
}
function set_title {
OVER_PROMPT_TITLE="$1"
}
function __over_prompt_preexec {
__over_prompt_set_title "${USER}: ${PWD} -> ${1}"
__over_prompt_set_title "${1:0:8}"
OVER_PROMPT_CMD_START=${EPOCHSECONDS}
}
function __over_prompt_precmd {
__over_prompt_set_title "${USER}: ${PWD}"
__over_prompt_set_title "${USER}"
python3 /usr/share/over-env/prompt.py "${COLUMNS}" "${PWD}" "${OVER_PROMPT_LAST_REFRESH}" "${OVER_PROMPT_SYSLOAD_WARN:=1.25}" "${OVER_PROMPT_SYSLOAD_YELL:=3.0}" "${OVER_PROMPT_FREESPACE_WARN:=0.15}" "${OVER_PROMPT_FREESPACE_YELL:=0.05}" "${OVER_PROMPT_CMD_START}"
PS1="$(print "%(?.%{\e[1;36m%}.%{\e[1;31m%}%?%{\e[0m%}:%{\e[1;31m%})%(\!.#.$)%{\e[0m%} ")"
OVER_PROMPT_LAST_REFRESH=${EPOCHSECONDS}
OVER_PROMPT_CMD_START=0
if [[ "${OVER_PROMPT_BELL:=1}" == "1" ]]; then
print -Pn "\007"
fi
}
unset OVER_PROMPT_CFG