1
0
Fork 0
mirror of https://github.com/pnx/dotfiles synced 2026-06-16 03:14:55 +02:00

adding new tmux session scripts

This commit is contained in:
Henrik Hautakoski 2024-11-03 13:52:59 +01:00
parent 891ce58272
commit 06293d3a17
6 changed files with 42 additions and 14 deletions

View file

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

1
scripts/tmuxs/.env Normal file
View file

@ -0,0 +1 @@
FZF="fzf --tmux=center --border=sharp --separator=─ --margin=0 --layout=reverse --preview="

2
scripts/tmuxs/kill.sh Executable file
View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
tmux kill-session -t $(echo $@ | sed 's/: .*//g')

8
scripts/tmuxs/list-sessions.sh Executable file
View file

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

20
scripts/tmuxs/main.sh Executable file
View file

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

View file

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