From 0a48ef9fc7c78322baef0f04f07cdc5494d88ea4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 19 Dec 2016 10:18:13 +1300 Subject: Attempt a much saner approach to managing SHLVL --- X/xinitrc.d/shlvl.sh | 2 ++ bash/bashrc.d/prompt.bash | 5 ++--- ksh/kshrc.d/prompt.ksh | 11 ++++------- sh/shrc.d/tmux.sh | 9 --------- tmux/tmux.conf.m4 | 3 +++ zsh/zshrc.d/prompt.zsh | 5 ++--- 6 files changed, 13 insertions(+), 22 deletions(-) create mode 100644 X/xinitrc.d/shlvl.sh diff --git a/X/xinitrc.d/shlvl.sh b/X/xinitrc.d/shlvl.sh new file mode 100644 index 00000000..0e3bad04 --- /dev/null +++ b/X/xinitrc.d/shlvl.sh @@ -0,0 +1,2 @@ +# Reset SHLVL +unset SHLVL diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index 7058f4c3..ed09afdd 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -31,10 +31,9 @@ prompt() { # Add terminating "$" or "#" sign PS1=$PS1'\$' - # Add > signs at the front of the prompt to show the current shell - # level, taking tmux sessions into account + # Add > symbols to show nested shells local shlvl - for ((shlvl = SHLVL - TMUX_SHLVL; shlvl > 1; shlvl--)) ; do + for ((shlvl = 1; shlvl < SHLVL; shlvl++)) ; do PS1='>'$PS1 done diff --git a/ksh/kshrc.d/prompt.ksh b/ksh/kshrc.d/prompt.ksh index 32bb8192..719b119f 100644 --- a/ksh/kshrc.d/prompt.ksh +++ b/ksh/kshrc.d/prompt.ksh @@ -35,15 +35,12 @@ function prompt { # Add terminating "$" or "#" sign PS1=$PS1'\$' - # Add > signs at the front of the prompt to show the current shell - # level, taking tmux sessions into account, assuming this version - # of ksh does SHLVL; I think only ksh93t+ does it from what I can - # tell + # Add > symbols to show nested shells typeset shlvl - ((shlvl = SHLVL - TMUX_SHLVL)) - while ((shlvl > 1)); do + shlvl=1 + while ((shlvl < SHLVL)); do PS1='>'$PS1 - ((shlvl--)) + ((shlvl++)) done # Declare variables to contain terminal control strings diff --git a/sh/shrc.d/tmux.sh b/sh/shrc.d/tmux.sh index 32780c9d..bd954be8 100644 --- a/sh/shrc.d/tmux.sh +++ b/sh/shrc.d/tmux.sh @@ -17,12 +17,3 @@ tmux() { # Execute with concluded arguments command tmux "$@" } - -# If we have a SHLVL set from one of the shells that does that (bash, ksh93, -# zsh), then set a SHLVL-derived value that takes tmux into account if we -# haven't already. This can be used to show the current SHLVL in the prompt for -# more advanced shells. -if [ -n "$SHLVL" ] && [ -n "$TMUX" ] && [ -z "$TMUX_SHLVL" ] ; then - TMUX_SHLVL=$((SHLVL - 1)) - export TMUX_SHLVL -fi diff --git a/tmux/tmux.conf.m4 b/tmux/tmux.conf.m4 index a4af9f8e..f9f62456 100644 --- a/tmux/tmux.conf.m4 +++ b/tmux/tmux.conf.m4 @@ -8,6 +8,9 @@ set-environment -gru SSH_CONNECTION set-environment -gru SSH_TTY set-environment -gru WINDOWID +# Reset SHLVL +set-environment -gru SHLVL + # Otherwise, use the environment we had when we started; don't touch it during # a session unless I specifically ask set-option -g update-environment '' diff --git a/zsh/zshrc.d/prompt.zsh b/zsh/zshrc.d/prompt.zsh index 4b98c125..5dc00fd3 100644 --- a/zsh/zshrc.d/prompt.zsh +++ b/zsh/zshrc.d/prompt.zsh @@ -32,10 +32,9 @@ prompt() { # Add terminating "$" or "#" sign PS1=$PS1'%#' - # Add > signs at the front of the prompt to show the current shell - # level, taking tmux sessions into account + # Add > symbols to show nested shells local shlvl - for ((shlvl = SHLVL - TMUX_SHLVL; shlvl > 1; shlvl--)) ; do + for ((shlvl = 1; shlvl < SHLVL; shlvl++)) ; do PS1='>'$PS1 done -- cgit v1.2.3