Snapd installs bash completion files from snaps in
`/usr/share/bash-completion/completions` which in some distributions
is a read-only filesystem.
Instead of installing them in `/usr` we can install them within
`/var/lib/snapd` which should always be writable.
Because `/var/lib/snapd/desktop` is already in `XDG_DATA_DIRS`, we can
save the files there.
Because bash-completion 2.1 and prior do not support `XDG_DATA_DIRS`,
on older distributions, the legacy path
`/usr/share/bash-completion/completions` will still be used.
Add completion function for snap command for zsh. Most of heavy lifting is done
by go-flags and our completion helpers, this just glues everything together.
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Two small changes:
1. actually support tab completion of debug commands:
without this change completion of debug was broken, always
suggesting more debug commands
2. tag the argument of validate-seed as a file, and required
without this change, when giving it no argument it tried to
validate a file called "" which failed with a curious error
message. Also completion didn't know what to offer.
completion functions (and commands, which we treat the same way) are
documented as receiving three arguments. I hadn't noticed, as almost
nobody uses them because most everything you need is in the different
COMP_ variables, but python's argcomplete module uses it.
This fixes that, and adds a spread test just in case.
* data/completion: remove shebang and +x from etelpmoc.sh
The $(rev<<complete.sh) script doesn't need to be executable as it is
invoked directly via bash. It also doesn't need a shebang line for the
very same reason.
This silences the following rpmlint warning:
[ 108s] snapd.x86_64: W: non-executable-script /usr/lib/snapd/etelpmoc.sh 644 /bin/bash
[ 108s] This text file contains a shebang or is located in a path dedicated for
[ 108s] executables, but lacks the executable bits and cannot thus be executed. If
[ 108s] the file is meant to be an executable script, add the executable bits,
[ 108s] otherwise remove the shebang or move the file elsewhere.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
* data/complete,packaging: make complete scripts +x, with shebang
This undoes earlier patch but this is the best compromise I managed to
find. With this approach the scripts are executable (even though we
don't rely on that) and have a valid shebang. This makes both rpmlint
and shellcheck happy.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
* data/complete: match +x in the packaging with the tree
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
* data/complete,packaging: make complete scripts -x, sans shebang
The shebang conundrum was finally solved with a shellcheck specific
markup that identifies the shell type. This allows the scripts to be
shellcheck-clean, not executable and devoid of shebang. This allows
rpmlint to become happy again.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
This silences the following shellcheck warning:
In etelpmoc.sh line 90:
case "$opt" in
^-- SC2220: Invalid flags are not handled. Add a *) case.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
This silences the following shellcheck warning:
In etelpmoc.sh line 212:
printf "%s\n" "${COMPREPLY[@]}"
^-- SC1117: Backslash is literal in "\n". Prefer explicit escaping: "\\n".
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
This silences the following shellcheck warning:
In complete.sh line 119:
if [[ "$(which "$1")" =~ /snap/bin/ && ( -e "/var/lib/snapd/$etel" || -e "/$etel" ) ]]; then
^-- SC2230: which is non-standard. Use builtin 'command -v' instead.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
previously, if you were completing from the middle of a command,
things might get weird. For example,
$ snap install test- --devmode
^ you are here
if you hit tab there, without this change, you get a very helpful
“--devmode” replacing test-.
This is because we were just passing all the command off to go flags
for it to figure out, and it doesn't work that way.
Anyway, this fixes that.
This also modifies complete.sh to support this, as well as some minor
changes to dirs and snap to accommodate.
Symlinking the snippets is itself simple enough that I didn't think it
was worth creating an ad-hoc helper, so it's just a few lines glommed
onto the end of the existing wrapper funcs (and tests).
To be clear, I did write the helper, but between it being very few
lines of code, it needing to return enough information to the
caller to clean up behind it if something else went wrong, and
especially as the other user of that helper would be the aliases
and they don't have access to the AppInfo (which would be the
obvious thing to pass to such helpers), I decided against it.
How aliases are going to play into completion is still an open
question on the implementation side, which I need to look into soon,
but this is not that work.
Also make run-checks run shellcheck on the data completion scripts as
well as on tests/lib/*.sh. Includes making pinentry-fake.sh an actual
script (so shellcheck can check it too) instead of a here-document
inside another one.