dotfiles/.config/scripts/sessions.sh

190 lines
4.2 KiB
Bash
Raw Normal View History

2025-05-02 06:09:07 -05:00
#!/usr/bin/zsh
source ~/.config/shell/functions.zsh
2025-04-06 10:08:57 -05:00
2025-04-06 15:37:33 -05:00
new() {
2025-04-06 10:08:57 -05:00
2025-04-06 15:37:33 -05:00
dir=${1:-}
2025-04-06 10:08:57 -05:00
2025-05-28 05:37:15 -05:00
if [ -z "${dir}" ]; then
name=$(find "$HOME/Documents/gitlab" -mindepth 2 -maxdepth 2 -type d \
| awk -F/ '{print $(NF-1)"/"$NF}' \
| sort \
| wofi -dmenu -i -p "New Session" --columns 1)
if [ -z "$name" ]; then
return
fi
2025-06-15 15:47:24 -05:00
if [ -d "$name" ]; then
dir="$name"
else
# If 'name' isn't a directory, assume it's a subfolder name and search within "Documents/gitlab"
dir=$(find "$HOME/Documents/gitlab" -mindepth 2 -maxdepth 2 -type d | grep "$name$" | head -n 1)
if [ -z "$dir" ]; then
echo "Error: Directory not found for '$name' in Documents/gitlab." >&2
return 1 # Or exit, depending on your script's error handling
fi
fi
2025-05-28 05:37:15 -05:00
fi
if [ -z "$dir" ]; then
return
fi
2025-04-06 10:08:57 -05:00
name=$(basename "$dir")
if [[ $name == .* ]]; then
name=${name#.}
fi
2025-05-06 06:15:43 -05:00
tmux has-session -t ${name} 2>/dev/null && {
2025-04-06 10:08:57 -05:00
tmux switch-client -t ${name}
return
}
2025-05-06 06:15:43 -05:00
2025-04-06 10:08:57 -05:00
tmux new-session -d -s "$name" -c "$dir"
tmux rename-window -t "$name" "nvim"
tmux new-window -t "$name" -n terminal -c "$dir"
sleep 1
2025-04-10 05:56:48 -05:00
tmux send-keys -t "$name:1" 'tmux set status on; set-env; nvim' C-m
2025-04-06 10:08:57 -05:00
tmux select-window -t "$name:1"
tmux switch-client -t "$name"
2025-04-06 15:37:33 -05:00
}
2025-04-06 10:08:57 -05:00
2025-04-13 09:03:39 -05:00
goland-new() {
dir=${1:-}
2025-05-28 05:37:15 -05:00
if [ -z "${dir}" ]; then
name=$(find "$HOME/Documents/gitlab" -mindepth 2 -maxdepth 2 -type d \
| awk -F/ '{print $(NF-1)"/"$NF}' \
| sort \
| wofi -dmenu -i -p "New JetBrains Session" --columns 1)
if [ -z "$name" ]; then
return
fi
dir=$(find "$HOME/Documents/gitlab" -mindepth 2 -maxdepth 2 -type d | grep "$name$" | head -n 1)
fi
if [ -z "$dir" ]; then
return
fi
name=$(basename "$dir")
if [[ $name == .* ]]; then
name=${name#.}
fi
2025-04-13 09:03:39 -05:00
2025-04-24 10:40:42 -05:00
if [[ $dir == *'dotnet'* ]]; then
/home/user/.local/share/JetBrains/Toolbox/apps/rider/bin/rider $dir &
elif [[ $dir == *'go'* ]]; then
/home/user/.local/share/JetBrains/Toolbox/apps/goland/bin/goland $dir &
elif [[ $dir == *'devops'* ]]; then
/home/user/.local/share/JetBrains/Toolbox/apps/goland/bin/goland $dir &
fi
#sleep 1 && /home/user/.local/share/JetBrains/Toolbox/apps/goland/bin/goland $dir &
2025-04-13 09:03:39 -05:00
}
2025-04-06 15:37:33 -05:00
switch() {
2025-04-06 10:08:57 -05:00
2025-07-17 06:47:25 -05:00
session=$(tmux list-sessions -F '#{session_name}' |
2025-04-06 10:08:57 -05:00
sed '/^popup/d' |
2025-04-06 17:27:18 -05:00
sed '/^scratch/d' |
2025-04-06 10:08:57 -05:00
sed '/^$/d' |
2025-07-17 06:47:25 -05:00
fzf --reverse --header 'Switch Session' --no-preview)
2025-04-06 10:08:57 -05:00
2025-07-17 06:47:25 -05:00
[ -z "$session" ] && return 1
tmux switch-client -t $session
2025-04-06 15:37:33 -05:00
}
2025-04-06 10:08:57 -05:00
2025-04-06 15:37:33 -05:00
delete() {
2025-04-06 10:08:57 -05:00
2025-07-17 06:47:25 -05:00
session=$(tmux list-sessions -F '#{session_name}' |
2025-04-06 10:08:57 -05:00
sed '/^popup/d' |
2025-04-06 17:27:18 -05:00
sed '/^scratch/d' |
sed '/^general/d' |
2025-04-06 10:08:57 -05:00
sed '/^$/d' |
2025-09-05 21:49:50 -05:00
fzf --reverse --header 'Delete Session' --no-preview)
2025-07-17 06:47:25 -05:00
[ -z "$session" ] && return 1
tmux kill-session -t $session
2025-04-06 15:37:33 -05:00
}
2025-04-06 10:08:57 -05:00
2025-04-06 15:37:33 -05:00
window() {
2025-04-07 06:14:12 -05:00
current_window=$(tmux display-message -p '#I')
2025-04-06 10:08:57 -05:00
window=$(tmux list-windows -F '#{window_index} #{window_name}' |
2025-04-07 06:14:12 -05:00
sed "/^$/d" |
grep -v "$current_window" |
2025-04-06 10:08:57 -05:00
fzf --reverse --header 'Switch Window' --no-preview |
cut -d ' ' -f 1)
[ -z "$window" ] && return 1
tmux select-window -t $window
2025-04-06 15:37:33 -05:00
}
2025-04-08 06:48:07 -05:00
notes() {
name="notes"
tmux has-session -t ${name} >/dev/null && {
tmux attach-session -t ${name}
return
}
tmux new-session -d -s "$name" -c "$HOME/Documents/notes"
tmux new-session -s notes nvim Welcome.md
sleep 1
2025-04-08 07:01:07 -05:00
tmux send-keys -t "$name" 'tmux set -g status off;clear' C-m
2025-04-08 06:48:07 -05:00
tmux send-keys -t "$name" 'nvim Welcome.md' C-m
tmux attach-session -t "$name"
}
2025-04-08 07:01:07 -05:00
popup() {
name="popup"
tmux has-session -t ${name} >/dev/null && {
tmux attach-session -t ${name}
return
}
tmux new-session -d -s "$name" -c "$HOME"
sleep 1
tmux send-keys -t "$name" 'tmux set -g status off;clear' C-m
tmux attach-session -t "$name"
}
2025-04-08 07:05:48 -05:00
scratch() {
name="scratch"
tmux has-session -t ${name} >/dev/null && {
tmux attach-session -t ${name}
return
}
tmux new-session -d -s "$name" -c "$HOME"
sleep 1
tmux send-keys -t "$name" 'tmux set -g status off;clear' C-m
tmux send-keys -t "$name" 'nvim scratch' C-m
tmux attach-session -t "$name"
}
2025-04-06 15:37:33 -05:00
case "$1" in
new) new $2 ;;
switch) switch ;;
delete) delete ;;
window) window ;;
2025-04-08 06:48:07 -05:00
notes) notes ;;
2025-04-08 07:01:07 -05:00
popup) popup ;;
2025-04-08 07:05:48 -05:00
scratch) scratch ;;
2025-04-13 09:03:39 -05:00
goland-new) goland-new $2 ;;
2025-04-06 15:37:33 -05:00
*) echo "Please enter an action" ;;
esac