Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions contrib/bash-completion/jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -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}))
Expand Down