new: Added open-in-tmux.sh

This commit is contained in:
Sayantan Santra 2024-03-12 17:35:15 -05:00
parent 026b6117df
commit 7bfb102dac
Signed by: SinTan1729
GPG Key ID: EB3E68BFBA25C85F
2 changed files with 18 additions and 1 deletions

View File

@ -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.

17
open-in-tmux.sh Normal file
View File

@ -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