From 94d782878c94b5bf4e0a373f8893da6e8454eec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radom=C3=ADr=20Bos=C3=A1k?= Date: Wed, 7 Jun 2017 23:24:08 +0200 Subject: [PATCH] WIP Separate job bash completion for environments Fixes #47 --- contrib/bash-completion/jenkins | 36 ++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/contrib/bash-completion/jenkins b/contrib/bash-completion/jenkins index fc85403..20b7d01 100755 --- a/contrib/bash-completion/jenkins +++ b/contrib/bash-completion/jenkins @@ -17,28 +17,58 @@ _jenkins() console \ changes \ -h \ + -e \ --help \ --host \ --username \ --password \ + --environment \ --version" + # figure out the environment + EXPECT_ENV=0 + ENV="DEFAULT" + for i in "${words[@]}" + do + if [[ "$EXPECT_ENV" == "1" ]]; then + ENV="$i" + EXPECT_ENV=0 + fi + if [[ "$i" == "-e" ]] || [[ "$i" == "--environment" ]]; then + EXPECT_ENV=1 + fi + done + + # figure out the config file + CONFIG_FILE= + if [ -r "$HOME/.jenkins-cli" ]; then + CONFIG_FILE="~/.jenkins-cli" + fi + if [ -r "$PWD/.jenkins-cli" ]; then + CONFIG_FILE="$PWD/.jenkins-cli" + fi + case $prev in jobs) opts="-h --help -a -p" ;; builds|start|info|configxml|setbranch|stop|console|changes) opts="-h --help" - # if the cached-jobs file exists suggest also job names CACHE_DIR=${XDG_CACHE_HOME:-~/.cache}"/python-jenkins-cli" - if [ -r $CACHE_DIR/job_cache ]; then - opts="$opts $(cat $CACHE_DIR/job_cache)" + if [ -r "$CACHE_DIR/job_cache_$ENV" ]; then + opts="$opts $(cat $CACHE_DIR/job_cache_$ENV)" fi ;; queue|building) opts="-h --help" ;; + -e|--environment) + if [ -n "$CONFIG_FILE" ]; then + opts="$(grep -e '\[.*\]' ~/.jenkins-cli | tr -d '[]')" + else + opts="" + fi esac COMPREPLY=($(compgen -W "${opts}" -- ${cur}))