plugins/xterm: lint

pull/1947/head
John D Pell 2021-09-14 14:32:01 -07:00
parent 11d7115962
commit 54200c372f
1 changed files with 16 additions and 8 deletions

View File

@ -3,29 +3,37 @@ cite about-plugin
about-plugin 'automatically set your xterm title with host and location info' about-plugin 'automatically set your xterm title with host and location info'
_short-dirname() { _short-dirname() {
local dir_name=$(dirs +0) local dir_name="${PWD/~/\~}"
[ "$SHORT_TERM_LINE" = true ] && [ "${#dir_name}" -gt 8 ] && echo "${dir_name##*/}" || echo "${dir_name}" if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then
echo "${dir_name##*/}"
else
echo "${dir_name}"
fi
} }
_short-command() { _short-command() {
local input_command="$*" local input_command="$*"
[ "$SHORT_TERM_LINE" = true ] && [ "${#input_command}" -gt 8 ] && echo "${input_command%% *}" || echo "${input_command}" if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then
echo "${input_command%% *}"
else
echo "${input_command}"
fi
} }
set_xterm_title() { set_xterm_title() {
local title="$1" local title="${1:-}"
echo -ne "\033]0;$title\007" echo -ne "\033]0;${title}\007"
} }
precmd_xterm_title() { precmd_xterm_title() {
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) $PROMPT_CHAR" set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}"
} }
preexec_xterm_title() { preexec_xterm_title() {
set_xterm_title "$(_short-command "${1}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" set_xterm_title "$(_short-command "${1:-}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
} }
case "$TERM" in case "${TERM:-dumb}" in
xterm* | rxvt*) xterm* | rxvt*)
precmd_functions+=(precmd_xterm_title) precmd_functions+=(precmd_xterm_title)
preexec_functions+=(preexec_xterm_title) preexec_functions+=(preexec_xterm_title)