Added tab-completion to checkver
This commit is contained in:
parent
b504e354a1
commit
5bb44a6926
|
@ -2,6 +2,8 @@
|
|||
SCRIPT_DIR=${SCRIPT_DIR:-"$( cd -- "$( dirname -- "$0" )" &> /dev/null && pwd )"}
|
||||
|
||||
set -e
|
||||
BASE_NAME="${0##*/}"
|
||||
SCRIPT_NAME="${SCRIPT_DIR}/${BASE_NAME}"
|
||||
|
||||
# Function to compare semantic versions
|
||||
compare_major_version() {
|
||||
|
@ -20,7 +22,7 @@ if [[ "${1}" =~ ^(-h|--help$) ]]; then
|
|||
"Query runtipi's current version and compares with what is available online" \
|
||||
"" \
|
||||
"Usage:" \
|
||||
" ${0##*/} -h | --help | [next] [<version>] " \
|
||||
" ${BASE_NAME} -h | --help | [next] [<version>] " \
|
||||
"" \
|
||||
"Arguments:" \
|
||||
" -h | --help Display usage" \
|
||||
|
@ -36,7 +38,51 @@ if [[ "${1}" =~ ^(-h|--help$) ]]; then
|
|||
" major versions do not match"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# --- tab completion ---
|
||||
completion_bash() {
|
||||
cat <<EOF
|
||||
_runtipi_checkver()
|
||||
{
|
||||
local cur prev opts
|
||||
COMPREPLY=()
|
||||
cur="\${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
||||
opts="next --help -h"
|
||||
|
||||
case "\${prev}" in
|
||||
next)
|
||||
COMPREPLY=( \$(compgen -W "\$("${SCRIPT_NAME}" --next)" -- \${cur}) )
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=( \$(compgen -W "\${opts}" -- \${cur}) )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
complete -F _runtipi_checkver ${BASE_NAME}
|
||||
EOF
|
||||
}
|
||||
|
||||
completion_zsh() {
|
||||
cat <<EOF
|
||||
_runtipi_checkver() {
|
||||
_values "version" next --help -h
|
||||
}
|
||||
compdef _runtipi_checkver ${BASE_NAME}
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ "$1" == "completion" ]; then
|
||||
if [ "$2" == "bash" ]; then
|
||||
completion_bash
|
||||
elif [ "$2" == "zsh" ]; then
|
||||
completion_zsh
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Get Current Version of Runtipi
|
||||
runtipi_path=${RUNTIPI_DIR:-"$(cd -- "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"}
|
||||
current_version="$1"
|
||||
|
@ -97,3 +143,4 @@ elif [ "$next_tag" != "$current_version" ]; then
|
|||
compare_major_version "$next_tag" "$current_version"
|
||||
fi
|
||||
|
||||
# vim: set ft=sh expandtab tabstop=4 shiftwidth=4:
|
Loading…
Reference in New Issue