From 7b30a29ed57912557e045c6af4f92960de40743e Mon Sep 17 00:00:00 2001 From: Gonzalo Martinez Lema Date: Fri, 16 Feb 2024 19:06:24 +0100 Subject: [PATCH] Fall back to default completion after first argument --- bin/city-completion | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/bin/city-completion b/bin/city-completion index 5cba0bf1d..189e0b107 100644 --- a/bin/city-completion +++ b/bin/city-completion @@ -1,15 +1,19 @@ #/usr/bin/env bash _city_completions () { - for fullpath in `ls $ICTDIR/invisible_cities/cities/*.py`; do - cityname=$(basename $fullpath) - if [[ $cityname == *"test"* ]]; then continue; fi - if [[ $cityname == *"components"* ]]; then continue; fi - if [[ $cityname == "__"* ]]; then continue; fi - if [[ $cityname == *"~" ]]; then continue; fi - cityname=${cityname/.py/} - COMPREPLY+=("$cityname") - done + PREV_WORD=${COMP_WORDS[COMP_CWORD-1]} + + if [[ ${PREV_WORD} == "city" ]]; then + for fullpath in `ls $ICTDIR/invisible_cities/cities/*.py`; do + cityname=$(basename $fullpath) + if [[ $cityname == *"test"* ]]; then continue; fi + if [[ $cityname == *"components"* ]]; then continue; fi + if [[ $cityname == "__"* ]]; then continue; fi + if [[ $cityname == *"~" ]]; then continue; fi + cityname=${cityname/.py/} + COMPREPLY+=("$cityname") + done + fi } -complete -F _city_completions city \ No newline at end of file +complete -o default -F _city_completions city