gsu.git
9 years agogsu: Don't fail if HOME is unset.
Andre Noll [Tue, 26 Aug 2014 19:52:07 +0000 (21:52 +0200)]
gsu: Don't fail if HOME is unset.

As pointed out by Joffrey Fitz, gsu-based scripts do not work when
run as a user without home directory. This happens for example if
the script is executed through a web application as the www-data user.

This patch replaces all references to HOME by ${HOME:-}, i.e. we just
default to the empty string but don't fail immediately.

9 years agogsu: Mark get_geometry() as a private function.
Andre Noll [Tue, 26 Aug 2014 21:35:51 +0000 (23:35 +0200)]
gsu: Mark get_geometry() as a private function.

The function is not called from any scripts that currently use gsu.
This commit marks it private by prepending an underscore to its name.

9 years agogsu: Improve documentation of gsu_getopts().
Andre Noll [Mon, 25 Aug 2014 20:24:07 +0000 (22:24 +0200)]
gsu: Improve documentation of gsu_getopts().

The sentence which explains how $o_X is set for both types of options
was rather confusing. The new text should be better.

While we're at it,
* mention that getopts is a bash builtin
* switch to "modern" ((expr)) arithmetic evaluation in example
* use '' to quote constants in example

9 years agogsu: Improve help text of complete subcommand.
Andre Noll [Sun, 24 Aug 2014 14:57:08 +0000 (16:57 +0200)]
gsu: Improve help text of complete subcommand.

The current help text talks about two forms to run this command,
but only one is mentioned. This commit tries to clarify that the
function behaves differently when called without argument.

9 years agogsu: Fix quoting of config default options.
Andre Noll [Wed, 6 Aug 2014 14:44:43 +0000 (16:44 +0200)]
gsu: Fix quoting of config default options.

This makes newlines in the default of a gsu config option work.

9 years agogsu: Add missing declaration of a local variable.
Andre Noll [Wed, 30 Jul 2014 10:37:53 +0000 (12:37 +0200)]
gsu: Add missing declaration of a local variable.

"opt" is used but not declared local.

9 years agogsu: User banner text also for gsu gui.
Andre Noll [Fri, 16 May 2014 13:35:32 +0000 (15:35 +0200)]
gsu: User banner text also for gsu gui.

Currently the $gsu_banner_txt variable is used only for subcommand
utilities but not for dialog-based tools. There is no real reason for
this restriction, so this commit starts to use the variable also for
the various GUIs.

9 years agogsu/gui: Fix regex for tree walk.
Andre Noll [Wed, 16 Apr 2014 18:22:38 +0000 (18:22 +0000)]
gsu/gui: Fix regex for tree walk.

If one directory name is a suffix of another, the regex
for grep found both, which is bad.

9 years agogsu_gui: Add check for dialog executable.
Andre Noll [Fri, 13 Dec 2013 09:57:42 +0000 (10:57 +0100)]
gsu_gui: Add check for dialog executable.

Currently, programs which use gsu_gui exit silently with no indication about
what went wrong if dialog is not installed. This patch makes it print an error
message in this case.

9 years agoAdd gsu_gui.
Andre Noll [Fri, 23 Sep 2011 12:04:23 +0000 (14:04 +0200)]
Add gsu_gui.

The dialog-based shell library for earth-shaking graphical user
interfaces that don't suck.

Its main entry function gsu_gui() allows to pass a tree to control
the menus.

9 years agogsu: simplify banner message.
Andre Noll [Fri, 27 Jul 2012 08:59:08 +0000 (10:59 +0200)]
gsu: simplify banner message.

This was unnecessarily complex and caused an error if set -u
was used.

9 years agogsu: Avoid referencing an unset variable.
Andre Noll [Fri, 27 Jul 2012 08:58:12 +0000 (10:58 +0200)]
gsu: Avoid referencing an unset variable.

This causes an error if scripts use set -u.

9 years agogsu subcommand: Add gsu_get_unnamed_arg_num().
Andre Noll [Tue, 29 Nov 2011 22:28:51 +0000 (23:28 +0100)]
gsu subcommand: Add gsu_get_unnamed_arg_num().

This will be handy for many gsu applications.

