Create new window and set name - tmux

Currently I'll often do prefix-cprefix-, to open a new window then rename it. I would like to make prefix-c automatically ask for a name for the new window.
Basically I want it to behave as if I'd entered prefix-:new-window -n.How do I map prefix-c to that command?
I've tried adding bind-key c 'new-window -n' to my ~/.tmux.conf but that doesn't work.

You'll need a prompt to ask for the new window name:
bind-key c command-prompt -p "window name:" "new-window; rename-window '%%'"

Related

Start tmux with specific layout

I have a question and searched on the web but didn't find a specific solution, or solutions didn't work for me.
In order to start tmux with a specific layout of panes, I'd like to setup my tmux.conf accordingly.
Now, I found something like this:
new -s my_sess # create new session
neww -n shell # create new window
splitw -v
Which has no effect, since I see only one window, not split into panes. Another trial was like this:
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
# Split the pane horizontally
splitw -h
Which results in an error no current target.
It's probably a stupid mistake of mine caused by poor understanding. But I hope that people here might be able to help.
I'd say that this very basic task is covered abominably in the available tmux resources.
It cost me six hours of perusing material to come to a solution. The biggest help came from https://gist.github.com/sdondley/b01cc5bb1169c8c83401e438a652b84e
Your minimal .tmux.conf file shall be (you got there 99%):
new -s my_sess # create new session
neww -n shell # create new window
split-window -t shell # split vertically the window just created
and you have to launch it with tmux attach instead of a plain tmux.
I have created a gist to sum up my experiences. It covers also topics like launching different commands in each new pane.
If you create new sessions in .tmux.conf, you probably want to start tmux with tmux attach not tmux new. If you don't, you will be creating both your session in .tmux.conf and a new session, which is probably not what you want. Your first attempt looks OK, so I guess this is what you are doing.
Also remember .tmux.conf is only loaded on server startup, so only the first time you run tmux. If you want to create a new session like this later, put it in a separate config file and load it with source-file.

tmux: allow-rename, but ALSO override?

I'd like to be able to issue a command like this:
tmux new-window -n irc ssh -t eco /usr/bin/weechat
and have the title of the new window be "irc". Instead, as soon as weechat launches, the title changes to weechat.
I had been under the impression based on the tmux man page that if you set a window title explicitly, automatic-rename would be disabled for you:
automatic-rename
[...] This flag is automatically disabled for an individual window when a
name is specified at creation with new-window or new-session, or later
with rename-window, or with a terminal escape sequence.
But that seems to not be the case. What am I missing here? I do want automatic-rename in most cases - I just want to also be able to specify -n windowname and have it take precedence.

Prevent tmux from displaying/replacing user-namespace from window's name

I would like to give fix name different tmux pane title but whenever I move to a different directory tmux just replace pane name that I have define with something like: 0:username#namespace:~/directory which confusing. Any help?
I found the answer here
The tmux command for this is:
set-option -g allow-rename off

How do I make vim-style key bindings work on tmux using set-window-option?

I am aware that I can manually bind individual keys in my .tmux.conf file, but according to this page I should be able to get vim-like key bindings in tmux simply by adding the following to my .tmux.conf, saving me having to maintain a list of keybindings:
set-window-option -g mode-keys vi
But this doesn't really seem to work as expected. Sure enough, when I press Ctrl+b [ I am able to navigate through my terminal history using vim keys hjkl, but when I press Ctrl+b k it doesn't take me to the above window, for that I still have to press Ctrl+b Up, same goes for down, left and right.
Why doesn't this work? Do I really have to map these keys manually on top of vi mode to get actual vi mode?
I'm using tmux 1.6
add this to your cnofig:
#switch panels
bind k selectp -U # switch to panel Up
bind j selectp -D # switch to panel Down
bind h selectp -L # switch to panel Left
bind l selectp -R # switch to panel Right

Show pane in all windows in tmux

I wonder if I can configure a pane in tmux to appear in all windows.
Any hints how to do that?
Of course this is possible, but you would need to run tmux inside a tmux pane.
+-------------+-------------+
| tmux pane 1 | tmux pane 2 |
| | |
| |+-----------+|
| || new tmux ||
| || session ||
| |+-----------+|
+-------------+-------------+
How to do it:
start new tmux session
split pane
unset TMUX in pane 2 # this allows tmux in tmux
start new tmux session in pane
repeat 1-3
run tmux attach -t <target-session> # this is opens the shared session
This does not work as easily if you are running wrappers for tmux, such as come with oh-my-zsh or tmuxinator. And there are probably many reasons you shouldn't do it, I just don't know any of them.
Here's a way to do this, but the mirrored panes will be read-only. There's the pipe-pane command which sends the pane's output to a command. You can have that command write the output to a file and then from the panes you want to mirror from, you can tail -f that file. Example:
# In source pane
tmux pipe-pane 'cat > /tmp/asdf'
# In the target pane (or another tmux session or terminal window)
tail -f /tmp/asdf
no you can't configure a pane to be linked to every window in a traditional sense but you can use tmux's link-window functionality to achieve much of this effect. wrap it in a script or tmux session file to link it to many windows at once.
**edit
you will also want to use the join-pane feature.

Resources