From dccf390820bc7c58d617c45b4fe55d00ff29c6d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Thu, 4 Sep 2014 11:55:21 +0200 Subject: [PATCH] Add tab-completion support --- README.md | 4 +++- completion.sh | 22 ++++++++++++++++++++++ install.sh | 4 ++++ scripts/example.sh | 1 + 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 completion.sh diff --git a/README.md b/README.md index 4247df0..be78bff 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ ### INSTALLATION Clone and run as root `install.sh`, or edit `install.sh` to choose -locations in user-space. +locations in user-space. +Close and reopen your terminal to make completion available, or execute +`. /etc/bash_completion.d/love-release` ### SYNOPSIS `love-release.sh [-adlmw] [-n project_name] [-r release_dir] [-v love_version] [FILES...]` diff --git a/completion.sh b/completion.sh new file mode 100644 index 0000000..67c7b70 --- /dev/null +++ b/completion.sh @@ -0,0 +1,22 @@ +# love-release Bash completion + +_love-release() +{ + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="-l" + opts="$opts -w --win-icon" + opts="$opts -d --deb-package-version --deb-maintainer-name --maintainer-email --deb-package-name" + opts="$opts -a --activity --apk-package-version --apk-maintainer-name --apk-package-name --update-android" + opts="$opts -m --osx-icon --osx-maintainer-name" + opts="$opts -h -n -r -v -x --config --homepage --description --clean --help" + + if [[ ${cur} == -* ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi +} +complete -F _love-release love-release + diff --git a/install.sh b/install.sh index 4bd8787..b1b2ded 100755 --- a/install.sh +++ b/install.sh @@ -10,6 +10,7 @@ echo "Installing..." BINARY_DIR=/usr/bin INSTALL_DIR=/usr/share/love-release MANPAGE_DIR=/usr/share/man/man1 +COMPLETION_DIR=/etc/bash_completion.d SED_ARG=$(echo "$INSTALL_DIR" | sed -e 's/[\/&]/\\&/g') mkdir -p "$BINARY_DIR" @@ -25,5 +26,8 @@ mkdir -p "$MANPAGE_DIR" sed -e "s/scripts/$SED_ARG\/scripts/g" -e "s/config.ini/$SED_ARG\/config.ini/g" love-release.1 > "$MANPAGE_DIR"/love-release.1 gzip -9 -f "$MANPAGE_DIR"/love-release.1 +mkdir -p "COMPLETION_DIR" +cp ./completion.sh "$COMPLETION_DIR"/love-release + echo "Done !" diff --git a/scripts/example.sh b/scripts/example.sh index b700e3d..6fad307 100644 --- a/scripts/example.sh +++ b/scripts/example.sh @@ -25,6 +25,7 @@ # - a dot "." if it has an optional argument # - a colon ":" if it requires an argument # If you need options that might conflict by their names with already defined options, please prefix them. +# If you want automatic completion to be available, add them to completion.sh SCRIPT_ARGS="q; wer: ty. uiop $SCRIPT_ARGS" # If some options require a file or a directory as argument,