9 years agogsu subcommand: Fix off-by-one bug in gsu_cword_is_option_parameter().
Andre Noll [Tue, 29 Nov 2011 22:26:48 +0000 (23:26 +0100)]
gsu subcommand: Fix off-by-one bug in gsu_cword_is_option_parameter().

We define $n as the number of characters in the getopt string *minus one*,
so we must loop from 0 to $n, inclusively.

This patch also adds documentation of this public function.

9 years agoFix gsu com_complete().
Andre Noll [Tue, 29 Nov 2011 13:02:48 +0000 (14:02 +0100)]
Fix gsu com_complete().

It should work also if set -u was given. Currently this fails if
_com_complete() is called with no arguments.

Moreover, the first argument, if it is provided, should be a number
but we missed to check this.

9 years agogsu subcommand: Use gsu_getopts.
Andre Noll [Sun, 9 Oct 2011 16:52:03 +0000 (18:52 +0200)]
gsu subcommand: Use gsu_getopts.

This makes the prefs command error out on invalid options
and avoids the expansion of the possibly unset parameter $1.

9 years agogsu_getopts: Rename local variable opt to _gsu_getopts_opt.
Andre Noll [Wed, 12 Oct 2011 08:26:38 +0000 (10:26 +0200)]
gsu_getopts: Rename local variable opt to _gsu_getopts_opt.

As pointed out by Sebastian Stark, calling the loop variable "opt"
in code which is supposed to be eval'd by the application may conflict
with another local variable of the same name defined in the function
which calls gsu_getopt().

This could lead to rather obscure bugs which are hard to detect.
The callers don't use this loop variable directly, so we are free
to call it whatever we want. Therefore this patch renames $opt to
something which is much less likely to cause a conflict.

9 years agogsu: Avoid parameter expansion on unset variables.
Andre Noll [Sun, 9 Oct 2011 11:18:29 +0000 (13:18 +0200)]
gsu: Avoid parameter expansion on unset variables.

This patch allows to run scripts which use gsu with bash's -u option
enabled. This is mostly useful to spot bugs due to typos in variable
names.

9 years agogsu: Overhaul of the rexexp matching for help commands.
Andre Noll [Thu, 29 Sep 2011 13:12:33 +0000 (15:12 +0200)]
gsu: Overhaul of the rexexp matching for help commands.

The old sed scripts were unreadable and broken on non-gnu systems
since they made use of some gnuisms of grep and sed like \+ in regular
expressions to match at least one character or sed's T command which
jumps to a label if no substitution has been made since the most
recent reading of an input line.

This patch switches to extended regular expressions and replaces all
broken sed scripts by portable ones, which are known to work at least
on FreeBSD and MacOS. The new scripts are commented verbosely so that
any subsequent changes do not require a full rewrite, hopefully.

9 years agogsu: Initial completion support.
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".

9 years agogsu: Don't export functions.
Andre Noll [Wed, 28 Sep 2011 14:47:46 +0000 (16:47 +0200)]
gsu: Don't export functions.

This is no longer necessary now that all gsu scripts include the gsu
shell library directly.

9 years agoSplit gsu.
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.

9 years agoAllow hyphens in command names.
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.

9 years agogsu: Avoid duplication of command regex.
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.

9 years agogsu: Set copyright year to 2011.
Andre Noll [Tue, 2 Aug 2011 12:42:22 +0000 (14:42 +0200)]
gsu: Set copyright year to 2011.

9 years agogsu: Fix handling of config options with newlines.
Andre Noll [Sun, 27 Mar 2011 09:49:35 +0000 (11:49 +0200)]
gsu: Fix handling of config options with newlines.

Without this, newlines are transformed into spaces.

9 years agogsu: Don't use the =~ operator.
Andre Noll [Thu, 25 Nov 2010 16:36:23 +0000 (17:36 +0100)]
gsu: Don't use the =~ operator.

I need it at least on one machine that still has only bash-2.

9 years agogsu_getopts: Abort on programming errors and add documentation.
Andre Noll [Sun, 24 Oct 2010 09:59:46 +0000 (11:59 +0200)]
gsu_getopts: Abort on programming errors and add documentation.

9 years agogsu: Introduce gsu_getopts().
Andre Noll [Sun, 24 Oct 2010 09:28:23 +0000 (11:28 +0200)]
gsu: Introduce gsu_getopts().

