Skip to content

Commit

Permalink
[Fix #59] Do not increment SHLVL, for tmux will
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinHebert authored and sorin-ionescu committed Mar 21, 2012
1 parent c508d21 commit 17a4505
Showing 1 changed file with 0 additions and 2 deletions.
2 changes: 0 additions & 2 deletions plugins/tmux/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ alias tl="tmux list-sessions"

# Auto Start
if (( $SHLVL == 1 )) && zstyle -t ':omz:plugin:tmux:auto' start; then
(( SHLVL += 1 )) && export SHLVL

session="$(
tmux list-sessions 2> /dev/null \
| cut -d':' -f1 \
Expand Down

27 comments on commit 17a4505

@japz
Copy link

@japz japz commented on 17a4505 Mar 25, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHLVL doesn't get incremented by tmux for me, so this change causes the shell to crash on log-in. I think double increasing it won't hurt whilst not increasing it at all does, so in my opinion this change is best reverted.

@sorin-ionescu
Copy link
Owner

@sorin-ionescu sorin-ionescu commented on 17a4505 Mar 25, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ColinHebert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorin-ionescu, indeed, it should be the inside shell that increase SHLVL.

It works fine without #55 (Actually it works fine with a vanilla zsh and a vanilla tmux).

Could you show us your tmux settings, @japz ? (have you got a set-option default-command in your conf?)

@sorin-ionescu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea behind incrementing SHLVL was to stop the code from executing and lauching tmux again. I don't remember why I had to add that to the screen plugin, which was copied to the tmux plugin, but I remember having trouble without it.

@ColinHebert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, in screen for some reason SHLVL isn't incremented, but in tmux it is (as far as I know).

@sorin-ionescu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not working for me. It's always one. I get an infinite loop. I'm reverting this.

@ColinHebert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if it's not working it's better to revert this. But still I don't know why there would be different behaviours.

@sorin-ionescu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm fed up with tmux, iTerm, or both.

Interval Since Last Panic Report:  739334 sec
Panics Since Last Report:          1
Anonymous UUID:                    F2556F53-B2DE-4804-AC23-2ACD87FFBEAE

Mon Mar 26 09:13:58 2012
panic(cpu 0 caller 0x33c798): "Negative open count?"@/SourceCache/xnu/xnu-1699.24.23/bsd/miscfs/specfs/spec_vnops.c:1368
Backtrace (CPU 0), Frame : Return Address (4 potential args on stack)
0x1533ce8 : 0x22032e (0x6ad91c 0x1533d08 0x229f00 0x0) 
0x1533d18 : 0x33c798 (0x6c9804 0x2000 0x1533d48 0x33f00d) 
0x1533d48 : 0x340381 (0x1533da8 0x1533d70 0x1533d70 0x1533d70) 
0x1533d88 : 0x32b6dc (0x1533da8 0x0 0x1533da8 0x5455190) 
0x1533dc8 : 0x30b07c (0x5455158 0x30 0x638d74c 0x5455158) 
0x1533e18 : 0x30adaf (0x5455190 0x5455158 0x14 0x6bf0ab) 
0x1533e58 : 0x30c2e4 (0x0 0x1 0x1533e98 0x5455158) 
0x1533e78 : 0x31dfc2 (0x5455158 0x1 0x1533f00 0x0) 
0x1533e98 : 0x327379 (0x1533ea8 0x689a404 0x821580 0x5455158) 
0x1533ec8 : 0x563388 (0x5455158 0x1 0x1533f00 0x225e5a) 
0x1533f18 : 0x23c038 (0x68718c8 0x1 0x68718c8 0x7c64000) 
0x1533f38 : 0x23c52c (0x7c6429c 0x0 0x1 0x7c64000) 
0x1533f58 : 0x23c5d1 (0x7c642b8 0x7c64000 0x7c6429c 0x7c64000) 
0x1533f78 : 0x21d970 (0x1 0x5842994 0x638d690 0x0) 
0x1533fa8 : 0x2cd0f2 (0xffffffff 0x1 0x82ea98 0x1533fe0) 
0x1533fc8 : 0x2e3e04 (0x0 0x0 0x10 0x5842990) 

BSD process name corresponding to current thread: tmux

Mac OS version:
11D50b

Kernel Panic

@ColinHebert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that's really weird. I've been using tmux for days now (on two different machines) I never got that.

Is it the last tmux available on homebrew?

Related (not read it yet) : http://comments.gmane.org/gmane.comp.terminal-emulators.tmux.user/1852

@sorin-ionescu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever you have in your default-command probably increments your SHLVL.

There also a couple of issues open in the iTerm bug tracker.

@sorin-ionescu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, checking for SHLVL is not reliable. You can start BASH then Zsh, where SHLVL will be 2 and tmux will be skipped. It will be better to just check for the zstyle and a session.

@sorin-ionescu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm getting an infinite loop no matter what. It's not creating new sessions. It attaches to the same one over and over again.

Screenshot

@sorin-ionescu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, "$SHELL -l" or no "$SHELL -l", I'm getting the socket error.

launch_msg("SetUserEnvironment"): Socket is not connected
launch_msg("SetUserEnvironment"): Socket is not connected
launch_msg("SetUserEnvironment"): Socket is not connected
launch_msg("SetUserEnvironment"): Socket is not connected
launch_msg("SetUserEnvironment"): Socket is not connected
launch_msg("SetUserEnvironment"): Socket is not connected

I'm thinking of removing the plugin.

@ColinHebert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"launch_msg("SetUserEnvironment"): Socket is not connected" is due to tmux being used on Mac OS as is, I got that message too until I set reattach-to-user-namespace as the default shell (calling zsh).

Another way to fix that SHLVL problem would be trying to get the TMUX env variable which is set inside a tmux instance:

tmux also initialises the TMUX variable with some internal
information to allow commands to be executed from inside

This fixes both the SHLVL incrementing too much by reverting to the "default" behaviour and the tmux inside a zsh inside a zsh issue.

And actually that's how tmux works by default if you try to nest tmux:

~ $ tmux                                                                      ⏎
sessions should be nested with care. unset $TMUX to force.

@sorin-ionescu
Copy link
Owner

@sorin-ionescu sorin-ionescu commented on 17a4505 Mar 26, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorin-ionescu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will not be merging #55 and will be removing the tmux plugin. I cannot in good conscience promote it. Perhaps it works well on Linux, but I will not have something in OMZ that crashes systems, any system.

@ColinHebert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you got so many issues, I'm working on Mac OS and didn't get any issue so far. But I understand why you want to remove the plugin

@sorin-ionescu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tmux has always had issues on Mac OS X. I'm not sure if any of its main developers use Mac OS X. GNU Screen may be an unmaintained spaghetti, but at least it's stable. Though, I prefer to use my own attach.

@ColinHebert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason for me to use tmux was the features available when the "daemon mode" I pushed in another branch is also active. Anyway I'll keep a branch with this plugin available if someone wants to use it (as it works fine in my environments, I'll use it myself).

@sorin-ionescu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine. You can add a comment to #62.

@ColinHebert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if I understand why you would want to remove the tmux plugin, I don't really understand why the screen plugin should stay. (same reasons as tmux)

@sorin-ionescu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have never seen GNU Screen crash a system, ever. So, it's not the same.

@sorin-ionescu
Copy link
Owner

@sorin-ionescu sorin-ionescu commented on 17a4505 Mar 26, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@japz
Copy link

@japz japz commented on 17a4505 Mar 26, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow that's a lot of talk in one day. :)
FWIW: I was using tmux without any special configuration on a linux machine.

@ColinHebert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@japz, I'll have to install an environment myself to do more tests. But could you tell me if you have a result on a print $TMUX ? It should be set automatically. If it actually works, we should have a nice way to start tmux without having to rely on SHLVL

@japz
Copy link

@japz japz commented on 17a4505 Mar 26, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, $TMUX is set (on my linux machine and OSX machine)
: ~ ❯ echo $TMUX
/tmp/tmux-500/default,6764,0

so checking for that instead of SHLVL makes sense

@ColinHebert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, so it will be fixed by #55

Please sign in to comment.