How do I create a simple tmux conf that splits a window?
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I'd like to create a simple tmux conf that does the follow.
- Splits the window/pane/whatever_stupid_terminology horizontally (hsplit)
- Opens in the top pane
tail -f foo
- Opens in the bottom pane
tail -f bar
How can I do this with tmux.
This is what I've got,
#!/bin/sh
tmux new-session -s asdf -n myWindow
tmux select-window -t myWindow
tmux split-window "tail -f /var/log/apache2/samperror.log"
tmux attach-session -t asdf
I can't get anything thought to work. So I know it's all wrong. One of the most unintuitive conf files ever
tmux
add a comment |Â
up vote
4
down vote
favorite
I'd like to create a simple tmux conf that does the follow.
- Splits the window/pane/whatever_stupid_terminology horizontally (hsplit)
- Opens in the top pane
tail -f foo
- Opens in the bottom pane
tail -f bar
How can I do this with tmux.
This is what I've got,
#!/bin/sh
tmux new-session -s asdf -n myWindow
tmux select-window -t myWindow
tmux split-window "tail -f /var/log/apache2/samperror.log"
tmux attach-session -t asdf
I can't get anything thought to work. So I know it's all wrong. One of the most unintuitive conf files ever
tmux
Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
â jasonwryan
Aug 11 '14 at 20:39
@jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
â Evan Carroll
Aug 11 '14 at 20:48
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I'd like to create a simple tmux conf that does the follow.
- Splits the window/pane/whatever_stupid_terminology horizontally (hsplit)
- Opens in the top pane
tail -f foo
- Opens in the bottom pane
tail -f bar
How can I do this with tmux.
This is what I've got,
#!/bin/sh
tmux new-session -s asdf -n myWindow
tmux select-window -t myWindow
tmux split-window "tail -f /var/log/apache2/samperror.log"
tmux attach-session -t asdf
I can't get anything thought to work. So I know it's all wrong. One of the most unintuitive conf files ever
tmux
I'd like to create a simple tmux conf that does the follow.
- Splits the window/pane/whatever_stupid_terminology horizontally (hsplit)
- Opens in the top pane
tail -f foo
- Opens in the bottom pane
tail -f bar
How can I do this with tmux.
This is what I've got,
#!/bin/sh
tmux new-session -s asdf -n myWindow
tmux select-window -t myWindow
tmux split-window "tail -f /var/log/apache2/samperror.log"
tmux attach-session -t asdf
I can't get anything thought to work. So I know it's all wrong. One of the most unintuitive conf files ever
tmux
tmux
asked Aug 11 '14 at 6:10
Evan Carroll
4,69493775
4,69493775
Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
â jasonwryan
Aug 11 '14 at 20:39
@jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
â Evan Carroll
Aug 11 '14 at 20:48
add a comment |Â
Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
â jasonwryan
Aug 11 '14 at 20:39
@jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
â Evan Carroll
Aug 11 '14 at 20:48
Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
â jasonwryan
Aug 11 '14 at 20:39
Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
â jasonwryan
Aug 11 '14 at 20:39
@jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
â Evan Carroll
Aug 11 '14 at 20:48
@jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
â Evan Carroll
Aug 11 '14 at 20:48
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
6
down vote
Here's a quick and dirty command-line that achieves what you want:
$ tmux new-session -s asdf -n myWindow -d 'tail -f foo';
split-window -d 'tail -f bar'; attach-session
There are a few drawbacks to this solution:
it doesn't scale very well (a few more commands and the result is incomprehensible).
the two tail commands aren't run in an interactive shell, so if you exit them both, the window
myWindow
will be destroyed (together with the session if you haven't created any more sessions.
Here's a shell script that works along the lines that you tried. For me it's always easiest to think about how I would achieve my goal manually and then translate that into tmux commands. This might not be the simplest or cleanest way, but it usually works:
#!/bin/sh
# create a new session. Note the -d flag, we do not want to attach just yet!
tmux new-session -s asdf -n 'myWindow' -d
# send 'tail -f foo<enter>' to the first pane.
# I address the first pane using the -t flag. This is not necessary,
# I'm doing it so explicitly to show you how to do it.
# for the <enter> key, we can use either C-m (linefeed) or C-j (newline)
tmux send-keys -t asdf:myWindow.0 'tail -f foo' C-j
# split the window *vertically*
tmux split-window -v
# we now have two panes in myWindow: pane 0 is above pane 1
# again, specifying pane 1 with '-t 1' is optional
tmux send-keys -t 1 'tail -f bar' C-j
# uncomment the following command if you want to attach
# explicitly to the window we just created
#tmux select-window -t asdf:mywindow
# finally attach to the session
tmux attach -t asdf
If after some trying you still don't like the tmux
command and configuration syntax, you might want to look into tmuxinator, a Ruby gem that lets you manage tmux sessions with a simplified and more transparent syntax.
In my answer to Multiple terminals at once without an X server you can find a few links to helpful tmux
resources
add a comment |Â
up vote
1
down vote
Based on the answer here is more generic code:
tmuxMany()
#https://unix.stackexchange.com/a/149729/47116
if [ $# -lt 2 ]; then
echo usage: sessionName command1 command2 ...
return 1
fi
local sessionName=$1
local firstCommand=$2
local secondAndRestCommands=( "$@:3" )
tmux new-session -s $sessionName -n 'myWindow' -d
tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
local i
for i in "$!secondAndRestCommands[@]"
do
echo $i
local command=$secondAndRestCommands[$i]
echo $command
tmux split-window -v
local tabNumber=$((i+1))
tmux send-keys -t $tabNumber "$command" C-j
done
tmux select-layout even-vertical
tmux attach -t $sessionName
Usage:
tmuxMany sessionName "tail -f file" "tail -f file2" htop
Will open tmux with 3 panes of equal height.
add a comment |Â
up vote
0
down vote
Assuming you do want to run this from your ~/.tmux.conf
, not an external script, you would append this to your config file:
# session initialisation
new -s SessionName -n WindowName 'tail -f /var/log/apache2/samperror.log'
splitw -h -p 50 -t 0 'tail -f /var/log/apache2/other.log'
selectw -t 0
Then, when you start tmux with the command to attach to a session, tmux a
, it will create SessionName with the window split horizontally (-h
) in half (-p 50
) running those two commands.
is there anyway to make the session automagically attach so I can just runtmux -f tmux.conf
, and if the session already exists it attaches it -- otherwise it initializes and attaches?
â Evan Carroll
Aug 13 '14 at 1:11
@EvanCarroll That is what thea
(a contraction ofattach
) is for. You can always write a function, like so:tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
â jasonwryan
Aug 13 '14 at 1:19
So there is no way to do it from within the .conf file?
â Evan Carroll
Aug 13 '14 at 1:32
1
@EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
â jasonwryan
Aug 13 '14 at 1:39
add a comment |Â
up vote
0
down vote
This is how I launch an editor + REPL now:
mux $(basename $(pwd))
"vim $(find src test resources test-resources -type f 2>/dev/null
| tr "n" " ")"
"lein repl"
I hacked on Maxim's code to get a different layout:
#!/bin/bash
#https://unix.stackexchange.com/a/149729/47116
if [ $# -lt 2 ]; then
echo usage: sessionName command1 command2 ...
return 1
fi
sessionName=$1
firstCommand=$2
secondAndRestCommands=( "$@:3" )
tmux new-session -s $sessionName -n 'myWindow' -d
WIN="$sessionName:myWindow"
tmux send-keys -t $WIN.1 "$firstCommand" C-j
for i in "$!secondAndRestCommands[@]"
do
command=$secondAndRestCommands[$i]
echo $i: $command
tmux split-window -v
tabNumber=$((i+2))
tmux send-keys -t $tabNumber "$command" C-j
done
tmux select-pane -t $WIN.1
fixlayout()
tmux set-window-option -t $WIN main-pane-width $(($COLUMNS - 80))
tmux select-layout -t $WIN main-vertical
fixlayout
sleep 1 && fixlayout &
tmux attach -t $sessionName
Incidentally this guy's tmux.conf seems pretty useful.
New contributor
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
Here's a quick and dirty command-line that achieves what you want:
$ tmux new-session -s asdf -n myWindow -d 'tail -f foo';
split-window -d 'tail -f bar'; attach-session
There are a few drawbacks to this solution:
it doesn't scale very well (a few more commands and the result is incomprehensible).
the two tail commands aren't run in an interactive shell, so if you exit them both, the window
myWindow
will be destroyed (together with the session if you haven't created any more sessions.
Here's a shell script that works along the lines that you tried. For me it's always easiest to think about how I would achieve my goal manually and then translate that into tmux commands. This might not be the simplest or cleanest way, but it usually works:
#!/bin/sh
# create a new session. Note the -d flag, we do not want to attach just yet!
tmux new-session -s asdf -n 'myWindow' -d
# send 'tail -f foo<enter>' to the first pane.
# I address the first pane using the -t flag. This is not necessary,
# I'm doing it so explicitly to show you how to do it.
# for the <enter> key, we can use either C-m (linefeed) or C-j (newline)
tmux send-keys -t asdf:myWindow.0 'tail -f foo' C-j
# split the window *vertically*
tmux split-window -v
# we now have two panes in myWindow: pane 0 is above pane 1
# again, specifying pane 1 with '-t 1' is optional
tmux send-keys -t 1 'tail -f bar' C-j
# uncomment the following command if you want to attach
# explicitly to the window we just created
#tmux select-window -t asdf:mywindow
# finally attach to the session
tmux attach -t asdf
If after some trying you still don't like the tmux
command and configuration syntax, you might want to look into tmuxinator, a Ruby gem that lets you manage tmux sessions with a simplified and more transparent syntax.
In my answer to Multiple terminals at once without an X server you can find a few links to helpful tmux
resources
add a comment |Â
up vote
6
down vote
Here's a quick and dirty command-line that achieves what you want:
$ tmux new-session -s asdf -n myWindow -d 'tail -f foo';
split-window -d 'tail -f bar'; attach-session
There are a few drawbacks to this solution:
it doesn't scale very well (a few more commands and the result is incomprehensible).
the two tail commands aren't run in an interactive shell, so if you exit them both, the window
myWindow
will be destroyed (together with the session if you haven't created any more sessions.
Here's a shell script that works along the lines that you tried. For me it's always easiest to think about how I would achieve my goal manually and then translate that into tmux commands. This might not be the simplest or cleanest way, but it usually works:
#!/bin/sh
# create a new session. Note the -d flag, we do not want to attach just yet!
tmux new-session -s asdf -n 'myWindow' -d
# send 'tail -f foo<enter>' to the first pane.
# I address the first pane using the -t flag. This is not necessary,
# I'm doing it so explicitly to show you how to do it.
# for the <enter> key, we can use either C-m (linefeed) or C-j (newline)
tmux send-keys -t asdf:myWindow.0 'tail -f foo' C-j
# split the window *vertically*
tmux split-window -v
# we now have two panes in myWindow: pane 0 is above pane 1
# again, specifying pane 1 with '-t 1' is optional
tmux send-keys -t 1 'tail -f bar' C-j
# uncomment the following command if you want to attach
# explicitly to the window we just created
#tmux select-window -t asdf:mywindow
# finally attach to the session
tmux attach -t asdf
If after some trying you still don't like the tmux
command and configuration syntax, you might want to look into tmuxinator, a Ruby gem that lets you manage tmux sessions with a simplified and more transparent syntax.
In my answer to Multiple terminals at once without an X server you can find a few links to helpful tmux
resources
add a comment |Â
up vote
6
down vote
up vote
6
down vote
Here's a quick and dirty command-line that achieves what you want:
$ tmux new-session -s asdf -n myWindow -d 'tail -f foo';
split-window -d 'tail -f bar'; attach-session
There are a few drawbacks to this solution:
it doesn't scale very well (a few more commands and the result is incomprehensible).
the two tail commands aren't run in an interactive shell, so if you exit them both, the window
myWindow
will be destroyed (together with the session if you haven't created any more sessions.
Here's a shell script that works along the lines that you tried. For me it's always easiest to think about how I would achieve my goal manually and then translate that into tmux commands. This might not be the simplest or cleanest way, but it usually works:
#!/bin/sh
# create a new session. Note the -d flag, we do not want to attach just yet!
tmux new-session -s asdf -n 'myWindow' -d
# send 'tail -f foo<enter>' to the first pane.
# I address the first pane using the -t flag. This is not necessary,
# I'm doing it so explicitly to show you how to do it.
# for the <enter> key, we can use either C-m (linefeed) or C-j (newline)
tmux send-keys -t asdf:myWindow.0 'tail -f foo' C-j
# split the window *vertically*
tmux split-window -v
# we now have two panes in myWindow: pane 0 is above pane 1
# again, specifying pane 1 with '-t 1' is optional
tmux send-keys -t 1 'tail -f bar' C-j
# uncomment the following command if you want to attach
# explicitly to the window we just created
#tmux select-window -t asdf:mywindow
# finally attach to the session
tmux attach -t asdf
If after some trying you still don't like the tmux
command and configuration syntax, you might want to look into tmuxinator, a Ruby gem that lets you manage tmux sessions with a simplified and more transparent syntax.
In my answer to Multiple terminals at once without an X server you can find a few links to helpful tmux
resources
Here's a quick and dirty command-line that achieves what you want:
$ tmux new-session -s asdf -n myWindow -d 'tail -f foo';
split-window -d 'tail -f bar'; attach-session
There are a few drawbacks to this solution:
it doesn't scale very well (a few more commands and the result is incomprehensible).
the two tail commands aren't run in an interactive shell, so if you exit them both, the window
myWindow
will be destroyed (together with the session if you haven't created any more sessions.
Here's a shell script that works along the lines that you tried. For me it's always easiest to think about how I would achieve my goal manually and then translate that into tmux commands. This might not be the simplest or cleanest way, but it usually works:
#!/bin/sh
# create a new session. Note the -d flag, we do not want to attach just yet!
tmux new-session -s asdf -n 'myWindow' -d
# send 'tail -f foo<enter>' to the first pane.
# I address the first pane using the -t flag. This is not necessary,
# I'm doing it so explicitly to show you how to do it.
# for the <enter> key, we can use either C-m (linefeed) or C-j (newline)
tmux send-keys -t asdf:myWindow.0 'tail -f foo' C-j
# split the window *vertically*
tmux split-window -v
# we now have two panes in myWindow: pane 0 is above pane 1
# again, specifying pane 1 with '-t 1' is optional
tmux send-keys -t 1 'tail -f bar' C-j
# uncomment the following command if you want to attach
# explicitly to the window we just created
#tmux select-window -t asdf:mywindow
# finally attach to the session
tmux attach -t asdf
If after some trying you still don't like the tmux
command and configuration syntax, you might want to look into tmuxinator, a Ruby gem that lets you manage tmux sessions with a simplified and more transparent syntax.
In my answer to Multiple terminals at once without an X server you can find a few links to helpful tmux
resources
edited Mar 2 at 23:20
Jeff Schaller
33.6k851113
33.6k851113
answered Aug 11 '14 at 17:13
user80519
613
613
add a comment |Â
add a comment |Â
up vote
1
down vote
Based on the answer here is more generic code:
tmuxMany()
#https://unix.stackexchange.com/a/149729/47116
if [ $# -lt 2 ]; then
echo usage: sessionName command1 command2 ...
return 1
fi
local sessionName=$1
local firstCommand=$2
local secondAndRestCommands=( "$@:3" )
tmux new-session -s $sessionName -n 'myWindow' -d
tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
local i
for i in "$!secondAndRestCommands[@]"
do
echo $i
local command=$secondAndRestCommands[$i]
echo $command
tmux split-window -v
local tabNumber=$((i+1))
tmux send-keys -t $tabNumber "$command" C-j
done
tmux select-layout even-vertical
tmux attach -t $sessionName
Usage:
tmuxMany sessionName "tail -f file" "tail -f file2" htop
Will open tmux with 3 panes of equal height.
add a comment |Â
up vote
1
down vote
Based on the answer here is more generic code:
tmuxMany()
#https://unix.stackexchange.com/a/149729/47116
if [ $# -lt 2 ]; then
echo usage: sessionName command1 command2 ...
return 1
fi
local sessionName=$1
local firstCommand=$2
local secondAndRestCommands=( "$@:3" )
tmux new-session -s $sessionName -n 'myWindow' -d
tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
local i
for i in "$!secondAndRestCommands[@]"
do
echo $i
local command=$secondAndRestCommands[$i]
echo $command
tmux split-window -v
local tabNumber=$((i+1))
tmux send-keys -t $tabNumber "$command" C-j
done
tmux select-layout even-vertical
tmux attach -t $sessionName
Usage:
tmuxMany sessionName "tail -f file" "tail -f file2" htop
Will open tmux with 3 panes of equal height.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Based on the answer here is more generic code:
tmuxMany()
#https://unix.stackexchange.com/a/149729/47116
if [ $# -lt 2 ]; then
echo usage: sessionName command1 command2 ...
return 1
fi
local sessionName=$1
local firstCommand=$2
local secondAndRestCommands=( "$@:3" )
tmux new-session -s $sessionName -n 'myWindow' -d
tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
local i
for i in "$!secondAndRestCommands[@]"
do
echo $i
local command=$secondAndRestCommands[$i]
echo $command
tmux split-window -v
local tabNumber=$((i+1))
tmux send-keys -t $tabNumber "$command" C-j
done
tmux select-layout even-vertical
tmux attach -t $sessionName
Usage:
tmuxMany sessionName "tail -f file" "tail -f file2" htop
Will open tmux with 3 panes of equal height.
Based on the answer here is more generic code:
tmuxMany()
#https://unix.stackexchange.com/a/149729/47116
if [ $# -lt 2 ]; then
echo usage: sessionName command1 command2 ...
return 1
fi
local sessionName=$1
local firstCommand=$2
local secondAndRestCommands=( "$@:3" )
tmux new-session -s $sessionName -n 'myWindow' -d
tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
local i
for i in "$!secondAndRestCommands[@]"
do
echo $i
local command=$secondAndRestCommands[$i]
echo $command
tmux split-window -v
local tabNumber=$((i+1))
tmux send-keys -t $tabNumber "$command" C-j
done
tmux select-layout even-vertical
tmux attach -t $sessionName
Usage:
tmuxMany sessionName "tail -f file" "tail -f file2" htop
Will open tmux with 3 panes of equal height.
edited Apr 13 '17 at 12:36
Communityâ¦
1
1
answered Dec 23 '16 at 7:53
Maxim Yefremov
22338
22338
add a comment |Â
add a comment |Â
up vote
0
down vote
Assuming you do want to run this from your ~/.tmux.conf
, not an external script, you would append this to your config file:
# session initialisation
new -s SessionName -n WindowName 'tail -f /var/log/apache2/samperror.log'
splitw -h -p 50 -t 0 'tail -f /var/log/apache2/other.log'
selectw -t 0
Then, when you start tmux with the command to attach to a session, tmux a
, it will create SessionName with the window split horizontally (-h
) in half (-p 50
) running those two commands.
is there anyway to make the session automagically attach so I can just runtmux -f tmux.conf
, and if the session already exists it attaches it -- otherwise it initializes and attaches?
â Evan Carroll
Aug 13 '14 at 1:11
@EvanCarroll That is what thea
(a contraction ofattach
) is for. You can always write a function, like so:tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
â jasonwryan
Aug 13 '14 at 1:19
So there is no way to do it from within the .conf file?
â Evan Carroll
Aug 13 '14 at 1:32
1
@EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
â jasonwryan
Aug 13 '14 at 1:39
add a comment |Â
up vote
0
down vote
Assuming you do want to run this from your ~/.tmux.conf
, not an external script, you would append this to your config file:
# session initialisation
new -s SessionName -n WindowName 'tail -f /var/log/apache2/samperror.log'
splitw -h -p 50 -t 0 'tail -f /var/log/apache2/other.log'
selectw -t 0
Then, when you start tmux with the command to attach to a session, tmux a
, it will create SessionName with the window split horizontally (-h
) in half (-p 50
) running those two commands.
is there anyway to make the session automagically attach so I can just runtmux -f tmux.conf
, and if the session already exists it attaches it -- otherwise it initializes and attaches?
â Evan Carroll
Aug 13 '14 at 1:11
@EvanCarroll That is what thea
(a contraction ofattach
) is for. You can always write a function, like so:tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
â jasonwryan
Aug 13 '14 at 1:19
So there is no way to do it from within the .conf file?
â Evan Carroll
Aug 13 '14 at 1:32
1
@EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
â jasonwryan
Aug 13 '14 at 1:39
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Assuming you do want to run this from your ~/.tmux.conf
, not an external script, you would append this to your config file:
# session initialisation
new -s SessionName -n WindowName 'tail -f /var/log/apache2/samperror.log'
splitw -h -p 50 -t 0 'tail -f /var/log/apache2/other.log'
selectw -t 0
Then, when you start tmux with the command to attach to a session, tmux a
, it will create SessionName with the window split horizontally (-h
) in half (-p 50
) running those two commands.
Assuming you do want to run this from your ~/.tmux.conf
, not an external script, you would append this to your config file:
# session initialisation
new -s SessionName -n WindowName 'tail -f /var/log/apache2/samperror.log'
splitw -h -p 50 -t 0 'tail -f /var/log/apache2/other.log'
selectw -t 0
Then, when you start tmux with the command to attach to a session, tmux a
, it will create SessionName with the window split horizontally (-h
) in half (-p 50
) running those two commands.
answered Aug 11 '14 at 21:11
jasonwryan
47.7k14131180
47.7k14131180
is there anyway to make the session automagically attach so I can just runtmux -f tmux.conf
, and if the session already exists it attaches it -- otherwise it initializes and attaches?
â Evan Carroll
Aug 13 '14 at 1:11
@EvanCarroll That is what thea
(a contraction ofattach
) is for. You can always write a function, like so:tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
â jasonwryan
Aug 13 '14 at 1:19
So there is no way to do it from within the .conf file?
â Evan Carroll
Aug 13 '14 at 1:32
1
@EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
â jasonwryan
Aug 13 '14 at 1:39
add a comment |Â
is there anyway to make the session automagically attach so I can just runtmux -f tmux.conf
, and if the session already exists it attaches it -- otherwise it initializes and attaches?
â Evan Carroll
Aug 13 '14 at 1:11
@EvanCarroll That is what thea
(a contraction ofattach
) is for. You can always write a function, like so:tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
â jasonwryan
Aug 13 '14 at 1:19
So there is no way to do it from within the .conf file?
â Evan Carroll
Aug 13 '14 at 1:32
1
@EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
â jasonwryan
Aug 13 '14 at 1:39
is there anyway to make the session automagically attach so I can just run
tmux -f tmux.conf
, and if the session already exists it attaches it -- otherwise it initializes and attaches?â Evan Carroll
Aug 13 '14 at 1:11
is there anyway to make the session automagically attach so I can just run
tmux -f tmux.conf
, and if the session already exists it attaches it -- otherwise it initializes and attaches?â Evan Carroll
Aug 13 '14 at 1:11
@EvanCarroll That is what the
a
(a contraction of attach
) is for. You can always write a function, like so: tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
â jasonwryan
Aug 13 '14 at 1:19
@EvanCarroll That is what the
a
(a contraction of attach
) is for. You can always write a function, like so: tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
â jasonwryan
Aug 13 '14 at 1:19
So there is no way to do it from within the .conf file?
â Evan Carroll
Aug 13 '14 at 1:32
So there is no way to do it from within the .conf file?
â Evan Carroll
Aug 13 '14 at 1:32
1
1
@EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
â jasonwryan
Aug 13 '14 at 1:39
@EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
â jasonwryan
Aug 13 '14 at 1:39
add a comment |Â
up vote
0
down vote
This is how I launch an editor + REPL now:
mux $(basename $(pwd))
"vim $(find src test resources test-resources -type f 2>/dev/null
| tr "n" " ")"
"lein repl"
I hacked on Maxim's code to get a different layout:
#!/bin/bash
#https://unix.stackexchange.com/a/149729/47116
if [ $# -lt 2 ]; then
echo usage: sessionName command1 command2 ...
return 1
fi
sessionName=$1
firstCommand=$2
secondAndRestCommands=( "$@:3" )
tmux new-session -s $sessionName -n 'myWindow' -d
WIN="$sessionName:myWindow"
tmux send-keys -t $WIN.1 "$firstCommand" C-j
for i in "$!secondAndRestCommands[@]"
do
command=$secondAndRestCommands[$i]
echo $i: $command
tmux split-window -v
tabNumber=$((i+2))
tmux send-keys -t $tabNumber "$command" C-j
done
tmux select-pane -t $WIN.1
fixlayout()
tmux set-window-option -t $WIN main-pane-width $(($COLUMNS - 80))
tmux select-layout -t $WIN main-vertical
fixlayout
sleep 1 && fixlayout &
tmux attach -t $sessionName
Incidentally this guy's tmux.conf seems pretty useful.
New contributor
add a comment |Â
up vote
0
down vote
This is how I launch an editor + REPL now:
mux $(basename $(pwd))
"vim $(find src test resources test-resources -type f 2>/dev/null
| tr "n" " ")"
"lein repl"
I hacked on Maxim's code to get a different layout:
#!/bin/bash
#https://unix.stackexchange.com/a/149729/47116
if [ $# -lt 2 ]; then
echo usage: sessionName command1 command2 ...
return 1
fi
sessionName=$1
firstCommand=$2
secondAndRestCommands=( "$@:3" )
tmux new-session -s $sessionName -n 'myWindow' -d
WIN="$sessionName:myWindow"
tmux send-keys -t $WIN.1 "$firstCommand" C-j
for i in "$!secondAndRestCommands[@]"
do
command=$secondAndRestCommands[$i]
echo $i: $command
tmux split-window -v
tabNumber=$((i+2))
tmux send-keys -t $tabNumber "$command" C-j
done
tmux select-pane -t $WIN.1
fixlayout()
tmux set-window-option -t $WIN main-pane-width $(($COLUMNS - 80))
tmux select-layout -t $WIN main-vertical
fixlayout
sleep 1 && fixlayout &
tmux attach -t $sessionName
Incidentally this guy's tmux.conf seems pretty useful.
New contributor
add a comment |Â
up vote
0
down vote
up vote
0
down vote
This is how I launch an editor + REPL now:
mux $(basename $(pwd))
"vim $(find src test resources test-resources -type f 2>/dev/null
| tr "n" " ")"
"lein repl"
I hacked on Maxim's code to get a different layout:
#!/bin/bash
#https://unix.stackexchange.com/a/149729/47116
if [ $# -lt 2 ]; then
echo usage: sessionName command1 command2 ...
return 1
fi
sessionName=$1
firstCommand=$2
secondAndRestCommands=( "$@:3" )
tmux new-session -s $sessionName -n 'myWindow' -d
WIN="$sessionName:myWindow"
tmux send-keys -t $WIN.1 "$firstCommand" C-j
for i in "$!secondAndRestCommands[@]"
do
command=$secondAndRestCommands[$i]
echo $i: $command
tmux split-window -v
tabNumber=$((i+2))
tmux send-keys -t $tabNumber "$command" C-j
done
tmux select-pane -t $WIN.1
fixlayout()
tmux set-window-option -t $WIN main-pane-width $(($COLUMNS - 80))
tmux select-layout -t $WIN main-vertical
fixlayout
sleep 1 && fixlayout &
tmux attach -t $sessionName
Incidentally this guy's tmux.conf seems pretty useful.
New contributor
This is how I launch an editor + REPL now:
mux $(basename $(pwd))
"vim $(find src test resources test-resources -type f 2>/dev/null
| tr "n" " ")"
"lein repl"
I hacked on Maxim's code to get a different layout:
#!/bin/bash
#https://unix.stackexchange.com/a/149729/47116
if [ $# -lt 2 ]; then
echo usage: sessionName command1 command2 ...
return 1
fi
sessionName=$1
firstCommand=$2
secondAndRestCommands=( "$@:3" )
tmux new-session -s $sessionName -n 'myWindow' -d
WIN="$sessionName:myWindow"
tmux send-keys -t $WIN.1 "$firstCommand" C-j
for i in "$!secondAndRestCommands[@]"
do
command=$secondAndRestCommands[$i]
echo $i: $command
tmux split-window -v
tabNumber=$((i+2))
tmux send-keys -t $tabNumber "$command" C-j
done
tmux select-pane -t $WIN.1
fixlayout()
tmux set-window-option -t $WIN main-pane-width $(($COLUMNS - 80))
tmux select-layout -t $WIN main-vertical
fixlayout
sleep 1 && fixlayout &
tmux attach -t $sessionName
Incidentally this guy's tmux.conf seems pretty useful.
New contributor
New contributor
answered Oct 1 at 8:07
lxs
1011
1011
New contributor
New contributor
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f149606%2fhow-do-i-create-a-simple-tmux-conf-that-splits-a-window%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
â jasonwryan
Aug 11 '14 at 20:39
@jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
â Evan Carroll
Aug 11 '14 at 20:48