Skip to content

Instantly share code, notes, and snippets.

@nerflad
Last active August 4, 2025 20:42
Show Gist options
  • Select an option

  • Save nerflad/173b228ab269447b8bb1464ddafa7312 to your computer and use it in GitHub Desktop.

Select an option

Save nerflad/173b228ab269447b8bb1464ddafa7312 to your computer and use it in GitHub Desktop.
function x --wraps=exit --description 'alias x exit'
set -l currentSession (ps aux | grep (zellij list-sessions | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | grep current 2>/dev/null | awk -F' ' '{print $1}') 2>/dev/null | grep -v grep 2>/dev/null | awk -F' ' '{print $2}')
set -l zellijAttach (pgrep -f "zellij attach")
set -l zellijMain (pgrep -f "zellij" | head -n1)
[ -n "$zellijAttach" ] && kill -15 "$zellijAttach" && return 0
#↓ else: haven't detached from session yet
if contains "$currentSession" (pgrep zellij)
kill -15 "$zellijMain"
return 0
end
if ! contains (ps -o ppid -p $fish_pid | sed 's/^ //g') (pgrep zellij)
exit $argv
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment