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:
parent
891ce58272
commit
06293d3a17
6 changed files with 42 additions and 14 deletions
1
scripts/tmuxs/.env
Normal file
1
scripts/tmuxs/.env
Normal file
|
|
@ -0,0 +1 @@
|
|||
FZF="fzf --tmux=center --border=sharp --separator=─ --margin=0 --layout=reverse --preview="
|
||||
2
scripts/tmuxs/kill.sh
Executable file
2
scripts/tmuxs/kill.sh
Executable 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
8
scripts/tmuxs/list-sessions.sh
Executable 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
20
scripts/tmuxs/main.sh
Executable 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
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue