2.7 KiB
2.7 KiB
Create a tmux session
This script help me to create a tmux session and manage related windows, panes and commands.
Usage
create-tmux-session -n <name> -i <id> -p <project> <command> <command>
-n --name <name> define a session name
-i --id <id> define a session id,
-r --repo <project> define the repo used as base directory if not defined
'ghq' and 'fzf' will be use to let you select one
<command> a command launched in the new created session. you can
use it many time.
Commands
Commands create windows and panes, launch program and change current directory related to git project (managed by [ghq][ghq]). Each command can take a parameter which is mandatpry if no default value exists. If parameter contains spaces, must be surrounded by quotes / double quote.
vsplit
: split current pane vertically, parameter define the vertical size of the created pane in percent (default 20).# split first windows, new created pane will take 50% of vertical space create-tmux-session.sh -n mysession vsplit:50
hsplit
: split current pane horizontally# split first windows, new created pane will take 50% of horizontal space create-tmux-session.sh -n mysession hsplit:50
neww
: create a new windows, parameter define the new windows name (not mandatory)# Create a new window name 'shell' create-tmux-session.sh -n mysession -r blog neww:shell
run
: launch a command in last created element (window / pane ), parameter define command.# Just launch ls create-tmux-session.sh -n mysession -r blog run:ls # This time with parameters create-tmux-session.sh -n mysession -r blog "run:ls -la"
repo
: change current directory to given git repository in parameter. If not parameter is provided, script will launch a menu to select one withfzf
. New directory will take effect for new created panes / windows afterrepo
command.# change current directory ti ephase:nix repo create-tmux-session.sh -n mysession -r blog repo:ephase/nix neww
Example
Create a new session for my blog repository, launch Neovim, split pane to create a terminal pane bellow text editor then create a new window to lanche development server
create-tmux-session.sh -n blog -r ephase/blog 'run:nvim .' vsplit neww 'run:task serve'
Create a new session for my blog like previous example but open new windows with my nix repository and launch Neovim
create-tmux-session.sh -n blog -r ephase/blog 'run:nvim .' vsplit neww 'run:task serve' repo:ephase/nix neww:nix 'run:nvim .'