gsu.git
7 years agoconfig: Fix braino in comment.
Andre Noll [Mon, 17 Apr 2017 13:16:51 +0000 (15:16 +0200)]
config: Fix braino in comment.

This was wrong since forever.

7 years agosubcommand: Make help text variables private.
Andre Noll [Sun, 5 Mar 2017 22:03:36 +0000 (23:03 +0100)]
subcommand: Make help text variables private.

It is unnecessary to export these as they are never needed in the
environment of subsequently executed commands. In fact, these variables
should be considered private to gsu. The name should thus start with
an underscore.

7 years agosubcommand: Move up gsu_getopts().
Andre Noll [Sun, 5 Mar 2017 21:39:20 +0000 (22:39 +0100)]
subcommand: Move up gsu_getopts().

It will soon be needed by com_man() which is above gsu_getopts()
at the moment, so move it up. Again, no changes.

7 years agosubcommand: Move gsu_check_arg_count().
Andre Noll [Sun, 5 Mar 2017 21:36:25 +0000 (22:36 +0100)]
subcommand: Move gsu_check_arg_count().

It is called from gsu_getopts() which is defined further up in the
file. This does not really matter in bash, but it is still confusing,
so let's move gsu_check_arg_count() up.

Pure code movement, no changes.

7 years agosubcommand: Do not duplicate options to com_prefs().
Andre Noll [Sun, 5 Mar 2017 21:57:10 +0000 (22:57 +0100)]
subcommand: Do not duplicate options to com_prefs().

7 years agosubcommand: Get rid of global $gsu_cmds.
Andre Noll [Sun, 5 Mar 2017 21:17:25 +0000 (22:17 +0100)]
subcommand: Get rid of global $gsu_cmds.

It is only used in _gsu_print_available_commands() so we may
make it local to this function.

7 years agosubcommand: Simplify gsu().
Andre Noll [Sun, 5 Mar 2017 21:13:53 +0000 (22:13 +0100)]
subcommand: Simplify gsu().

There is no need to special-case the four autocommands in the main
entry function gsu(). Dropping the undercore in the name of the
four command handlers allows to treat them in the same way as the
subcommands which are provided by the application.

7 years agosubcommand: Fix identation of code in com_man().
Andre Noll [Sun, 5 Mar 2017 21:50:29 +0000 (22:50 +0100)]
subcommand: Fix identation of code in com_man().

Some lines were indented with spaces rather than tabs. No semantic
changes.

7 years agosubcommand: Kill stray "cmt".
Andre Noll [Sun, 5 Mar 2017 21:58:26 +0000 (22:58 +0100)]
subcommand: Kill stray "cmt".

A leftover from old days where cmt (the cluster management tool) was
the only gsu application.

7 years agosubcommand: Use POSIX compatible command regex.
Andre Noll [Sun, 5 Mar 2017 18:55:13 +0000 (19:55 +0100)]
subcommand: Use POSIX compatible command regex.

The POSIX way to ask for one or more matches of the preceeding atom
is {1,} while the plus character is a non-portable shortcut.

Note that since the closing brace of the regex bound is inside
parameter expansion, we need to escape it with a backslash while the
opening brace must not be escaped.

7 years agoConvert README to markdown format.
Andre Noll [Mon, 6 Mar 2017 15:25:30 +0000 (16:25 +0100)]
Convert README to markdown format.

It used to be in grutatext format, and was converted to html with the
grutatxt perl script. The grutatxt project is dead, so let's switch
to markdown.

7 years agoREADME: Add documentation of $gsu_options.
Andre Noll [Tue, 7 Mar 2017 07:40:39 +0000 (08:40 +0100)]
README: Add documentation of $gsu_options.

For some reason this public variable was mentioned in the list of
public variables, but the list item lacked the description.

7 years agogsu_make_tempfile(): Avoid reading an unbound variable. next
Andre Noll [Thu, 28 Jul 2016 11:56:05 +0000 (13:56 +0200)]
gsu_make_tempfile(): Avoid reading an unbound variable.

If a gsu script

(a) enables the -u option to treat unset variables as
    an error for parameter expansion,
(b) does not set TMPDIR,
(c) calls gsu_make_tempfile(),

