34 Commits

Author SHA1 Message Date
Valentin David
a1cb7ae352 many: Install bash completion files in writable directory
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.
2022-06-03 10:38:37 +02:00
Maciej Borzecki
188cab443e data: move bash/zsh completion support to separate directories
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-05-05 09:45:46 +02:00
Maciej Borzecki
ac75466c53 data/completion: add completion for zsh
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>
2020-04-29 21:07:36 +02:00
James Henstridge
df14d68e0a data: allow completion of "snap routine" subcommands 2019-11-01 19:59:55 +08:00
John R. Lenton
313669bb53 cmd/snap, data/completion: improve completion for 'snap debug'
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.
2019-08-02 13:49:12 +01:00
John R. Lenton
f15432a737 data/completion: pass documented arguments to completion functions
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.
2018-11-12 15:55:19 +00:00
Zygmunt Krynicki
0f06f20dc4 Merge pull request #5355 from zyga/tweak/shellcheck-complete-scripts
data/complete: fix three out of four shellcheck warnings in data/complete
2018-06-21 14:19:09 +02:00
Zygmunt Krynicki
b075a8d4a3 data/complete: match both {,/var/lib/snapd}/snap/bin
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2018-06-21 13:48:53 +02:00
Zygmunt Krynicki
ac08bf465e data/completion: fix inconsistency in +x and shebang (#5353)
* 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>
2018-06-21 11:34:46 +02:00
Zygmunt Krynicki
edd5dd4cde data/complete: explicitly ignore unknown command line options
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>
2018-06-20 11:10:54 +02:00
Zygmunt Krynicki
9a77ec1a84 data/complete: escape backslash for \n
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>
2018-06-20 11:10:54 +02:00
Zygmunt Krynicki
0573e7b349 data/complete: prefer command -v over which
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>
2018-06-20 11:10:54 +02:00
John R. Lenton
2da547718e data/completion: small tweak to snap completion snippet
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.
2017-09-18 18:45:39 +01:00
John Lenton
eac3d5deac wrappers: symlink completion snippets when symlinking binaries (#3724)
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.
2017-08-16 10:49:50 +01:00
John R. Lenton
5f0aeae640 many: cover *all* standalone shell scripts with shellcheck
This might be getting out of hand. I blame ogra.
2017-05-22 17:40:43 +01:00
John R. Lenton
c5733ff47f many: make shell scripts shellcheck-clean
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.
2017-05-22 14:46:25 +01:00
Zygmunt Krynicki
35bc91540d Merge pull request #3214 from chipaca/complete-interfaces
cmd/snap: iterate interface tab completion
2017-05-08 14:34:50 +02:00
John R. Lenton
e75170d89c address issues from review 2017-05-04 11:54:26 +01:00
John R. Lenton
35d048ab4d fix for tests: debian does not have /snap/bin in secure_path so sudo
needs PATH=$PATH to work properly. Also, use 'slow send'
everywhere. Finally, add a comment about not filtering the 'bounced'
completion.
2017-04-28 18:38:54 +01:00
John R. Lenton
a82ba0dbda typo 2017-04-27 13:59:10 +01:00
John R. Lenton
8a60343a82 address review feedback, add a lot of comments :-), call shellcheck on the completion scripts, fix a bug in compopt 2017-04-27 13:32:09 +01:00
John R. Lenton
6dcbcded52 some more filtering / validatiion 2017-04-26 11:11:24 +01:00
John R. Lenton
b02ba90d15 address review feedback 2017-04-25 13:05:23 +01:00
John R. Lenton
46ea55c7c7 address review comments; some tweaks 2017-04-25 13:00:56 +01:00
John R. Lenton
fe815e7fa2 cleanup in isle 5 please. 2017-04-25 13:00:55 +01:00