Commit 1e9cbe7d authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Harden terminal setup and tput use in shell files

parent 66a12246
Loading
Loading
Loading
Loading
+1 −51
Original line number Diff line number Diff line
. ~/.shell/lib/term-setup.sh
. ~/.shell/funcs
. ~/.shell/colours

@@ -85,54 +86,3 @@ export CLICOLOR=yes

has gpg-agent &&
	export SSH_AUTH_SOCK=`gpgconf --list-dirs agent-ssh-socket`


## TERMINAL SETUP ##

# do no setup if TERM is not set or dumb
[ "${TERM-dumb}" = dumb ] && return

tput init

case "$TERM" in
linux)
	# Set default colours on linux VT
	tput -S <<-END
		initc $COLOUR_BLACK           000 000 000
		initc $COLOUR_RED             764 027 443
		initc $COLOUR_GREEN           062 654 470
		initc $COLOUR_YELLOW          658 611 078
		initc $COLOUR_BLUE            000 556 768
		initc $COLOUR_MAGENTA         321 235 474
		initc $COLOUR_CYAN            125 647 729
		initc $COLOUR_GRAY            850 850 850

		initc $COLOUR_DARK_GRAY       258 258 258
		initc $COLOUR_BRIGHT_RED      984 000 478
		initc $COLOUR_BRIGHT_GREEN    372 843 686
		initc $COLOUR_BRIGHT_YELLOW   952 894 188
		initc $COLOUR_BRIGHT_BLUE     125 733 988
		initc $COLOUR_BRIGHT_MAGENTA  407 333 870
		initc $COLOUR_BRIGHT_CYAN     309 721 800
		initc $COLOUR_WHITE           945 945 945

		setaf $COLOUR_WHITE
		setab $COLOUR_BLACK
	END
	printf '\e[8]'
	unicode_start
	;;
*)
	# Set title
	# (not suported by linux VT)
	hostname=`hostname -f 2>/dev/null || hostname`
	case $LC_TERMINAL in
		iTerm2) code=1 ;;
		*) code=2 ;;
	esac
	SET_TITLE=`printf '\e]%i;%s\007' $code "$hostname"`
	PROMPTCODES="$SET_TITLE"
	echo "$SET_TITLE"
	unset hostname code
	;;
esac
+4 −2
Original line number Diff line number Diff line
. ~/.shell/lib/term-setup.sh

SCRIPT_NAME=`basename -- $0`

BOLD=`tput bold`
UNBOLD=`tput sgr0`
BOLD=`tput bold || test $? -eq 1`
UNBOLD=`tput sgr0 || test $? -eq 1`

if [ -n "${ZSH_NAME:-}" ]; then
	CURRENT_SHELL=zsh
+58 −0
Original line number Diff line number Diff line
${TERM_SETUP_LOADED-false} && return
export TERM_SETUP_LOADED=true

# do no setup if TERM is not set or dumb
case ${TERM-unset} in
	unset) export TERM=dumb; return 0 ;;
	dumb) return 0 ;;
esac

tput init ||
case $? in
	# Unknown TERM value
	3) export TERM=dumb; return 0 ;;
	*) return 1 ;;
esac

case "$TERM" in
linux)
	# Set default colours on linux VT
	tput -S <<-END
		initc $COLOUR_BLACK           000 000 000
		initc $COLOUR_RED             764 027 443
		initc $COLOUR_GREEN           062 654 470
		initc $COLOUR_YELLOW          658 611 078
		initc $COLOUR_BLUE            000 556 768
		initc $COLOUR_MAGENTA         321 235 474
		initc $COLOUR_CYAN            125 647 729
		initc $COLOUR_GRAY            850 850 850

		initc $COLOUR_DARK_GRAY       258 258 258
		initc $COLOUR_BRIGHT_RED      984 000 478
		initc $COLOUR_BRIGHT_GREEN    372 843 686
		initc $COLOUR_BRIGHT_YELLOW   952 894 188
		initc $COLOUR_BRIGHT_BLUE     125 733 988
		initc $COLOUR_BRIGHT_MAGENTA  407 333 870
		initc $COLOUR_BRIGHT_CYAN     309 721 800
		initc $COLOUR_WHITE           945 945 945

		setaf $COLOUR_WHITE
		setab $COLOUR_BLACK
	END
	printf '\e[8]'
	unicode_start
	;;
*)
	# Set title
	# (not suported by linux VT)
	hostname=`hostname -f 2>/dev/null || hostname`
	case $LC_TERMINAL in
		iTerm2) code=1 ;;
		*) code=2 ;;
	esac
	SET_TITLE=`printf '\e]%i;%s\007' $code "$hostname"`
	PROMPTCODES="$SET_TITLE"
	echo "$SET_TITLE"
	unset hostname code
	;;
esac