feat: complétion bash et zsh
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
3 files changed
+82 −1
M
README.md
+15 −1
A
completions/_sssh
+37 −0
A
completions/sssh.bash
+30 −0
README.md
@@ -23,7 +23,21 @@ go build -o sssh .
mv sssh ~/.local/bin/ # ou n'importe où dans ton PATH
```
-Complétion fish : `cp completions/sssh.fish ~/.config/fish/completions/`
+### Complétion shell
+
+```sh
+# fish
+cp completions/sssh.fish ~/.config/fish/completions/
+
+# bash — dans ~/.bashrc :
+source /chemin/vers/sssh/completions/sssh.bash
+
+# zsh — dans un répertoire du fpath, avant compinit :
+mkdir -p ~/.zsh/completions && cp completions/_sssh ~/.zsh/completions/
+# puis dans ~/.zshrc : fpath=(~/.zsh/completions $fpath)
+```
+
+La complétion propose les noms de hosts (y compris ceux de `~/.ssh/config`) et les sous-commandes.
## Usage
completions/_sssh
@@ -0,0 +1,37 @@
+#compdef sssh
+# Complétion zsh pour sssh — à copier dans un répertoire du fpath, ex. :
+# mkdir -p ~/.zsh/completions && cp _sssh ~/.zsh/completions/
+# # puis dans ~/.zshrc, avant compinit :
+# fpath=(~/.zsh/completions $fpath)
+
+_sssh() {
+ local -a names subcmds
+ names=(${(f)"$(sssh list --names 2>/dev/null)"})
+ subcmds=(
+ 'add:Ajouter un host'
+ 'edit:Éditer un host'
+ 'rm:Supprimer un host'
+ 'list:Lister les hosts'
+ 'export:Exporter hosts.toml'
+ 'import:Importer un hosts.toml'
+ 'help:Aide'
+ 'version:Version'
+ )
+
+ if (( CURRENT == 2 )); then
+ _describe -t hosts 'host SSH' names
+ _describe -t commands 'commande' subcmds
+ return
+ fi
+
+ case $words[2] in
+ edit|rm)
+ (( CURRENT == 3 )) && _describe -t hosts 'host SSH' names
+ ;;
+ import|export)
+ _files
+ ;;
+ esac
+}
+
+_sssh "$@"
completions/sssh.bash
@@ -0,0 +1,30 @@
+# Complétion bash pour sssh — à sourcer depuis ~/.bashrc :
+# source /chemin/vers/completions/sssh.bash
+# ou à copier dans ~/.local/share/bash-completion/completions/sssh
+
+_sssh() {
+ local cur cmd
+ cur="${COMP_WORDS[COMP_CWORD]}"
+
+ if [[ $COMP_CWORD -eq 1 ]]; then
+ local names subcmds
+ names="$(sssh list --names 2>/dev/null)"
+ subcmds="add edit rm list export import help version"
+ COMPREPLY=($(compgen -W "$names $subcmds" -- "$cur"))
+ return
+ fi
+
+ cmd="${COMP_WORDS[1]}"
+ case "$cmd" in
+ edit|rm)
+ if [[ $COMP_CWORD -eq 2 ]]; then
+ COMPREPLY=($(compgen -W "$(sssh list --names 2>/dev/null)" -- "$cur"))
+ fi
+ ;;
+ import|export)
+ COMPREPLY=($(compgen -f -- "$cur"))
+ ;;
+ esac
+}
+
+complete -F _sssh sssh