Commit Graph

29 Commits

Author SHA1 Message Date
Philip Withnall
70c0f3bff6
completion: Rework quoting in gsettings completion script
This is a partial revert and rework of commit
c79575362e, for the `gsettings` script
only (the other completion scripts are fine).

I blindly added quoting to everything shellcheck told me to, without
testing it properly.

As it turns out, the `$schemadir` argument to `gsettings` invocations
was deliberately not quoted, so that it would expand to zero arguments
if unset, and two arguments (`--schemadir /some/path`) if set earlier in
the command-being-completed.

Quoting it meant that it expanded to one argument (the empty string) if
unset, which caused the `gsettings` subcommands to fail, and hence any
further tab completion to fail.

Fix that as suggested on https://www.shellcheck.net/wiki/SC2086 by
turning `schemadir` into an array, which either has zero members if
unset, or two members if set.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-17 17:43:50 +01:00
Philip Withnall
295a6fb965
completion: Add missing copyright and licensing headers
The copyright entries come from looking at `git log gio/completion/*`
and, in particular, `git log -- gio/gsettings-bash-completion.sh` (etc.)
as the files were moved after being originally written, and haven’t
really changed since.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1415
2024-04-17 17:43:44 +01:00
Philip Withnall
cc22637856
completion: Invoke the command being completed
As suggested by Ville Skyttä in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4012#note_2084405,
make sure to invoke the copy of the command which is being completed
when asking for completions of a given subcommand.

This avoids accidentally invoking any old `gdbus`/`gresource`/etc.
binary which is hanging around in another part of `$PATH`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-17 17:43:38 +01:00
Philip Withnall
827bca3212
completion: Ignore SC2207 for COMPREPLY assigments
Using the same justification as in
https://gitlab.gnome.org/GNOME/dconf/-/merge_requests/81#note_2083220:
it’s hard to get this right, with error handling, in a way which is
understandable to people reading it, and which both bash and shellcheck
will be happy with.

On the assumption that none of the completions generated by any of these
utilities will include ‘problematic’ characters (ones which would cause
word splitting or globbing in bash), just ignore the shellcheck
warnings. Note that I have not actually closely verified that these
utilities can’t return ‘problematic’ characters.

This means we can enable shellcheck, with fatal warnings, for these
scripts, and hence catch future regressions.

If someone wants to improve the handling of globbing/word splitting in
some/all of these array assignments in future, the shellcheck disables
can be removed.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:09:36 +01:00
Philip Withnall
6024fb9753
completion: Quote argument to unset
Otherwise it gets globbed and the wrong thing potentially gets unset.
Spotted by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:08:39 +01:00
Philip Withnall
17f0cad2c7
completion: Drop some unused variables
Spotted by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:08:08 +01:00
Philip Withnall
7ad93a0c95
completion: Use read -r rather then plain read
This means that backslashes in the input (which is unlikely, but I guess
possible) won’t affect line splitting. Spotted by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:07:12 +01:00
Philip Withnall
b1ef6a125e
completion: Quote variable dereferences within variable dereferences
Otherwise they could get split. Spotted by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:06:13 +01:00
Philip Withnall
d3d811f4e5
completion: Split declaration and assignment of variables
Having them on the same line masks failure of the subcommand generating
the value being assigned. Spotted by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:05:04 +01:00
Philip Withnall
a7ad2a4c3a
completion: Drop unnecessary $ from variables in arithmetic expressions
It’s not needed, according to shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:03:19 +01:00
Philip Withnall
c79575362e
completion: Add missing quoting
As suggested by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 13:58:49 +01:00
Philip Withnall
aaf715a046
completion: Stop using old backtick quoting for subcommands
Fixes a shellcheck warning.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 13:54:33 +01:00
Philip Withnall
f95e8b4e7c
completion: Add shellcheck shell hints to all completion scripts
Because completion scripts are not executed directly, they don’t have a
shebang line, so shellcheck can’t be sure which shell syntax to use for
them. Help it out.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 13:51:44 +01:00
Ville Skyttä
bf1508fa76 completion: make gsettings work in nounset mode
With the shell in nounset mode, an error is emitted on referencing
`schemadir` as it is not initialized in all code paths.

Initialize to an empty string to fix.

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
2024-04-01 10:31:34 +00:00
Philip Withnall
2ca4d865b2 completion: Declare variables as local in gio completion script
Most variables were, but a few were not declared as local, and hence
leaked into the calling environment every time someone tab-completed the
`gio` command.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2275
2021-01-05 16:14:16 +00:00
Frederic Martinsons
c3a073e96f Add gio launch command to execute desktop file
This command will try to execute a desktop file, before that
it will load the input as a keyfile for checking its existence
and its validity (as a keyfile).
File arguments are allowed after the desktop file.