gsu_make_tempfile() fails with an "TMPDIR: unbound variable" error.

The code already contains a fallback for this case, so we can use
the :- construct to avoid the error and fall back to /tmp if TMPDIR
is unset or NULL.

8 years agoAdd gsu_make_tempfile() and fix bug in gui module.
Andre Noll [Wed, 20 Jan 2016 09:54:35 +0000 (10:54 +0100)]
Add gsu_make_tempfile() and fix bug in gui module.

While mkstemp(3) is required by POSIX.1-2001, mktemp(1) is not in POSIX
and the various Unixes ship different and incompatible implementations
of this command line utility.

This commit adds the new public gsu_make_tempfile() helper to the
common part of gsu and changes the gui module to use it.

The mktemp invocation in the gui module was buggy because it ran
mktemp with a relative template (no slash). Hence the temporary file
was created in the current working directory. Of course this fails
if $CWD is not writable. The new public function gets this right.

9 years agocommon: Allow undefined $gsu_errors.
Andre Noll [Tue, 3 Mar 2015 17:28:19 +0000 (18:28 +0100)]
common: Allow undefined $gsu_errors.

If this variable is undefined, and the nounset option is turned on
(set -u), gsu aborts early when setting up the gsu_error_txt array.

Fix this by using ${gsu_errors:-} instead of plain $gsu_errors to
allow for scripts without error codes.

Reported by Congmao Wang.

9 years agosubcommand: Avoid referencing possibly undefined $ret.
Andre Noll [Tue, 3 Mar 2015 17:21:06 +0000 (18:21 +0100)]
subcommand: Avoid referencing possibly undefined $ret.

If a subcommand does not set $ret (like the minimal "hello" example
does), and sets the nounset bash option (set -u), gsu aborts at
the attempt to reference $ret. Fix this flaw by setting $ret to
$GSU_SUCCESS prior to calling the subcommand.

Reported by Congmao Wang.

9 years ago_gsu_print_available_commands(): Don't abort if set -e is set.
Andre Noll [Tue, 3 Mar 2015 17:15:52 +0000 (18:15 +0100)]
_gsu_print_available_commands(): Don't abort if set -e is set.

It was pointed out by Congmao Wang that the example hello.bash script
prints only the first subcommand and exits if it is called with an
invalid subcommand and set -e is set. This is due to the "let count++"
statement which returns 1 in the first iteration of the loop since
count is zero.

This patch changes the statement to "let ++count" which returns zero
in all cases.

9 years agocommon: Fix gsu_is_a_number().
Andre Noll [Sat, 14 Feb 2015 20:17:53 +0000 (21:17 +0100)]
common: Fix gsu_is_a_number().

We must use [ ... ] in gsu_is_a_number() because arithmetic expansion
with ((...))  undergoes parameter and variable expansion. For example

x=foo
gsu_is_a_number "$x"

will pass "foo" to gsu_is_a_number() where the expression  (("$1"))
tries to expand the (non-existing) variable foo, aborting the script
if set -u was given.

This bug was introduced a few month ago in commit 44860e92 (Use modern
style arithmetic evaluation everwhere).

9 years agoREADME: Move table of contents to the top of the document. maint
Andre Noll [Mon, 10 Nov 2014 10:13:46 +0000 (11:13 +0100)]
README: Move table of contents to the top of the document.

Without the "=====" markers it is printed at the bottom, which is not
very useful.

9 years agoREADME: Fix gitweb link.
Andre Noll [Mon, 10 Nov 2014 10:07:06 +0000 (11:07 +0100)]
README: Fix gitweb link.

The gitweb page is hosted by git.tuebingen.mpg.de. The ilm.eb.local
instance was used only for testing and no longer exists.

9 years agoAdd GSU logo.
Andre Noll [Thu, 9 Oct 2014 22:47:43 +0000 (22:47 +0000)]
Add GSU logo.

It's nice to have a logo for the GSU library. Here's a simple one
made with dia.

9 years agoAdd license.
Andre Noll [Sat, 27 Sep 2014 23:16:51 +0000 (23:16 +0000)]
Add license.

I've put 2006 as the copyright year since this was the date of the
first usable version of gsu. Hope that's OK.