No users yet.

9 years agogsu: Remove check on bash version.
Andre Noll [Fri, 15 Oct 2010 16:20:18 +0000 (18:20 +0200)]
gsu: Remove check on bash version.

It hurts more than the possible incompatibilities.

9 years agogsu: com_prefs -e fixes.
Andre Noll [Sun, 10 Oct 2010 09:12:51 +0000 (11:12 +0200)]
gsu: com_prefs -e fixes.

Create the subdirectory for the config file if it does not exist, and fix the
return value for the editor command.

9 years agogsu: Kill some unused error codes.
Andre Noll [Sat, 25 Sep 2010 17:28:45 +0000 (19:28 +0200)]
gsu: Kill some unused error codes.

9 years agogsu: Add -e option to com_prefs.
Andre Noll [Mon, 13 Sep 2010 03:30:36 +0000 (05:30 +0200)]
gsu: Add -e option to com_prefs.

9 years agogsu: Minor cosmetic cleanup.
Andre Noll [Mon, 13 Sep 2010 03:30:18 +0000 (05:30 +0200)]
gsu: Minor cosmetic cleanup.

9 years agogsu com_help(): Be more strict when looking for command documentation.
Andre Noll [Mon, 30 Aug 2010 21:52:07 +0000 (23:52 +0200)]
gsu com_help(): Be more strict when looking for command documentation.

9 years agoChange name of internal commands.
Andre Noll [Mon, 30 Aug 2010 16:28:52 +0000 (18:28 +0200)]
Change name of internal commands.

These are not meant to be called from elsewhere, so mark them with an
underscore. Also fix the indentation of the com_help() code.

9 years agogsu: Error out if not running as bash-4.
Andre Noll [Sat, 25 Sep 2010 16:56:25 +0000 (18:56 +0200)]
gsu: Error out if not running as bash-4.

9 years agogsu: Change semantics of gsu_check_arg_count().
Andre Noll [Sun, 18 Jul 2010 13:30:18 +0000 (15:30 +0200)]
gsu: Change semantics of gsu_check_arg_count().

It's kind of ugly having to specify an artificial upper bound on the arg count
if the allowed number of arguments is unlimited.

9 years agogtt: The git topic tool.
Andre Noll [Fri, 4 Jun 2010 16:17:55 +0000 (18:17 +0200)]
gtt: The git topic tool.

Another gsu-based script for managing git topic branches.

9 years agogsu: Add gsu_check_arg_count().
Andre Noll [Mon, 21 Jun 2010 14:29:20 +0000 (16:29 +0200)]
gsu: Add gsu_check_arg_count().

This function is open-coded $MANY times, so it makes sense to
have one globally visible function that can be called from all
scripts that use gsu.

9 years agogsu: Print the name of the invalid config variable on errors.
Andre Noll [Sun, 13 Jun 2010 23:46:21 +0000 (01:46 +0200)]
gsu: Print the name of the invalid config variable on errors.

9 years agogsu: Fix quoting for multi-line variables.
Andre Noll [Mon, 5 Apr 2010 16:29:14 +0000 (18:29 +0200)]
gsu: Fix quoting for multi-line variables.

The new para_adm topics command triggered this bug.

9 years agogsu: Fix com_prefs() for invalid preferences.
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.

9 years agogsu: Make command line vars trump config file vars.
Andre Noll [Tue, 2 Mar 2010 15:00:23 +0000 (16:00 +0100)]
gsu: Make command line vars trump config file vars.

This allows to overrule preferences  given in the config file by
using command line like this

lv=foo snapfsck

which ignores the setting of lv in ~/.snapfsck.rc and uses the value
"foo" instead.

9 years agogsu: Print help text on prefs command.
Andre Noll [Tue, 2 Mar 2010 14:56:50 +0000 (15:56 +0100)]
gsu: Print help text on prefs command.

This uses another nice bashism I recently learned.

9 years agogsu: Use bash shebang.
Andre Noll [Tue, 2 Mar 2010 14:55:32 +0000 (15:55 +0100)]
gsu: Use bash shebang.

It's kind of pointless trying to be portable here.

