diff --git a/omz-custom/custom_commands.sh b/omz-custom/custom_commands.sh index 88fd976..bc47f89 100755 --- a/omz-custom/custom_commands.sh +++ b/omz-custom/custom_commands.sh @@ -403,3 +403,6 @@ function gpla() { echo "Finished fetching branches." } + +# source the tmux-sessions.sh in the same folder +source $(dirname "$0")/tmux-sessions.sh diff --git a/omz-custom/tmux-sessions.sh b/omz-custom/tmux-sessions.sh new file mode 100644 index 0000000..78f9738 --- /dev/null +++ b/omz-custom/tmux-sessions.sh @@ -0,0 +1,28 @@ +function mux() { + project_dir=$1 + if [[ -z "$project_dir" ]]; then + echo "Usage: mux [session_name]" + return 1 + fi + session_name=${2:-$(basename $(realpath "$project_dir"))} + whole_path=$(realpath "$project_dir") + if [[ $whole_path == "*No such file or directory*" ]]; then + echo "Directory does not exist: $project_dir" + return 1 + fi + + # check if file doesn't exist yet in the tmuxinator config directory + tmuxinator_config=~/.config/tmuxinator/$session_name.yml + if [[ -f $tmuxinator_config ]]; then + echo "File already exists" + else + cp ~/.config/tmuxinator/template.yml.temp $tmuxinator_config + # replace variables in placeholder config with real values - PROJECT_NAME, PROJECT_ROOT + sed -i '' "s|{{\$PROJECT_NAME}}|$session_name|g" $tmuxinator_config + sed -i '' "s|{{\$PROJECT_ROOT}}|$whole_path|g" "$tmuxinator_config" + fi + + tmuxinator start $session_name + +} +complete -o default mux diff --git a/tmuxinator/template.yml.temp b/tmuxinator/template.yml.temp new file mode 100644 index 0000000..5111ddb --- /dev/null +++ b/tmuxinator/template.yml.temp @@ -0,0 +1,10 @@ +--- +name: {{$PROJECT_NAME}} +project_root: {{$PROJECT_ROOT}} +windows: +- zsh: + layout: b8f6,198x59,0,0[198x39,0,0,71,198x19,0,40{99x19,0,40,73,98x19,100,40,75}] + panes: + - nvim + - + - dcud