Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a trigger before enabling SHLVL (LP_ENABLE_SHLVL) #821

Closed
mathieumd opened this issue Feb 15, 2024 · 5 comments
Closed

Allow a trigger before enabling SHLVL (LP_ENABLE_SHLVL) #821

mathieumd opened this issue Feb 15, 2024 · 5 comments
Labels
enhancement Feature request
Milestone

Comments

@mathieumd
Copy link
Contributor

Description

I discovered LP_ENABLE_SHLVL today, nice!

But, as I'm always running my shells under Tmux, the bold green mark is always present ("└2"), which distract me. And, more importantly, I would not notice when I'm actually running a subshell ("└3")!

Would it be possible to display the mark only when $SHLVL is greater than 2, by example?

How will this be useful?

Warn about sub shells only when the user needs it.

@mathieumd mathieumd added the enhancement Feature request label Feb 15, 2024
@Rycieos
Copy link
Collaborator

Rycieos commented Feb 15, 2024

I suppose a LP_SHLVL_THRESHOLD value would make sense. I think that's a valid request.

As a work around, you could add something to your bash/zshrc that decrements $SHLVL by one when it detects its parent is Tmux.

@mathieumd
Copy link
Contributor Author

As a work around, you could add something to your bash/zshrc that decrements $SHLVL by one when it detects its parent is Tmux.

Tried this in .bashrc, but then $SHLVL is always equal to 1, regardless of number of sub shells!

if [ "x$TMUX" != "x" ]; then
  SHLVL="$(( SHLVL - 1 ))"
fi
14:39:16 [mathieu:~] $ bash
14:39:18 [mathieu:~] $ echo $SHLVL
1
14:39:22 [mathieu:~] $ bash
14:39:24 [mathieu:~] $ echo $SHLVL
1
14:39:30 [mathieu:~] $ bash
14:39:32 [mathieu:~] $ echo $SHLVL
1
14:39:34 [mathieu:~] $
exit
14:39:37 [mathieu:~] 5s $
exit
14:39:38 [mathieu:~] 14s $
exit
14:39:39 [mathieu:~] 21s $

While without the decrement code, it works well:

14:40:49 [mathieu:~]└2 $ bash
14:40:52 [mathieu:~]└3 $ bash
14:40:53 [mathieu:~]└4 $ bash
14:40:54 [mathieu:~]└5 $
exit
14:40:54 [mathieu:~]└4 $
exit
14:40:55 [mathieu:~]└3 2s $
exit
14:40:56 [mathieu:~]└2 5s $

@Rycieos
Copy link
Collaborator

Rycieos commented Feb 16, 2024

Tried this in .bashrc, but then $SHLVL is always equal to 1, regardless of number of sub shells!

Weird, it works perfectly for me if I add this to my .bashrc:

if [[ -n ${TMUX-} ]]; then
  SHLVL=$(( SHLVL - 1 ))
fi

Of course, if you then run bash or another shell inside that Tmux again, since $TMUX is still set, the level will still not increment. And if you ever source .bashrc it will decrement the level again. The best way I can think to fix that is to run tmux as your login shell, or to invoke Tmux with SHLVL set to 0:

SHLVL=0 tmux

@mathieumd
Copy link
Contributor Author

Thanks for your suggestions @Rycieos, but I can't make them to work on my system (Yep, I'm running Bash inside Tmux, good catch!).

Anyway, it's not blocking, and I can wait, and hope LP_SHLVL_THRESHOLD will be implemented one day! ;)

@Rycieos Rycieos added this to the v2.2 milestone May 22, 2024
@Rycieos
Copy link
Collaborator

Rycieos commented May 22, 2024

LP_SHLVL_THRESHOLD was released as part of v2.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request
Projects
None yet
Development

No branches or pull requests

2 participants