How to move to next / previous session in tmux -CC (iterm2 + tmux integration) - tmux

There are lot of useful tmux shortcuts that I am unable to use in the iterm2+tmux integration that you can run using tmux -CC.
For instance, ctrl-B ) goes to the next session, ctrl-B ( goes to the previous session in vanilla tmux, but not in tmux -CC. Where can I find shortcuts for tmux -CC?
Thanks!

Related

Having an interactive menu when running a shell command

I have this line in my .tmux.conf file.
bind-key q run "fish --interactive -c q"
The code for function q is written in fish. This is the code.
function q
set session (t ls | fzf)
set chosen (string split ":" $session)
t switch -t $chosen[1]
end
What q does is simple. Pipe the output from the output for t ls, which is tmux ls, into fzf. Then split the string by : and then switch tmux sessions.
When I run q normally as a command in fish, it works fine. The fzf ui shows up and I can switch sessions.
But when I use the keybinding I set. It lets me change sessions but an interactive window does not appear. It just switches sessions without letting me choose.
What I want is to be able to have an interactive menu when I use prefix-q. So that I can choose which session I want to switch to.
When tmux invokes your bind-key shell command, it does so without any tmux pane active. That is, it runs the shell detached from any tty, because a tmux command might switch panes, or create a new pane, or destroy one; so it runs in a void.
The right idea is use tmux bindings to control tmux, and shell bindings to run commands in the current shell instance, which may in turn talk to tmux. Try this (as a shell command, not in tmux.conf):
bind \cTb q
This is a shell binding. Now 'control-T' followed by 'b' will run the menu in whatever pane is active.
The problem is the command capture alters the stdin/stdout/stderr file descriptors that fzf is handed. Try forcing it to interact with the tty:
set session (t ls | fzf 2>/dev/tty)

is there a tmux pre-command for when i run tmux kill session

Suppose i have a tmux session with a process running like a docker container / wsgi server etc..
Is there a way to define a "process kill command" that will run before the tmux session is killed?
I don't want any leftovers when the session has stopped.
You can use tmux hooks for this. Set the hook in your tmux.conf like this:
set-hook -g -n 'session-closed' 'run "<your command>"'
I am not sure you need it though. When tmux kill-session is run, all processes inside tmux will receive SIGHUP, so they should exit gracefully on their own.
If your process can be killed with Ctrl+c, a tmux plugin called tmux-safekill may do the trick.

How do you switch from a tmux pane that you've scrolled up in to another tmux pane?

If I have two tmux panes open and I go to one and scroll back to the history using CTRL-B [, then for some reason I can't switch to the other pane without making the current pane scroll back to the bottom. Does anyone know how to work around this? Note that I use some custom tmux configuration, as described here, to make it easier to navigate between vim windows and tmux panes. Is this somehow messing up how tmux scrolling works?
Is it possible you're running into a conflicting default keybinding for tmux when it's in copy mode?
When tmux is running, you can check the currently active keybindings by doing prefix+?. When I do this on a bare tmux config, I can see that C-k is bound to send-keys -X copy-end-of-line, and it will move a buffer that's in copy mode to the end of the buffer, like you're describing. Alternatively, if you're using tmux's copy-mode-vi, then it looks like C-j is bound by default to send-keys -X copy-selection-and-cancel.
Try adding the following to your .tmux.conf:
unbind-key -Tcopy-mode C-k
unbind-key -Tcopy-mode-vi C-j
After this configuration update, I'm able to use C-j and C-k to navigate panes like described in the article you linked.

Is there a way to automate the process of creating sessions and panes in tmux

I have huge list of programs to run in tmux session
is there any simple way so that we give session name and specify which pane runs which program.
Yes, you can either do this with tmux commands in a shell script, for example:
#!/bin/sh
S=$(tmux new -dP -smysession 'myprogram1')
W=$(tmux neww -dP -t$S 'myprogram2')
tmux -t$W splitw 'myprogram3'
Or a tmux script you can load with tmux source-file or from .tmux.conf:
new -smysession 'myprogram1'
neww 'myprogram2'
splitw 'myprogram3'
Or you could look at the many existing wrapper programs to do this. The most popular are:
https://github.com/tmuxinator/tmuxinator
https://github.com/tmux-python/tmuxp
https://github.com/remiprev/teamocil
There is a list at https://github.com/rothgar/awesome-tmux#tools-and-session-management.

tmux creates persistant, unkillable session

I wanted tmux to launch automatically, so I added [[ $TERM != "screen" ]] && exec tmux to my bash.bashrc file. However, now a session is created that I cannot kill and runs in "windowed" (for lack of a better word) mode.
If I run tmux kill-session -t ## another "windowed" session is created in its place. I can kill all other sessions fine, but this one stays constant.
I'm accessing the terminal through PuTTY, and there are only two users logged on (myself and the system itself)
How can I kill/prevent the creation of this session?

Resources