update
This commit is contained in:
parent
c246bf6a45
commit
4481e4ceaf
5 changed files with 231 additions and 48 deletions
30
.config/scripts/sessions.sh
Normal file → Executable file
30
.config/scripts/sessions.sh
Normal file → Executable file
|
|
@ -1,11 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
action=${1:-}
|
||||
new() {
|
||||
|
||||
[ -z "$action" ] && echo "Please enter an action" && return 1
|
||||
dir=${1:-}
|
||||
|
||||
if [[ $action == "new" ]]; then
|
||||
dir=$(find $HOME/Documents/gitlab -mindepth 2 -maxdepth 2 -type d | awk -F/ '{print $(NF-1)"/"$NF " " $0}' | fzf --no-preview --reverse --header "New Session" --with-nth=1 | awk '{print $2}')
|
||||
[ -z "${dir}" ] && dir=$(find $HOME/Documents/gitlab -mindepth 2 -maxdepth 2 -type d | awk -F/ '{print $(NF-1)"/"$NF " " $0}' | fzf --reverse --header "New Session" --with-nth=1 | awk '{print $2}')
|
||||
[ -z "$dir" ] && return 1
|
||||
|
||||
name=$(basename "$dir")
|
||||
|
|
@ -24,9 +23,9 @@ if [[ $action == "new" ]]; then
|
|||
tmux send-keys -t "$name:1" 'set-env; nvim' C-m
|
||||
tmux select-window -t "$name:1"
|
||||
tmux switch-client -t "$name"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ $action == "switch" ]]; then
|
||||
switch() {
|
||||
|
||||
tmux list-sessions -F '#{?session_attached,,#{session_name}}' |
|
||||
sed '/^popup/d' |
|
||||
|
|
@ -34,20 +33,18 @@ if [[ $action == "switch" ]]; then
|
|||
fzf --reverse --header 'Switch Session' --preview 'tmux capture-pane -pt {}' \
|
||||
--bind 'enter:execute(tmux switch-client -t {})+accept'
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ $action == "delete" ]]; then
|
||||
delete() {
|
||||
|
||||
tmux list-sessions -F '#{?session_attached,,#{session_name}}' |
|
||||
sed '/^popup/d' |
|
||||
sed '/^$/d' |
|
||||
fzf --reverse --header 'Delete Session' --preview 'tmux capture-pane -pt {}' \
|
||||
--bind 'enter:execute(tmux kill-session -t {})+accept'
|
||||
}
|
||||
|
||||
fi
|
||||
|
||||
if [[ $action == "window" ]]; then
|
||||
|
||||
window() {
|
||||
window=$(tmux list-windows -F '#{window_index} #{window_name}' |
|
||||
sed '/^$/d' |
|
||||
fzf --reverse --header 'Switch Window' --no-preview |
|
||||
|
|
@ -56,5 +53,12 @@ if [[ $action == "window" ]]; then
|
|||
[ -z "$window" ] && return 1
|
||||
|
||||
tmux select-window -t $window
|
||||
}
|
||||
|
||||
fi
|
||||
case "$1" in
|
||||
new) new $2 ;;
|
||||
switch) switch ;;
|
||||
delete) delete ;;
|
||||
window) window ;;
|
||||
*) echo "Please enter an action" ;;
|
||||
esac
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue