From fdea8c4e88188d841afa6d4a048da9f47ace09fd Mon Sep 17 00:00:00 2001 From: Gabriel Moreau <gabriel.moreau@univ-grenoble-alpes.fr> Date: Tue, 18 Jan 2022 11:22:46 +0100 Subject: [PATCH] Better completion of computer name and log filename --- tssh | 2 +- tssh.bash_completion | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tssh b/tssh index 747c635..598254c 100644 --- a/tssh +++ b/tssh @@ -7,7 +7,7 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin export LANG=C -VERSION='0.4.9' +VERSION='0.4.10' function usage() { cat <<END_USAGE diff --git a/tssh.bash_completion b/tssh.bash_completion index 960f87c..7ad33ad 100644 --- a/tssh.bash_completion +++ b/tssh.bash_completion @@ -9,11 +9,23 @@ _tssh() { cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - if [[ "$cur" == '-*' || $COMP_CWORD -gt 1 ]] + case $prev in + -l|--log) + COMPREPLY=($(compgen -f -- "$cur"|grep -v -f <(compgen -d --|sed -e 's/^/^/;s/$/\$/;'); compgen -d -S / -- "$cur")) + return 0 + ;; + esac + + if [[ "$cur" == '-*' ]] then - COMPREPLY=($(compgen -W "$(tssh -h|grep '^ tssh'|sed -e 's/[\[]/\n/g;'|grep -- '^-'|cut -f 1 -d ']'|cut -f 1 -d ' '|sed -e 's/|/ /g;'|xargs echo -n)" -- "$cur")) + COMPREPLY=($(compgen -W "$(tssh --help|grep '^ tssh'|sed -e 's/[\[]/\n/g;'|grep -- '^-'|cut -f 1 -d ']'|cut -f 1 -d ' '|sed -e 's/|/ /g;'|xargs echo -n)" -- "$cur")) + #elif [[ $COMP_CWORD -gt 1 && "$prev" != '-*' ]] + #then + # COMPREPLY=($(compgen -W "$(tr '\n' ' '<$HOME/.csshrc|sed -e 's/=/ /g;s/[[:space:]][[:space:]]*/ /g')" -- "$cur")) else - COMPREPLY=($(compgen -W "$(tssh -h|grep '^ tssh'|sed -e 's/[\[]/\n/g;'|grep -- '^-'|cut -f 1 -d ']'|cut -f 1 -d ' '|sed -e 's/|/ /g;'|xargs echo -n)" -- "$cur")) + COMPREPLY=($(compgen -W "$((tssh --help|grep '^ tssh'|sed -e 's/[\[]/\n/g;'|grep -- '^-'|cut -f 1 -d ']'|cut -f 1 -d ' '|sed -e 's/|/ /g;'; + tr '\n' ' '<$HOME/.csshrc|sed -e 's/=/ /g;s/[[:space:]][[:space:]]*/ /g' + ) | xargs echo -n)" -- "$cur")) fi } && complete -F _tssh tssh -- GitLab