mirror of
https://github.com/kristoferssolo/solorice.git
synced 2025-10-21 20:10:34 +00:00
38 lines
1.1 KiB
Bash
Executable File
38 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
if [[ $# -eq 1 ]]; then
|
|
selected=$1
|
|
else
|
|
selected=$(project-finder ~/repos/ ~/Nextcloud/ ~/Obsidian/ | sk --height 16)
|
|
fi
|
|
|
|
if [[ -z $selected ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
selected_name=$(basename "$selected" | tr . _)
|
|
tmux_running=$(pgrep tmux)
|
|
|
|
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
|
|
# Create new session with nvim in first window, detached
|
|
tmux new-session -ds "$selected_name" -c "$selected" "${EDITOR:-vim} ."
|
|
# Create second window as plain terminal
|
|
tmux new-window -t "$selected_name:" -c "$selected"
|
|
# Select the first window (index 0)
|
|
tmux select-window -t "$selected_name:1"
|
|
# Attach to the session
|
|
tmux attach-session -t "$selected_name"
|
|
exit 0
|
|
fi
|
|
|
|
if ! tmux has-session -t="$selected_name" 2>/dev/null; then
|
|
# Create new session with nvim in first window, detached
|
|
tmux new-session -ds "$selected_name" -c "$selected" "${EDITOR:-vim} ."
|
|
# Create second window as plain terminal
|
|
tmux new-window -t "$selected_name:" -c "$selected"
|
|
# Select the first window (index 0)
|
|
tmux select-window -t "$selected_name:1"
|
|
fi
|
|
|
|
tmux switch-client -t "$selected_name"
|