9 years agogsu: Allow help/man/prefs command even on invalid configs.
Andre Noll [Fri, 21 Aug 2009 15:20:39 +0000 (17:20 +0200)]
gsu: Allow help/man/prefs command even on invalid configs.

These generic subcommands do not need the config file. It's pointless
to refuse to print the help e.g. if a required config variable is unset.

Also, use the name of the executable as the default value for gsu_name.

9 years agogsu: Introduce gsu_config_var_prefix.
Andre Noll [Fri, 19 Jun 2009 09:25:27 +0000 (11:25 +0200)]
gsu: Introduce gsu_config_var_prefix.

It defaults to the $gsu_name, i.e. this is a backwards-compatible change.

9 years agogsu: Fix a typo in gsu_check_options().
Andre Noll [Fri, 19 Jun 2009 09:24:38 +0000 (11:24 +0200)]
gsu: Fix a typo in gsu_check_options().

This caused gsu to exit without an error message in case there is
an invalid option type given in the script that used gsu.

9 years agogsu: Allow empty default values.
Andre Noll [Fri, 12 Jun 2009 11:33:24 +0000 (13:33 +0200)]
gsu: Allow empty default values.

9 years agoPriliminary version of gsu2.
Andre Noll [Wed, 10 Jun 2009 14:48:47 +0000 (16:48 +0200)]
Priliminary version of gsu2.

Backwards compatible, new features are only used by dpch yet.

9 years agogsu improvements.
Andre Noll [Fri, 3 Apr 2009 08:45:53 +0000 (10:45 +0200)]
gsu improvements.

Support config files from within gsu. Untested.

9 years agogsu: Remove unused variable "tilde_signs".
Andre Noll [Sun, 26 Aug 2007 22:15:53 +0000 (00:15 +0200)]
gsu: Remove unused variable "tilde_signs".

9 years agogsu: Make man a generic gsu command.
Andre Noll [Sun, 26 Aug 2007 21:07:14 +0000 (23:07 +0200)]
gsu: Make man a generic gsu command.

Also, make the help text of eat grutatxt-friendly and add some more
documentation.

9 years agogsu: Kill debug "ret=1".
Andre Noll [Sat, 25 Aug 2007 19:00:25 +0000 (21:00 +0200)]
gsu: Kill debug "ret=1".

9 years agogsu: Replace "$*" by "$@".
Andre Noll [Fri, 24 Aug 2007 17:06:30 +0000 (19:06 +0200)]
gsu: Replace "$*" by "$@".

This allows to pass parameters containing spaces.

9 years agogsu: Trivial gsu_err_msg() cleanup.
Andre Noll [Wed, 1 Aug 2007 15:09:07 +0000 (17:09 +0200)]
gsu: Trivial gsu_err_msg() cleanup.

9 years agogsu: Fix two bashisms.
Andre Noll [Thu, 26 Jul 2007 13:40:42 +0000 (15:40 +0200)]
gsu: Fix two bashisms.

Always include the '$', even in math expressions where bash doesn't
need it.

9 years agogsu: Fix "echo -en" bashism.
Andre Noll [Thu, 26 Jul 2007 13:15:37 +0000 (15:15 +0200)]
gsu: Fix "echo -en" bashism.

9 years agogsu: trivial cleanup.
Andre Noll [Fri, 13 Jul 2007 17:06:50 +0000 (19:06 +0200)]
gsu: trivial cleanup.

9 years agogsu: remove shebang
Andre Noll [Wed, 11 Jul 2007 14:59:48 +0000 (16:59 +0200)]
gsu: remove shebang

It's not needed for functions.

9 years agogsu: print $(basename $0) instead of $0 on help output.
Andre Noll [Wed, 11 Jul 2007 13:33:07 +0000 (15:33 +0200)]
gsu: print $(basename $0) instead of $0 on help output.

9 years agointroduce gsu: The global subcommand utility, and make bbf_adm use it.
Andre Noll [Wed, 11 Jul 2007 09:34:43 +0000 (11:34 +0200)]
introduce gsu: The global subcommand utility, and make bbf_adm use it.

18 years agoeat: the environment admin tool
Andre [Tue, 21 Feb 2006 17:20:09 +0000 (18:20 +0100)]
eat: the environment admin tool

It is no good sign if one has written so many scripts that
a tool for managing them is neccessary..