Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/system-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Build and install application
run: |
meson setup build --buildtype=release
meson install -C build
sudo meson install -C build
- name: Setup loopdev and symlink
run: |
dd if=/dev/zero of=loop-file bs=1M count=100
Expand Down
3 changes: 2 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Martin Schwan <m.schwan@phytec.de>
Contributors
============

Leonard Anderweit <l.anderweit@phytec.de>
* Leonard Anderweit <l.anderweit@phytec.de>
* Steffen Hemer <s.hemer@phytec.de>
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
- Add a FAQ section to the documentation explaining the ``Filesystem has
unsupported feature(s)`` error of ``resize2fs``, caused by the ext4
``orphan_file`` feature and old e2fsprogs versions.
- Add a Bash completion script, which completes commands, options and their
arguments. It is installed together with partup.

.. rubric:: Contributors

`Steffen Hemer <s.hemer@phytec.de>`__,
`Martin Schwan <https://github.com/mschwan-phytec>`__

.. _release-4.0.0:

Expand Down
164 changes: 164 additions & 0 deletions completions/bash/partup
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Bash completion for partup

_partup_commands="install package show"
_partup_help_options="-h --help -V --version"
_partup_app_options="-q --quiet -d --debug -D --debug-domains"
_partup_install_options="-s --skip-checksums"
_partup_package_options="-f --force -C --directory"
_partup_show_options="-s --size"

_partup_in_list()
{
local list=$1
local value=$2

[[ " ${list} " == *" ${value} "* ]]
}

_partup_complete_files()
{
local pattern=$1
local current=$2

if [[ -n ${pattern} ]]; then
mapfile -t -O "${#COMPREPLY[@]}" COMPREPLY < <(compgen -f -X "!${pattern}" -- "${current}")
mapfile -t -O "${#COMPREPLY[@]}" COMPREPLY < <(compgen -d -- "${current}")
else
mapfile -t -O "${#COMPREPLY[@]}" COMPREPLY < <(compgen -f -- "${current}")
fi
}

_partup_completions()
{
local current="${COMP_WORDS[COMP_CWORD]}"
local previous=""
local command=""
local -a positionals=()
local i word skip=0

COMPREPLY=()

if (( COMP_CWORD > 0 )); then
previous="${COMP_WORDS[COMP_CWORD - 1]}"
fi

# Find the command and the positional arguments in front of the cursor.
# Arguments of options that take a value are skipped.
for (( i = 1; i < COMP_CWORD; i++ )); do
word="${COMP_WORDS[i]}"

if (( skip )); then
skip=0
continue
fi

case "${word}" in
-D|--debug-domains|-C|--directory)
skip=1
continue
;;
-*)
continue
;;
esac

if [[ -z ${command} ]] && _partup_in_list "${_partup_commands}" "${word}"; then
command="${word}"
else
positionals+=( "${word}" )
fi
done

# Complete the argument of an option that takes a value.
case "${previous}" in
-D|--debug-domains)
return 0
;;
-C|--directory)
if [[ ${command} == package ]]; then
mapfile -t COMPREPLY < <(compgen -d -- "${current}")
return 0
fi
;;
esac

case "${current}" in
--debug-domains=*)
return 0
;;
--directory=*)
if [[ ${command} == package ]]; then
mapfile -t COMPREPLY < <(compgen -d -P "--directory=" -- "${current#--directory=}")
return 0
fi
;;
esac

if [[ -z ${command} ]]; then
mapfile -t COMPREPLY < <(compgen -W "${_partup_help_options} ${_partup_commands} ${_partup_app_options}" -- "${current}")
return 0
fi

local options="${_partup_app_options}"

# Only offer help directly after the command
if (( ${#positionals[@]} == 0 )) && [[ ${previous} == "${command}" ]]; then
options+=" ${_partup_help_options}"
fi

case "${command}" in
install)
options+=" ${_partup_install_options}"
;;
package)
options+=" ${_partup_package_options}"
;;
show)
options+=" ${_partup_show_options}"
;;
esac

if [[ ${current} == -* ]]; then
mapfile -t COMPREPLY < <(compgen -W "${options}" -- "${current}")
return 0
fi

case "${command}" in
install)
# install PACKAGE DEVICE
case ${#positionals[@]} in
0)
_partup_complete_files "*.partup" "${current}"
;;
1)
mapfile -t COMPREPLY < <(compgen -f -- "${current:-/dev/}")
;;
esac
;;
package)
# package PACKAGE FILES...
if (( ${#positionals[@]} == 0 )); then
_partup_complete_files "*.partup" "${current}"
else
_partup_complete_files "" "${current}"
fi
;;
show)
# show PACKAGE
if (( ${#positionals[@]} == 0 )); then
_partup_complete_files "*.partup" "${current}"
fi
;;
esac

if [[ -z ${current} ]] && (( ${#COMPREPLY[@]} == 0 )); then
mapfile -t COMPREPLY < <(compgen -W "${options}" -- "${current}")
fi

return 0
}

complete -o filenames -F _partup_completions partup
1 change: 0 additions & 1 deletion debian/dirs

This file was deleted.

1 change: 0 additions & 1 deletion debian/partup.bash-completion

This file was deleted.

2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export DH_VERBOSE=1

%:
dh $@ --with bash-completion
dh $@

override_dh_auto_configure:
rm -rf build
Expand Down
13 changes: 13 additions & 0 deletions doc/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ version
.. deprecated:: 5.0.0
Use the global ``-V, --version`` option instead.

Shell Completion
----------------

partup ships a completion script for Bash. It completes commands, options and
their arguments, e.g. directories for ``--directory``, ``*.partup`` files for
the *PACKAGE* argument and device paths for the *DEVICE* argument.

The script is installed together with partup to the ``bash-completion``
directory of the installation prefix. To use it without installing partup,
source the script ``completions/bash/partup`` from the source tree::

source completions/bash/partup

Supported Output Devices
------------------------

Expand Down
15 changes: 15 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ exec = executable(
install : true
)

bash_completion_dep = dependency('bash-completion', required : false)
if bash_completion_dep.found()
bash_completion_dir = bash_completion_dep.get_variable(
'completionsdir',
pkgconfig_define : ['datadir', get_option('prefix') / get_option('datadir')]
)
else
bash_completion_dir = get_option('prefix') / get_option('datadir') / 'bash-completion' / 'completions'
endif

install_data(
'completions/bash/partup',
install_dir : bash_completion_dir
)

partup_dep = declare_dependency(
dependencies : deps,
include_directories : ['src'],
Expand Down
119 changes: 0 additions & 119 deletions partup-completion.bash

This file was deleted.

1 change: 1 addition & 0 deletions tools/debian-package/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install --yes \
bash-completion \
debhelper \
git \
meson \
Expand Down