9 years agoAdd README.
Andre Noll [Sat, 30 Aug 2014 12:46:37 +0000 (14:46 +0200)]
Add README.

Up to now the API of gsu was completely undocumented. This commit
tries to improve on this. It adds a README file which explains the
public functions and variables of the three gsu modules (subcommand,
config and gui). Most features are illustrated by examples.

The README file is formatted in the grutatxt markup language, so it
can easily be converted to a nice html document.

Many thanks to George Wang who read an early draft of this document
and contributed many improvements.

9 years agosubcommand: Add documentation of gsu_complete_options().
Andre Noll [Thu, 4 Sep 2014 22:36:11 +0000 (00:36 +0200)]
subcommand: Add documentation of gsu_complete_options().

It's a public function that should be documented.

9 years agosubcommand: Fix two typos.
Andre Noll [Sat, 6 Sep 2014 00:08:36 +0000 (02:08 +0200)]
subcommand: Fix two typos.

9 years agogui: Use trap to make sure temporary files are removed.
Andre Noll [Sat, 13 Sep 2014 14:16:34 +0000 (16:16 +0200)]
gui: Use trap to make sure temporary files are removed.

Without this, killing the application might leave a temporary file.

9 years agogui: Introduce _set_dialog_ret().
Andre Noll [Sat, 6 Sep 2014 17:41:16 +0000 (19:41 +0200)]
gui: Introduce _set_dialog_ret().

The improved exit code handling for dialog(1) also makes sense for
the other invocations of dialog. This patch abtracts out the logic
into the new internal _set_dialog_ret() function.

9 years agogui: Add documentation of public functions.
Andre Noll [Sat, 6 Sep 2014 00:34:59 +0000 (02:34 +0200)]
gui: Add documentation of public functions.

The functions gsu_inputbox(), gsu_textbox() and gsu_msgbox() were not
documented at all. This commit adds summary, usage and a description
for each.

9 years agogui: Conform to $ret and $result conventions.
Andre Noll [Mon, 1 Sep 2014 22:23:41 +0000 (00:23 +0200)]
gui: Conform to $ret and $result conventions.

Unlike the rest of gsu, the functions of the gui module did not follow
the rule that functions should always set $ret to indicate error or
success, and $result to either the result of the function (if any)
or to an error context string. This commit makes all functions of
the gui module conform to this rule.

This patch also improves the error handling of _gsu_menu(). This
function should distinguish between three cases, according to the
exit code of dialog(1): OK (user selected the OK button), Cancel
(user pressed the escape key or selected the Cancel button), and error
(dialog(1) failed to execute or returned unsuccessfully).

The old code does not distinguish between the last two cases. Hence one
could not exit the application by pressing CTRL+C from a menu. This
patch changes _gsu_menu() to look more carefully at the exit code of
dialog(1) to tell apart the "error" case and the "cancel" case.

9 years agogui: Make $first a local variable of _get_subtree().
Andre Noll [Mon, 1 Sep 2014 22:20:21 +0000 (00:20 +0200)]
gui: Make $first a local variable of _get_subtree().

Apparently this was missed when the function was introduced. The
variable is only referenced in _get_subtree().

9 years agogui: Make _gsu_node_name_pattern private.
Andre Noll [Mon, 1 Sep 2014 21:58:29 +0000 (23:58 +0200)]
gui: Make _gsu_node_name_pattern private.

Conform to the convention that the name of a private variables should
start with an underscore character. Also there is no need to export
the variable.

9 years agogui: Make gsu_menu() private.
Andre Noll [Mon, 1 Sep 2014 21:54:09 +0000 (23:54 +0200)]
gui: Make gsu_menu() private.

Its single caller is _browse(), which is a private function as
well. This patch prepends an underscore to the function name to
indicate that the function is not supposed to be called by application
code.

9 years agogui: Remove unused widgets.
Andre Noll [Mon, 1 Sep 2014 21:53:19 +0000 (23:53 +0200)]
gui: Remove unused widgets.

No application uses these public functions, so remove them for now.
They can be re-added on demand but for now they are just dead code.

9 years agoMerge branch 't/kill_pointless_subshell'
Andre Noll [Sat, 27 Sep 2014 23:00:45 +0000 (23:00 +0000)]
Merge branch 't/kill_pointless_subshell'

