From 485f4d82fc7652af0c567a0ced4831d24d87bdd4 Mon Sep 17 00:00:00 2001 From: Steffen Hemer Date: Wed, 12 Nov 2025 14:58:24 +0100 Subject: [PATCH 1/4] bash-completion: Add initial draft All commands, options, and command parameters should be completed correctly. Some option parameter won't complete. Signed-off-by: Steffen Hemer --- partup-completion.bash | 124 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 partup-completion.bash diff --git a/partup-completion.bash b/partup-completion.bash new file mode 100644 index 00000000..456ede6c --- /dev/null +++ b/partup-completion.bash @@ -0,0 +1,124 @@ +#!/usr/bin/env bash + +partup_commands="install package show version" +help_options="-h --help" +app_options="-q --quiet -d --debug -D --debug-domains" +install_options="-s --skip-checksums" +package_options="-f --force -C --directory" +show_options="-s --size" + +function exists_in_list() +{ + LIST=$1 + DELIMITER=$2 + VALUE=$3 + [[ "$LIST" =~ ($DELIMITER|^)$VALUE($DELIMITER|$) ]] +} + +function add_command_help() +{ + if [[ ${previous} == ${command} ]] ; then + # only add help if we are first after command + COMPREPLY+=( $(compgen -W "${help_options}" -- ${current}) ) + fi + if exists_in_list "${help_options}" " " "${previous}" ; then + # if we have choosen help option, nothing should follow + COMPREPLY=() + return 1 + fi + return 0 +} + + +_partup_completions() +{ + local current="" + local previous="" + local command="" + + if (( ${COMP_CWORD} > 0 )) ; then + current="${COMP_WORDS[COMP_CWORD]}" + + if (( ${COMP_CWORD} > 1 )) ; then + # iterate over all COMP_WORDS + for s in "${COMP_WORDS[@]:1}"; do + if exists_in_list "${partup_commands}" " " "${s}" ; then + command="${s}" + fi + done + previous="${COMP_WORDS[COMP_CWORD - 1]}" + fi + fi + + if [[ -z ${command} ]] ; then + add_command_help ${command} ${current} ${previous} || return 0 + COMPREPLY+=( $(compgen -W "${partup_commands} ${app_options}" -- ${current}) ) + return 0 + fi + + # we may have things like "partup --debug install ..." + + if [[ ${command} == install ]] ; then + add_command_help ${command} ${current} ${previous} || return 0 + + COMPREPLY+=( $(compgen -W "${install_options} ${app_options}" -- ${current}) ) + + # PACKAGE + COMPREPLY+=( $(compgen -f -o plusdirs -X '!*.partup' -- ${current}) ) + + # DEVICE -> if previous ends with partup, complete only from /dev + if [[ ${previous} == *.partup ]] ; then + if [[ -z ${current} ]] ; then + COMPREPLY=( '/dev' ) + return 0 + else + COMPREPLY+=( $(compgen -f -o plusdirs -- ${current} ) ) + fi + fi + + # don't allow options after dev + if [[ ${previous} == /dev/* ]] ; then + COMPREPLY=() + fi + + return 0 + fi + + if [[ ${command} == package ]] ; then + add_command_help ${command} ${current} ${previous} || return 0 + + COMPREPLY+=( $(compgen -W "${package_options} ${app_options}" -- ${current}) ) + + # -C, --directory=DIR + # PACKAGE FILES… + + if exists_in_list "${package_options}" " " ${previous} ; then + #if output is previous, a file must follow + COMPREPLY=( $(compgen -f -- ${current}) ) + fi + + return 0 + fi + + if [[ ${command} == show ]] ; then + add_command_help ${command} ${current} ${previous} || return 0 + + COMPREPLY+=( $(compgen -W "${show_options} ${app_options}" -- ${current}) ) + + # PACKAGE - if we do not already have one, complete available partup files + if [[ ${previous} != *.partup ]] ; then + COMPREPLY+=( $(compgen -f -o plusdirs -X '!*.partup' -- ${current}) ) + fi + + return 0 + fi + + if [[ ${command} == version ]] ; then + COMPREPLY=() + return 0 + fi + + return 1 +} + +complete -o filenames -F _partup_completions partup From 49d7b435332ace799474531481efc3b6b3900ab9 Mon Sep 17 00:00:00 2001 From: Steffen Hemer Date: Sat, 22 Aug 2026 11:02:19 +0200 Subject: [PATCH 2/4] debian: Package bash-completion script Signed-off-by: Steffen Hemer --- debian/control | 3 ++- debian/partup.bash-completion | 1 + debian/rules | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 debian/partup.bash-completion diff --git a/debian/control b/debian/control index a6baf3fc..ad7cd751 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,8 @@ Build-Depends: libyaml-dev, libparted-dev, util-linux, - meson + meson, + bash-completion Standards-Version: 4.7.2 Homepage: https://github.com/phytec/partup Vcs-Git: https://github.com/phytec/partup.git diff --git a/debian/partup.bash-completion b/debian/partup.bash-completion new file mode 100644 index 00000000..c6b068de --- /dev/null +++ b/debian/partup.bash-completion @@ -0,0 +1 @@ +partup-completion.bash diff --git a/debian/rules b/debian/rules index 71a79be6..79d7d8c3 100755 --- a/debian/rules +++ b/debian/rules @@ -3,7 +3,7 @@ export DH_VERBOSE=1 %: - dh $@ + dh $@ --with bash-completion override_dh_auto_configure: rm -rf build From 9f735e514f8e2edec23ee6626bc044abc3103532 Mon Sep 17 00:00:00 2001 From: Steffen Hemer Date: Tue, 1 Sep 2026 10:41:34 +0200 Subject: [PATCH 3/4] gitignore: Add Debian package build artefacts When test-building the package locally, these otherwise float the untracked files. Signed-off-by: Steffen Hemer --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 33258294..cf117cae 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,9 @@ env/ tags plan.md +debian/.debhelper/ +debian/partup/ +debian/files +debian/debhelper-build-stamp +debian/partup.debhelper.log +debian/partup.substvars From 3a9e25613937017b04d68f25ab4aae9ff43b4d97 Mon Sep 17 00:00:00 2001 From: Steffen Hemer Date: Fri, 23 Oct 2026 13:02:13 +0200 Subject: [PATCH 4/4] bash-completion: Replace version command with respective option Version command is deprecated, so don't complete it anymore. Add the version options instead (as a 'help_option' so no completion follows which is not exactly how the parsing of partup works...). Signed-off-by: Steffen Hemer --- partup-completion.bash | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/partup-completion.bash b/partup-completion.bash index 456ede6c..80dd36dd 100644 --- a/partup-completion.bash +++ b/partup-completion.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash -partup_commands="install package show version" -help_options="-h --help" +partup_commands="install package show" +help_options="-h --help -V --version" app_options="-q --quiet -d --debug -D --debug-domains" install_options="-s --skip-checksums" package_options="-f --force -C --directory" @@ -113,11 +113,6 @@ _partup_completions() return 0 fi - if [[ ${command} == version ]] ; then - COMPREPLY=() - return 0 - fi - return 1 }