Reputation: 15329
I'm new to tmux and would like to configure it such that when I run tmux
, my customized windows/panes are immediately accessible.
For example, here's a basic ~/.tmux.conf:
new -s main -n workspace
neww
When I run tmux, I get dumped into a plain old session. When I do a list-sessions
, I can see the workspace session specified in the conf file, but in order to use it, I have to switch to it.
How can I just go ahead and make the "workspace" session the session I'm dumped into when I open tmux so that I don't have to switch to it every time?
Upvotes: 8
Views: 14078
Reputation: 5408
You can attach to the last used session (which will be the one your conf file created if applicable) by running tmux attach
instead of just tmux
.
If you have more than one session setup in your config, you can choose which one you land on by using the session name target flag like: tmux attach -t <session_name>
.
Upvotes: 1
Reputation:
Use my script. IniTmux. You can easyly describe you sessions, windows and panes with simple YAML files.
---
name: AK-Math
root: /i/project/LibAK/feature/Math
windows:
- Matrix : feature
- Vector : feature
- Number : feature
- Complex : feature
- Real : feature
- Integer : feature
- Bool : feature
- Math:
layout : tiled
dir : branch
panes :
- 'ranger'
- ''
models:
feature:
layout: "40fd,113x31,0,0[113x22,0,0{22x22,0,0,0,90x22,23,0,1},113x9,0,23,2]"
dir: <WName>
panes:
- loop "tree obj" 0.5
- vim -c VWSLoadWorkSpace
- ''
Upvotes: 0
Reputation: 21600
I've create this script. It does not need tmuxinator, ruby or others. It is just a bash script, configurable:
A file named config should contains something like this:
combo=()
combo+=('logs' 'cd /var/log; clear; pwd')
combo+=('home' 'cd ~; clear; pwd')
and the bash code should be:
#!/bin/bash
if [ -r config ]; then
echo ""
echo "Loading custom file"
. config
else
. config.dist
fi
tmux start-server
window=0
windownumber=-1
for i in "${combo[@]}"; do
if [ $((window%2)) == 0 ]; then
name=${i}
((windownumber++))
else
command=${i}
fi
if [ ${combo[0]} == "${i}" ]; then
tmux new-session -d -s StarTmux -n "${name}"
else
if [ $((window%2)) == 0 ]; then
tmux new-window -tStarTmux:$windownumber -n "${name}"
fi
fi
if [ $((window%2)) == 1 ]; then
tmux send-keys -tStarTmux:$windownumber "${command}" C-m
fi
((window++))
done
tmux select-window -tStarTmux:0
tmux attach-session -d -tStarTmux
Upvotes: 1
Reputation: 5166
Not sure I understood the question, but I use tmuxinator to quickly launch sessions pre-populated with windows, panes and processes.
Upvotes: 3
Reputation: 530853
You create a session in your .tmux.conf
file, but you never attach to it. When you just run
tmux
there is no command specified, so it defaults to running new-session
and attaching to the resulting session.
It's a little cleaner to limit your .tmux.conf
file to various settings, and reserve session creation and management to a separate script.
#!/bin/bash
tmux new -s main -n workspace
tmux neww # Creates a 2nd window, in addition to the new session's first window
tmux attach -t main
Upvotes: 0