mirror of
https://github.com/SinTan1729/random.git
synced 2024-12-25 04:48:37 -06:00
new: Added open-in-tmux.sh
This commit is contained in:
parent
026b6117df
commit
7bfb102dac
2 changed files with 18 additions and 1 deletions
|
@ -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
17
open-in-tmux.sh
Normal 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
|
||||
|
Loading…
Reference in a new issue