Created
June 22, 2025 12:10
-
-
Save jtsagata/56f4965119f7ce60fc53ffe176070e0d to your computer and use it in GitHub Desktop.
zellyj startup
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 | |
function zedit() { | |
zellij edit --floating "$*" | |
} | |
function zrun() { | |
NAME=$(echo "$1" | cut -d ' ' -f1) | |
zellij run --name "$NAME" --floating -- zsh -i -c "$*" | |
} | |
function zcat() { | |
NAME=$(echo "$1" | cut -d ' ' -f1) | |
zellij run --name "$NAME" --floating --width 80 -- zsh -c "bat $* && zellij action close-pane" | |
} | |
function zkill() { | |
gum confirm "Are you sure you want to kill all Zellij sessions?" || return 0 | |
ctrem "[green]Killing all Zellij sessions...[/]" | |
zellij kill-all-sessions --yes | |
zellij delete-all-sessions --force --yes | |
} |
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 zsh | |
# Get the SHELL NAME | |
if [ -n "$BASH" ]; then | |
export CRUSTY_SHELL="bash" | |
elif [ -n "$ZSH_NAME" ]; then | |
export CRUSTY_SHELL="zsh" | |
elif [ -n "$FISH_VERSION" ]; then | |
export CRUSTY_SHELL="fish" | |
fi | |
# Get the terminal | |
if [ -z "${TERM_PROGRAM}" ]; then | |
if [ "${TERMINAL_EMULATOR}" = "JetBrains-JediTerm" ]; then | |
export TERM_PROGRAM="JetBrains" | |
elif [ -n "$ALACRITTY_WINDOW_ID" ]; then | |
# Also cosmic terminal | |
export TERM_PROGRAM="alacrity" | |
elif [ -n "$INSIDE_NAUTILUS_PYTHON" ]; then | |
export TERM_PROGRAM="nautilus" | |
else | |
export TERM_PROGRAM="xterm" | |
fi | |
fi | |
function new_session() { | |
name=$(gum input --placeholder "What is the name of the new session?") | |
if [[ -z "$name" ]]; then | |
zellij | |
else | |
zellij --session "$name" | |
fi | |
} | |
function zkill() { | |
gum confirm "Are you sure you want to kill all Zellij sessions?" || return 0 | |
ctrem "[green]Killing all Zellij sessions...[/]" | |
zellij kill-all-sessions --yes | |
zellij delete-all-sessions --force --yes | |
} | |
function select_session() { | |
local sessions | |
sessions=$(zellij list-sessions 2>/dev/null) | |
sessions=$(echo -e "${sessions}\nNew session\nKill All Sessions\n") | |
gum style --foreground 50 --border-foreground 30 --border rounded \ | |
--align center --width 50 --margin "0 1" --padding "0 4" \ | |
'Choose a Zellij Session to attach to:' | |
selected=$(echo "$sessions" | gum choose --header 'Choose session:' | cut -d ' ' -f 1) | |
if [[ "$selected" == "New" ]]; then | |
new_session | |
exit 0 | |
elif [[ "$selected" == "Kill" ]]; then | |
zkill | |
new_session | |
exit 0 | |
fi | |
zellij attach "$selected" | |
} | |
function start_zellij() { | |
local sessions | |
sessions=$(zellij list-sessions 2>/dev/null) | |
if [[ "$sessions" == "" ]]; then | |
ctrem "[green]No existing Zellij sessions found. Starting a new session. [/]" | |
zellij --session "default" | |
exit 0 | |
else | |
select_session | |
fi | |
} | |
if [[ "$TERM_PROGRAM" != "vscode" && "$TERM_PROGRAM" != "JetBrains" ]]; then | |
start_zellij | |
else | |
ctrem "[green]Zellij[/] is not supported in [green]VSCode[/] or [green]JetBrains IDEs[/]." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment