Tmux New Session
Entrée
I keep forgetting how to create a new tmux session.
Is it this one?
$ tmux new
sessions should be nested with care, unset $TMUX to force
No.
Is it this one?
$ tmux new-session
sessions should be nested with care, unset $TMUX to force
No.
$ tmux new-session -d
# from tmux cli, prefix/ctrl+b
# :new -d
No error? Good. Check session with prefix + s (ctrl + b + s
). Ok it seems this works.
However this gives a strange session name like 29. What is it? I though the ultimate answer to the universe was 42.
Solution
Here is the complete command to create a new tmux session:
$ tmux new-session -d -s "new" -c ~/path/to/some/dir -n "main"
This command will create a session named new, with a window named main in
~/path/to/some/dir
as working directory.
It would probably better to run it from function with some args for more customization;
# .zshrc/.bashrc
# Crate and attach a new session with args
# defaults: session named "new" in ${HOME} as working dir with window named "main"
#
# Usage:
# $ tnew
# $ tnew remote ~/path/to/dir
# $ tnew remote ~/path/to/dir scripts
tnew() {
local session_name="${1:-new}"
local session_dir=${2:-~/}
local session_window_name="${3:-main}"
tmux new-session \
-d \
-s ${session_name} \
-c ${session_dir} \
-n ${session_window_name}
}
As described in function’s doc you can use this function as below:
$ tnew
$ tnew remote ~/path/to/dir
$ tnew remote ~/path/to/dir scripts
Now I can peacefully forget (again) creating new tmux session, all I need to remember: tnew.
All done!
Subscribe
Read Related