-
-
Save cbaconnier/c07b8ca1f70807818419e1a88180b728 to your computer and use it in GitHub Desktop.
Run projects in kitty sessions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| SESSIONS_DIR="$HOME/.config/kitty/sessions" | |
| # Ensure sessions directory exists | |
| mkdir -p "$SESSIONS_DIR" | |
| # Check for --rofi flag | |
| USE_ROFI=false | |
| if [[ "$1" == "--rofi" ]]; then | |
| USE_ROFI=true | |
| shift # Remove --rofi from arguments | |
| fi | |
| # Check direct access `$ <script> ~/some/path/to/project` | |
| if [[ $# -eq 1 ]]; then | |
| selected=$1 | |
| else | |
| items=$(find ~/Projects -maxdepth 2 -mindepth 1 -type d) | |
| items+=`echo -e "\n/tmp"` | |
| if [[ "$USE_ROFI" == "true" ]]; then | |
| selected=$(echo "$items" | rofi -dmenu -config ~/.config/rofi/config-long.rasi) | |
| else | |
| selected=$(echo "$items" | fzf) | |
| fi | |
| fi | |
| # Exit if no selection made (user cancelled) | |
| if [[ -z "$selected" ]]; then | |
| exit 0 | |
| fi | |
| # Create unique session name using path structure | |
| # Replace slashes and dots with underscores, remove home prefix | |
| # ~/Some/Path/to-project => Some_Path_to-project.kitty-session | |
| session_name=$(echo "$selected" | sed "s|$HOME/||" | sed 's|[/\.]|_|g') | |
| session_file="$SESSIONS_DIR/${session_name}.kitty-session" | |
| # If session file doesn't exist, create it | |
| if [[ ! -f "$session_file" ]]; then | |
| { | |
| echo "# vim: ft=conf" | |
| echo "" | |
| echo "new_tab nvim" | |
| echo "cd $(printf '%q' "$selected")" | |
| echo "launch --hold nvim" | |
| echo "" | |
| echo "new_tab git" | |
| echo "cd $(printf '%q' "$selected")" | |
| echo "launch --hold lazygit" | |
| echo "" | |
| echo "new_tab shell" | |
| echo "cd $(printf '%q' "$selected")" | |
| echo "launch zsh" | |
| echo "" | |
| echo "#################### REMOVE ME -- START" | |
| echo "new_tab session-config" | |
| echo "cd $HOME/.config/kitty/sessions/" | |
| echo "launch nvim $(printf '%q' "$session_file")" | |
| echo "#################### REMOVE ME -- END" | |
| } > "$session_file" | |
| fi | |
| kitty --session "$session_file" > /dev/null 2>&1 & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment