From 7bfb102dacf04dd3de81902354b7f5850cac15a5 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Tue, 12 Mar 2024 17:35:15 -0500 Subject: [PATCH] new: Added open-in-tmux.sh --- README.md | 2 +- open-in-tmux.sh | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 open-in-tmux.sh diff --git a/README.md b/README.md index 45d157e..a23717d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Number of scripts](https://img.shields.io/badge/number_of_scripts-39-blue) +![Number of scripts](https://img.shields.io/badge/number_of_scripts-40-blue) # Random Scripts This repository is for random scripts I wrote mostly for personal use. diff --git a/open-in-tmux.sh b/open-in-tmux.sh new file mode 100644 index 0000000..5737908 --- /dev/null +++ b/open-in-tmux.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# This script checks if any tmux panes are open in our current working directory. +# If yes, it switches to that window given it's not busy i.e. only has the shell running. +# If no, it creates a new window and switches to it. +# I use it as a startup command in alacritty. + +target_path="$(pwd -P)" + +tmux list-panes -s -F '#{window_id} #{pane_id} #{pane_current_path} #{pane_current_command}' \ +| while IFS=' ' read -r window pane path cmd; do + [[ "$path" = "$target_path" && " fish bash zsh " =~ " $cmd " ]] \ + && tmux select-pane -t "$pane" && tmux select-window -t "$window" && exit 0 +done || tmux new-window -c "$target_path" + +tmux new -As0 +