Closes #54

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2020-12-09 08:15:42 +01:00
Philip Withnall
00bfb3ab44 tree: Fix various typos and outdated terminology
This was mostly machine generated with the following command:
```
codespell \
    --builtin clear,rare,usage \
    --skip './po/*' --skip './.git/*' --skip './NEWS*' \
    --write-changes .
```
using the latest git version of `codespell` as per [these
instructions](https://github.com/codespell-project/codespell#user-content-updating).

Then I manually checked each change using `git add -p`, made a few
manual fixups and dropped a load of incorrect changes.

There are still some outdated or loaded terms used in GLib, mostly to do
with git branch terminology. They will need to be changed later as part
of a wider migration of git terminology.

If I’ve missed anything, please file an issue!

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-06-12 15:01:08 +01:00
Ondrej Holy
b3bf1e263e gio: Always include mounts in the results
Mounts are currently completed only if the prefix looks like scheme,
however, this doesn't work well if the mounts have also path component.
Let's always include them to fix this issue. The mounts are cached by the
volume monitors, so it should not significantly affect the performance.
2019-10-07 09:21:19 +02:00
Ondrej Holy
8bc52105ef gio: Complete also activation roots of volumes
Currently, "gio mount google-drive<tab>" isn't completed even though
that volume exists for google-drive://oholy@redhat.com/. Let's use
"gio mount -li" output to complete also activation roots of volumes.
2019-10-07 09:21:19 +02:00
Ondrej Holy
3a1492ec4f gio: Fix completion of URIs without hostname part
Currently, "gio list file:///h<tab>" doesn't complete "file:///home"
because the result of "dirname file:///h" is not "file:///" but "file:/",
which breaks the consequent logic. Let's subtract basename from the
path in order to workaround this issue.
2019-10-07 09:21:09 +02:00
Ondrej Holy
84c8899fca gio: Add missing "gio remove" option to bash completion script
Bash completion	script allows to complete various options, but "gio remove"
is missing. Let's add this missing option.
2019-09-16 11:19:50 +02:00
Simon McVittie
fa32ee6481 Remove unnecessary +x permissions
None of these files starts with a #! line, and they are not native
binary executables, so if a user attempts to execute them as a program,
Unix shells will run them as /bin/sh scripts. This is not going to end
well, since none of them are shell scripts (the gio bash completion
is for bash, which is not a lowest-common-denominator POSIX shell, and
in any case is designed to be sourced rather than executed).

Fixes: #1539
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-09-23 17:01:04 +01:00
Ondrej Holy
e0e0f259c3 gio: Add bash completion for gio tool
GVfs utils used to have bash completion, which was pretty useful. However,
it hasn't been ported to gio tool unfortunately. GLib provides completion
for various utils already, so it would be nice to provide completion also
for gio tool. I've updated old bash completion code and merged with some
my old unmerged fixes.

The gvfs completion used "gvfs-ls --show-completions" helper. This mentioned
option hasn't been obviously ported to "gio list" and the proposed completion
doesn't add this option in "gio list" to not pollute the codes, but maybe it
is a bit slower as consequence.

The proposed bash completion suggests subcommands, uris and paths including
the remote mounts. It contains some workarounds, especially because of proper
handling of paths with colons and other special chars (like spaces)...
2018-06-15 12:34:10 +02:00
Arnaud Bonatti
6d009bc56a Add ‘gsettings list-schemas --print-paths’ option
Prints next to the name of non-relocatable schemas their paths.

https://bugzilla.gnome.org/show_bug.cgi?id=792064
2018-01-05 13:01:03 +00:00
Jiro Matsuzawa
acea147cbc gsettings: Suppress error messages of completion
https://bugzilla.gnome.org/show_bug.cgi?id=695681
2017-10-05 14:41:24 +01:00
Florian Müllner
e048d31210 completion: Complete gsettings describe
Commit 8fd72838 added a 'describe' command to the gsettings tool,
but didn't implement completions for it.

https://bugzilla.gnome.org/show_bug.cgi?id=772297
2016-10-05 14:26:42 -04:00
Ryan Lortie
9defb6b1b1 New gapplication(1) tool
This is essentially a commandline implementation of the client-side of
the org.freedesktop.Application D-Bus interface.

It includes support for tab-completion based on desktop files and their
contents.

https://bugzilla.gnome.org/show_bug.cgi?id=704218
2013-10-17 10:12:27 -04:00
David Gomes
bfb6ff0dbd gsettings: implemented --version command
This was discussed in
https://bugzilla.gnome.org/show_bug.cgi?id=697131
2013-04-03 21:35:57 -04:00
Matthias Clasen
e9ec1ad068 Install bash completion files in /usr/share/
The bash-completion code nowadays expects completion files to
be installed in  /usr/share/bash-completion/completions, and
expects them to be named like the command they are completing
for.

https://bugzilla.gnome.org/show_bug.cgi?id=677782
2012-06-21 06:11:58 -04:00