Created
February 11, 2025 21:13
-
-
Save alextorma/b4cdb7bdee2898a74c0103c29561a0e8 to your computer and use it in GitHub Desktop.
Zellij ZSH Tab Completion Session Name Patch
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
--- comp.zsh 2025-02-10 22:36:57 | |
+++ session_completion.zsh 2025-02-11 16:11:57 | |
@@ -2,6 +2,17 @@ | |
autoload -U is-at-least | |
+_zellij_sessions() { | |
+ local line sessions desc; sessions=("${(@f)$(zellij ls -n)}") | |
+ local -a session_names_with_desc | |
+ for line in "${sessions[@]}"; do | |
+ session_name=${line%% *} | |
+ desc=${line#* } | |
+ session_names_with_desc+=("$session_name:$desc") | |
+ done | |
+ _describe -t sessions 'active session' session_names_with_desc | |
+} | |
+ | |
_zellij() { | |
typeset -A opt_args | |
typeset -a _arguments_options | |
@@ -122,7 +133,7 @@ | |
'--help[Print help information]' \ | |
&& ret=0 | |
;; | |
-(attach) | |
+(attach|a) | |
_arguments "${_arguments_options[@]}" \ | |
'*--index=[Number of the session index in the active sessions ordered creation date]:INDEX: ' \ | |
'*-c[Create a session if one does not exist]' \ | |
@@ -133,7 +144,7 @@ | |
'*--force-run-commands[If resurrecting a dead session, immediately run all its commands on startup]' \ | |
'-h[Print help information]' \ | |
'--help[Print help information]' \ | |
-'::session-name -- Name of the session to attach to:' \ | |
+'::session-name:_zellij_sessions' \ | |
":: :_zellij__attach_commands" \ | |
"*::: :->attach" \ | |
&& ret=0 | |
@@ -201,20 +212,20 @@ | |
;; | |
esac | |
;; | |
-(kill-session) | |
+(kill-session|k) | |
_arguments "${_arguments_options[@]}" \ | |
'-h[Print help information]' \ | |
'--help[Print help information]' \ | |
-'::target-session -- Name of target session:' \ | |
+'::target-session:_zellij_sessions' \ | |
&& ret=0 | |
;; | |
-(delete-session) | |
+(delete-session|d) | |
_arguments "${_arguments_options[@]}" \ | |
'*-f[Kill the session if it'\''s running before deleting it]' \ | |
'*--force[Kill the session if it'\''s running before deleting it]' \ | |
'-h[Print help information]' \ | |
'--help[Print help information]' \ | |
-'::target-session -- Name of target session:' \ | |
+'::target-session:_zellij_sessions' \ | |
&& ret=0 | |
;; | |
(kill-all-sessions) | |
@@ -1229,7 +1240,7 @@ | |
_describe -t commands 'zellij action write-chars commands' commands "$@" | |
} | |
-_zellij "$@" | |
+compdef _zellij zellij | |
function zr () { zellij run --name "$*" -- zsh -ic "$*";} | |
function zrf () { zellij run --name "$*" --floating -- zsh -ic "$*";} | |
function zri () { zellij run --name "$*" --in-place -- zsh -ic "$*";} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you saved Zellij's ZSH completions to a file your .zshrc sources, this patch can be applied to it to make completions of session names work with everything else.
Alternatively, you can modify these completions on the fly with the following command(s):
For example, in my .zshrc I have the following line:
Credit to @Lockszmith-GH for the initial help in getting these completions sourced correctly!