Cooking for almost a month.

* t/kill_pointless_subshell:
  subcommand: Overhaul _gsu_print_available_commands().

9 years agoMerge branch 't/default_gsu_dir'
Andre Noll [Sat, 27 Sep 2014 22:59:43 +0000 (22:59 +0000)]
Merge branch 't/default_gsu_dir'

Cooking for almost a month.

* t/default_gsu_dir:
  Unify gsu_dir handling.

9 years agoMerge branch 't/arithmetic_eval'
Andre Noll [Sat, 27 Sep 2014 22:58:16 +0000 (22:58 +0000)]
Merge branch 't/arithmetic_eval'

Cooking for almost a month.

* t/arithmetic_eval:
  Use modern style arithmetic evaluation everwhere.

9 years agoMerge branch 't/kill_gsu_self'
Andre Noll [Sat, 20 Sep 2014 08:09:24 +0000 (10:09 +0200)]
Merge branch 't/kill_gsu_self'

Cooking for three weeks.

* t/kill_gsu_self:
  Remove $_gsu_self.

Conflicts:
subcommand

9 years agoUse modern style arithmetic evaluation everwhere.
Andre Noll [Thu, 4 Sep 2014 07:01:48 +0000 (09:01 +0200)]
Use modern style arithmetic evaluation everwhere.

This is an equivalent transformation, and the new code is easier to
read and less error-prone.

9 years agoFix _gsu_banner_msg().
Andre Noll [Sun, 31 Aug 2014 17:06:40 +0000 (19:06 +0200)]
Fix _gsu_banner_msg().

This function did not print the banner at all. It also had only a
single caller. This patch removes the function and changes the single
caller to print the banner text.

9 years agoUnify gsu_dir handling.
Andre Noll [Sun, 31 Aug 2014 19:01:02 +0000 (21:01 +0200)]
Unify gsu_dir handling.

The three locations which include the common part of gsu need to know
the gsu installation directory. Currently we rely on the application
to set $gsu_dir. This is unnecessary since gsu can tell where it is
installed by examining ${BASH_SOURCE[0]}.

Also the fallback to $HOME/.gsu is not required. This commit unifies
all three locations and also calls _gsu_setup as early as possible:
when the gsu module is sourced.

9 years agoRemove $_gsu_self.
Andre Noll [Sun, 31 Aug 2014 16:54:09 +0000 (18:54 +0200)]
Remove $_gsu_self.

It has the same meaning as $gsu_name, so let's use $gsu_name
everywhere. Also avoid to call basename(1), as ${0##*/} does the same
and is cheaper.

9 years agosubcommand: Overhaul _gsu_print_available_commands().
Andre Noll [Sat, 30 Aug 2014 16:47:50 +0000 (18:47 +0200)]
subcommand: Overhaul _gsu_print_available_commands().

This function is rather confused. It uses gsu_short_msg() to print
the header to stderr while the list of subcommands is printed to
stdout. This is "fixed" by executing all commands in a subshell and
redirecting stderr to stdout.

It's easier to just print everything to stdout. This patch also
renames the loop variable i to cmd, declares $count as a local
integer variable and switches to single quoted string constants.

9 years agoMove all files to the top level directory.
Andre Noll [Sat, 30 Aug 2014 12:34:27 +0000 (14:34 +0200)]
Move all files to the top level directory.

With gsu being a separate repository, there is no point in burying
the gsu files below misc/gsu.

9 years agogsu: Document gsu().
Andre Noll [Fri, 29 Aug 2014 18:13:13 +0000 (20:13 +0200)]
gsu: Document gsu().

To get started, gsu application writers need to know how the gsu()
function works. So let's provide a small introduction here and a
minimal example.

9 years agogsu: Improve documentation of _gsu_get_command_regex().
Andre Noll [Tue, 26 Aug 2014 21:18:58 +0000 (23:18 +0200)]
gsu: Improve documentation of _gsu_get_command_regex().

Although this function is private, it is central to the subcommand
part of gsu and should thus be properly documented. The new text is
more precise about the meaning of the regular expression that is used
to identify subcommands.

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".