Add session-created hook to automate session layouts

This commit is contained in:
Kenneth Benzie 2022-09-20 13:32:44 +01:00
parent 27025bffbd
commit 1e14c8f9c6
4 changed files with 21 additions and 0 deletions

9
hooks/session-create.sh Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
session_name=$(tmux display-message -p '#S')
session_layout=~/.local/share/tmux/layouts/session-$session_name
if [ -f $session_layout ]; then
tmux source-file $session_layout
else
tmux rename-window home
fi

7
layouts/session-local Normal file
View File

@ -0,0 +1,7 @@
rename-window home
new-window -c ~/.config/local
rename-window local
move-window -s local:local -t 9
select-window -t local:home
# vim: filetype=tmux

View File

@ -14,6 +14,8 @@
dest: ~/.tmux.conf dest: ~/.tmux.conf
- src: ~/.config/tmux/layouts/session-main - src: ~/.config/tmux/layouts/session-main
dest: ~/.local/share/tmux/layouts/session-main dest: ~/.local/share/tmux/layouts/session-main
- src: ~/.config/tmux/layouts/session-local
dest: ~/.local/share/tmux/layouts/session-local
- src: ~/.config/tmux/layouts/window-tall - src: ~/.config/tmux/layouts/window-tall
dest: ~/.local/share/tmux/layouts/window-tall dest: ~/.local/share/tmux/layouts/window-tall
- src: ~/.config/tmux/layouts/window-wide-left - src: ~/.config/tmux/layouts/window-wide-left

View File

@ -1,3 +1,6 @@
# Set global hooks to perform actions when events occur
set-hook -g session-created 'run ~/.config/tmux/hooks/session-create.sh'
# Set the tmux version to check for command support # Set the tmux version to check for command support
run 'tmux setenv -g TMUX_VERSION $(tmux -V | cut -c 6-8)' run 'tmux setenv -g TMUX_VERSION $(tmux -V | cut -c 6-8)'