From 42d84a2e122909ec835ffbdbd508d8fee6899654 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Wed, 3 Nov 2021 07:44:15 +0000 Subject: [PATCH] zsh: prevent `tput` errors when $TERM is not set When running a command via SSH without allocating a pseudo terminal, for example, $TERM is not set, causing `tput` to freak out about not knowing the terminal type. So, we suppress the customization of man pages when $TERM is not set, in which case we wouldn't have needed it anyway, as we don't even have a terminal to type `man` :). --- zsh/zshenv | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/zsh/zshenv b/zsh/zshenv index e99691c..8cc4a23 100644 --- a/zsh/zshenv +++ b/zsh/zshenv @@ -20,17 +20,21 @@ export PAGER=less export PYTHONSTARTUP="$XDG_CONFIG_HOME/python/startup.py" export ZDOTDIR="$XDG_CONFIG_HOME/zsh" -# Make man pages pretty -rst="$(tput sgr0)" -export LESS_TERMCAP_md="$(printf '%s\n' 'setaf 3' | tput -S)" -export LESS_TERMCAP_mb="$LESS_TERMCAP_md" -export LESS_TERMCAP_me="$rst" -export LESS_TERMCAP_us="$(printf '%s\n' 'setaf 7' 'smul' | tput -S)" -export LESS_TERMCAP_ue="$rst" -export LESS_TERMCAP_so="$(printf '%s\n' 'setaf 4' 'setab 0' | tput -S)" -export LESS_TERMCAP_se="$rst" -export GROFF_NO_SGR=1 -unset rst +# Make man pages pretty, but only if $TERM is set because otherwise `tput` +# would report errors (e.g., when running a command via SSH without allocating +# a pty $TERM is not set). +[ -n "$TERM" ] && { + rst="$(tput sgr0)" + export LESS_TERMCAP_md="$(printf '%s\n' 'setaf 3' | tput -S)" + export LESS_TERMCAP_mb="$LESS_TERMCAP_md" + export LESS_TERMCAP_me="$rst" + export LESS_TERMCAP_us="$(printf '%s\n' 'setaf 7' 'smul' | tput -S)" + export LESS_TERMCAP_ue="$rst" + export LESS_TERMCAP_so="$(printf '%s\n' 'setaf 4' 'setab 0' | tput -S)" + export LESS_TERMCAP_se="$rst" + export GROFF_NO_SGR=1 + unset rst +} # Prevent path_helper from messing with the PATH when starting tmux. # See: https://superuser.com/a/583502