diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2021-08-04 14:43:50 -0400 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2021-08-04 14:43:50 -0400 |
commit | 1f624ca63f948f95155f2a95fe8f0d762fb863cb (patch) | |
tree | 5030e4b0eabe040c9f6ea124e3c10679684cd81d | |
parent | 2ea9a4398349965ca3380491294081f6d76ab973 (diff) |
tmux-float a better approach to floating windows
-rwxr-xr-x | .local/bin/tmux-toggle | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/.local/bin/tmux-toggle b/.local/bin/tmux-toggle new file mode 100755 index 0000000..ab1f7bc --- /dev/null +++ b/.local/bin/tmux-toggle @@ -0,0 +1,29 @@ +#!/bin/sh + +# Create a tmux window which is floating for use as a scratchpad. +# Takes in two arguments: +# session: title of the terminal window +# software: software to run +# flags: script to run when initializing the tmux session + +session="$1" +software="$2" +shift 2 +flags="$@" + +# Check if this software is started within tmux (start it if not) +tmux has-session -t $session 2>/dev/null +if [ $? != 0 ]; then + tmux new-session -d -s $session "$software $flags" + $TERMINAL -c "dropdown" -t "$session" -e tmux attach-session -t "$session" + exit +fi + +case "$(tmux list-sessions | grep "$session" )" in + # If the session is open, close it + *"attached"*) tmux detach -s "$session" ;; + *) $TERMINAL -c "dropdown" -t "$session" -e tmux attach-session -t "$session" ;; +esac + +# # If the session is closed, open it +# check_state && tmux detach -s "$session" |