Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Start up tmux with custom windows, panes and applications running
#!/bin/sh
#
# Setup a work space called `work` with two windows
# first window has 3 panes.
# The first pane set at 65%, split horizontally, set to api root and running vim
# pane 2 is split at 25% and running redis-server
# pane 3 is set to api root and bash prompt.
# note: `api` aliased to `cd ~/path/to/work`
#
session="work"
# set up tmux
tmux start-server
# create a new tmux session, starting vim from a saved session in the new window
tmux new-session -d -s $session -n vim #"vim -S ~/.vim/sessions/kittybusiness"
# Select pane 1, set dir to api, run vim
tmux selectp -t 1
tmux send-keys "api;vim" C-m
# Split pane 1 horizontal by 65%, start redis-server
tmux splitw -h -p 35
tmux send-keys "redis-server" C-m
# Select pane 2
tmux selectp -t 2
# Split pane 2 vertiacally by 25%
tmux splitw -v -p 75
# select pane 3, set to api root
tmux selectp -t 3
tmux send-keys "api" C-m
# Select pane 1
tmux selectp -t 1
# create a new window called scratch
tmux new-window -t $session:1 -n scratch
# return to main vim window
tmux select-window -t $session:0
# Finished setup, attach to the tmux session!
tmux attach-session -t $session
@MorganeAD
Copy link

MorganeAD commented Jul 29, 2016

I love you! You help me to automatize all my tmux lauch, I will save so much time each morning!

@joshbaptiste
Copy link

joshbaptiste commented May 20, 2017

Great script, helped me figure out default startup parameters,, cheers

@azizLIGHT
Copy link

azizLIGHT commented Mar 23, 2018

Found this on google. Great way to startup common tasks

@jpdippenaarS
Copy link

jpdippenaarS commented May 3, 2018

Rock star. Thanks!!

@iosifv
Copy link

iosifv commented Sep 16, 2018

Legend!

@AffanIndo
Copy link

AffanIndo commented Jan 14, 2019

Thank you for this! But there are several things that I don't understand.

  1. What is the function of whitespace after C-m on line 20 and 24? I remove the whitespace and it is still works.

  2. I try to use my script without tmux start-server, and it still work perfectly.

Once again, thank you! this gist is the best.

@zackyaple
Copy link

zackyaple commented Jan 22, 2019

Great script!!

@kosivantsov
Copy link

kosivantsov commented Feb 18, 2019

Love it, thanks a ton for the script.

@develforever
Copy link

develforever commented Mar 29, 2019

Carefuly read man page: http://man7.org/linux/man-pages/man1/tmux.1.html @AffanIndo

Thank you for this! But there are several things that I don't understand.

  1. What is the function of whitespace after C-m on line 20 and 24? I remove the whitespace and it is still works.
    m Mark the current pane (see select-pane -m).
  2. I try to use my script without tmux start-server, and it still work perfectly.

Once again, thank you! this gist is the best.

start-server
(alias: start)
Start the tmux server, if not already running, without creating
any sessions.

send-keys [-lMRX] [-N repeat-count] [-t target-pane] key ...
(alias: send)
Send a key or keys to a window. Each argument key is the name
of the key (such as ‘C-a’ or ‘NPage’) to send; if the string is
not recognised as a key, it is sent as a series of characters.
The -l flag disables key name lookup and sends the keys liter‐
ally. All arguments are sent sequentially from first to last.
The -R flag causes the terminal state to be reset.

         -M passes through a mouse event (only valid if bound to a mouse
         key binding, see MOUSE SUPPORT).

         -X is used to send a command into copy mode - see the WINDOWS
         AND PANES section.  -N specifies a repeat count.

@rcgoodfellow
Copy link

rcgoodfellow commented May 1, 2019

awesome, thanks!

@botenvouwer
Copy link

botenvouwer commented May 6, 2019

Very nice, much thanks, it makes my day easier.

@cmdcolin
Copy link

cmdcolin commented May 19, 2019

As long as we are here, you might consider getting on the tmux-resurrect train https://github.com/tmux-plugins/tmux-resurrect along with other plugins with tmux-plugin-manager. Pretty simple to save and restore apps that are running, but some are non-default and you can add them with

set -g @resurrect-processes '~cmus'

@mcai4gl2
Copy link

mcai4gl2 commented Aug 18, 2019

Brilliant!

@bilalix
Copy link

bilalix commented Feb 5, 2020

Thank you!!

@maluramichael
Copy link

maluramichael commented Mar 2, 2020

Thank you @todgru

@aamnah
Copy link

aamnah commented Aug 9, 2020

This is excellent, thank you! I was going to toil away writing my own but i'm glad i found yours :D

@imse-ty
Copy link

imse-ty commented Oct 4, 2020

Thanks!

@darzyx
Copy link

darzyx commented Dec 17, 2020

Very helpful, thanks for posting this!

@todgru
Copy link
Author

todgru commented Dec 17, 2020

@niouby you're too kind! ❤️ glad I could help!
@joshbaptiste you are welcome!
@azizLIGHT glad you like it!
@jpdippenaarS excellent! 🤘
@iosifv too kind!
@AffanIndo you're welcome! great questions - see @develforever got you covered.
@zackyaple thanks!
@kosivantsov anytime!
@develforever thanks for the contribution - nice work!
@rcgoodfellow you're welcome!
@botenvouwer nice! work smarter not harder 😎
@cmdcolin tmux-resurrect looks like a very useful tool! thank you!
@mcai4gl2 nah, i just searched man pages to figure this stuff out 😊 thank you!
@bilalelhoudaigui you're welcome!
@maluramichael you're welcome, anytime!
@aamnah you're welcome! i'm happy to have helped you save time and effort!
@setymedia you're welcome!
@darzyx glad i could help out!

thanks to everyone for the stars! 🤩
🎉 happy holidays! 🎄 🕎 ☪️ 🎉

@riazspace
Copy link

riazspace commented Feb 6, 2021

Nice

@ocpodariu
Copy link

ocpodariu commented Feb 20, 2021

Thanks for posting it 👍

@pottsga
Copy link

pottsga commented Jun 16, 2021

Thanks!

@MarkusMueller-DS
Copy link

MarkusMueller-DS commented Oct 9, 2021

thanks for posting, helped me a lot to set up my startup script 👍🏼

@zoj613
Copy link

zoj613 commented Nov 28, 2021

Much appreciated for this script. I was able to modify it to automate the launch of different ncmpcpp panes for displaying the media library, playlist and visualization.

@alexmachina
Copy link

alexmachina commented Dec 28, 2021

Amazing

@MondeSinxi
Copy link

MondeSinxi commented Apr 28, 2022

This is great! Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment