Andre Noll [Fri, 23 Sep 2011 15:21:58 +0000 (17:21 +0200)]
gsu: Initial completion support.
This adds the framework for command completion of scripts which make
use of the gsu subcommand library. The idea is to implement as much
as possible as generic helpers within gsu in order to minimize code
duplication in the scripts which source the gsu library.
The new "complete" subcommand is automatically included in each
application, just like the help, man and prefs commands we already
have. This subommand is meant to be used as the completer which calls
the custom subcommand completers included in the application.
Two new public helper functions, gsu_complete_options() and
gsu_cword_is_option_parameter() are introduced in this commit.
The former function takes a usual getopt string and completes according
to all options in this string. The latter is useful for completers
which need to determine whether the current word is the parameter to
some option in order to find out how to complete the current word.
For example, the -s option of cmt's vmem command takes a mandatory
parameter which is a number. So the completer for this command must
complete differently depending on whether the previous word is "-s".
Andre Noll [Fri, 23 Sep 2011 12:03:38 +0000 (14:03 +0200)]
Split gsu.
This patch splits the gsu file into two files for config parsing and
subcommand handling respectively. Each part may be used independently
of the other.
Moreover, all scripts which use gsu now include the needed parts
directly rather than relying on the shell to have already sourced
the needed gsu files. This shortens bash startup time and makes gsu
easier to use for people whose login shell is not bash.
Andre Noll [Tue, 2 Aug 2011 13:12:48 +0000 (15:12 +0200)]
Allow hyphens in command names.
There is no reason to forbid subcommands with hyphens, and sometimes
it is just natural have such a command. For instance if the subcommand
wraps an existing command with a hyphen like "apt-get".
So change the regular expression for subcommands accordingly.
Andre Noll [Tue, 2 Aug 2011 13:09:21 +0000 (15:09 +0200)]
gsu: Avoid duplication of command regex.
The regular expression for fining the subcommands was duplicated
four times in gsu. Needless to say that this resulted in more than
one variant of the expression...
Avoid this duplication by introducing the global gsu_command_regex
variable. While at it, use a more clever sed command in
_gsu_available_commands() which allows to kill a grep command.
Andre Noll [Thu, 25 Mar 2010 14:23:25 +0000 (15:23 +0100)]
gsu: Fix com_prefs() for invalid preferences.
The prefs command would print only empty values for
all options that come after an invalid option.
Refuse to execute com_prefs() in this case is the most
simple fix.