Gitfed
bastien-mrq/sssh/ Commits/ f3ec2c9

feat: complétion bash et zsh

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

bastien-mrq 2026-08-13 09:28 commit f3ec2c9832d72d8a928ea856132091e79a8a3f44 parent 1220acdf3e97e2baad17ce44d57851aae84c0762
3 files changed +82 −1
M README.md +15 −1
A completions/_sssh +37 −0
A completions/sssh.bash +30 −0
README.md
diff --git a/README.md b/README.md index b7386b0..fb243e8 100644 --- a/README.md +++ b/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
diff --git a/completions/_sssh b/completions/_sssh new file mode 100644 index 0000000..ef34422 --- /dev/null +++ b/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
diff --git a/completions/sssh.bash b/completions/sssh.bash new file mode 100644 index 0000000..d8d6fe9 --- /dev/null +++ b/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