From 06293d3a17f66f9bb2ca3815c33277e534af62d2 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 3 Nov 2024 13:52:59 +0100 Subject: [PATCH] adding new tmux session scripts --- install.sh | 3 ++- scripts/tmuxs/.env | 1 + scripts/tmuxs/kill.sh | 2 ++ scripts/tmuxs/list-sessions.sh | 8 ++++++++ scripts/tmuxs/main.sh | 20 ++++++++++++++++++++ scripts/{tmuxs => tmuxs/new.sh} | 22 +++++++++------------- 6 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 scripts/tmuxs/.env create mode 100755 scripts/tmuxs/kill.sh create mode 100755 scripts/tmuxs/list-sessions.sh create mode 100755 scripts/tmuxs/main.sh rename scripts/{tmuxs => tmuxs/new.sh} (54%) diff --git a/install.sh b/install.sh index e08d53c..1801270 100755 --- a/install.sh +++ b/install.sh @@ -30,6 +30,7 @@ ln -sfr $BASE_PATH/picom.conf $HOME/.config/picom.conf ln -sfr $BASE_PATH/fzfrc $HOME/.config/fzfrc mkdir -p $HOME/bin -for script in $(find $BASE_PATH/scripts -type f); do +ln -sfr $BASE_PATH/scripts/tmuxs/main.sh $HOME/bin/tmuxs +for script in $(find $BASE_PATH/scripts -maxdepth 1 -type f); do ln -sfr $script $HOME/bin/$(basename $script) done diff --git a/scripts/tmuxs/.env b/scripts/tmuxs/.env new file mode 100644 index 0000000..0d11963 --- /dev/null +++ b/scripts/tmuxs/.env @@ -0,0 +1 @@ +FZF="fzf --tmux=center --border=sharp --separator=─ --margin=0 --layout=reverse --preview=" diff --git a/scripts/tmuxs/kill.sh b/scripts/tmuxs/kill.sh new file mode 100755 index 0000000..f27d39b --- /dev/null +++ b/scripts/tmuxs/kill.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +tmux kill-session -t $(echo $@ | sed 's/: .*//g') diff --git a/scripts/tmuxs/list-sessions.sh b/scripts/tmuxs/list-sessions.sh new file mode 100755 index 0000000..abb6958 --- /dev/null +++ b/scripts/tmuxs/list-sessions.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# if [[ ! -z $TMUX ]]; then +# tmux list-sessions -F '#{?session_attached,,#{session_name}}' | grep '\S' +# else + tmux list-sessions -F '#{session_name}' +# fi + diff --git a/scripts/tmuxs/main.sh b/scripts/tmuxs/main.sh new file mode 100755 index 0000000..c7b32ca --- /dev/null +++ b/scripts/tmuxs/main.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +BASE_PATH=$(dirname $(readlink -f $BASH_SOURCE)) +source ${BASE_PATH}/.env + +# Scripts +LIST_SESSIONS_SCRIPT=${BASE_PATH}/list-sessions.sh +KILL_SCRIPT=${BASE_PATH}/kill.sh + + +if [[ $# -eq 1 ]]; then + if [[ "$1" == "-a" ]]; then + selected=$($LIST_SESSIONS_SCRIPT | $FZF --bind "ctrl-d:execute(${KILL_SCRIPT} {})+reload(${LIST_SESSIONS_SCRIPT})" --border-label=Session | sed 's/: .*//g') + ${BASE_PATH}/new.sh $selected + else + ${BASE_PATH}/new.sh $(realpath $1) + fi +else + ${BASE_PATH}/new.sh +fi + diff --git a/scripts/tmuxs b/scripts/tmuxs/new.sh similarity index 54% rename from scripts/tmuxs rename to scripts/tmuxs/new.sh index 28e03dc..161a127 100755 --- a/scripts/tmuxs +++ b/scripts/tmuxs/new.sh @@ -1,20 +1,15 @@ #!/usr/bin/env bash - -FZF="fzf --preview=" +BASE_PATH=$(dirname $(readlink -f $BASH_SOURCE)) +source ${BASE_PATH}/.env if [[ $# -eq 1 ]]; then - if [[ "$1" -eq "-a" ]]; then - selected=$(tmux list-sessions | $FZF | sed 's/: .*//g') - else - selected=$(realpath $1) + selected=$1 +else + DIRECTORIES=$(cat ~/.tmuxs | sed "s&^\~&${HOME}&g") + selected=$(find ${DIRECTORIES} -mindepth 1 -maxdepth 1 -type d | $FZF --border-label="New Session") + if [[ -z $selected ]]; then + exit 0 fi -else - DIRECTORIES=$(cat ~/.tmuxs | sed "s&^\~&${HOME}&g") - selected=$(find ${DIRECTORIES} -mindepth 1 -maxdepth 1 -type d | $FZF) -fi - -if [[ -z $selected ]]; then - exit 0 fi selected_name=$(basename "$selected" | tr . _) @@ -30,3 +25,4 @@ if ! tmux has-session -t=$selected_name 2> /dev/null; then fi tmux switch-client -t $selected_name +