This commit is contained in:
DeveloperDurp 2025-04-06 15:37:33 -05:00
parent c246bf6a45
commit 4481e4ceaf
5 changed files with 231 additions and 48 deletions

View file

@ -1,33 +0,0 @@
#!/bin/bash
dir=${1:-}
[ -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")
if [[ $name == .* ]]; then
name=${name#.}
fi
tmux has-session -t ${name} >/dev/null && {
tmux switch-client -t ${name}
return
}
tmux new-session -d -s "$name" -c "$dir"
RIGHT_PANE_WIDTH=60
BOTTOM_PANE_WIDTH=15
tmux split-window -h -t "$name:1" -c "$dir"
tmux resize-pane -t "$name:1.2" -x $RIGHT_PANE_WIDTH
tmux split-window -v -t "$name:1.1" -c "$dir"
tmux resize-pane -t "$name:1.1" -y $(($(tmux display -p '#{window_height}') - $BOTTOM_PANE_WIDTH))
tmux new-window "$name" -n lazygit -c "$dir"
sleep 1
tmux send-keys -t "$name:1.1" 'set-env; nvim' C-m
sleep 0.1
tmux send-keys -t "$name:1.3" 'set-env; nvim +CodeCompanionChat -c only' C-m
sleep 1
tmux send-keys -t "$name:2" 'lg' C-m
tmux select-window -t "$name:1"
tmux select-pane -t "$name:1.1"
tmux switch-client -t "$name"

30
.config/scripts/sessions.sh Normal file → Executable file
View 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