From 8b4f5774b59398b964e9dce0866068f14744d631 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 30 Nov 2016 10:48:14 +1300 Subject: Handle tmux sessions showing SHLVL properly --- bash/bashrc | 7 +++++++ bash/bashrc.d/prompt.bash | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'bash') diff --git a/bash/bashrc b/bash/bashrc index 088182ef..57d4bcf6 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -81,6 +81,13 @@ if ((BASH_VERSINFO[0] >= 4)) ; then ((BASH_VERSINFO[1] >= 3)) && shopt -s direxpand fi +# Set a SHLVL-derived value that takes tmux into account. This is used to show +# the current SHLVL in the prompt +if [[ -n $TMUX && -z $TMUX_SHLVL ]] ; then + TMUX_SHLVL=$((SHLVL - 1)) + export TMUX_SHLVL +fi + # Load Bash-specific startup files for sh in "$HOME"/.bashrc.d/*.bash ; do [[ -e $sh ]] && source "$sh" diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index 84cdf584..7058f4c3 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -32,9 +32,9 @@ prompt() { PS1=$PS1'\$' # Add > signs at the front of the prompt to show the current shell - # level - local i - for ((i = 1; i < SHLVL; i++)) ; do + # level, taking tmux sessions into account + local shlvl + for ((shlvl = SHLVL - TMUX_SHLVL; shlvl > 1; shlvl--)) ; do PS1='>'$PS1 done -- cgit v1.2.3