Use `unset` to remove the first element of `$_COMMAND_PARAMETERS` rather
than slicing because under bash 3.2 the resulting slice is treated as a
quoted string and doesn't easily get coaxed back into an array.
Since the regular expressions are essentially repeated, with the only
difference being the capturing groups that have no impact on the delete
operations, assign them to a set of descriptive variables. This makes
things more organized and additionally provides some explanation for
what each regular expression is matching against.
This provides a mechanism for removing exact IP and hostname pairs.
The existing search string functionality should continue to function as
it did previously.
The `disable` regular expressions avoid matching against commented lines
by excluding '#' characters at the beginning of the line. However, the
IP portion of the record is at the beginning of non-commented lines, so
in order to match these IPs the `target_regex_ip` needs to have the
search term checked against the beginning of the line. Therefore, the
`[^#]` at the beginning of `target_regex_ip` must be removed to make
`search_term` properly match these IPs.
These variables are used within regular expressions, but as the program
evolves they are not always in constant use. Exporting these variables
silences ShellCheck warnings and makes them available to subshells.
This is an application of the approach to `sed` calls that was included
in 94ca8bf
In order to make editing more precise, `sed` regular expressions only
match exact occurrences of the search string within each entry column.
* master:
Exit with "Not found" message on failed search in `enable`/`disable`
Bump version to 1.5.0
Print confirmation feedback in `add` on success.
Declare and assign separately to avoid masking return values.
Add `brew tap` command to `brew install` in Readme.
In order to make editing more precise, sed regular expressions only
match exact occurrences of the search string within each entry column.
In order to properly handle tab and space separators in a portable
manner, a set of global variables are included that provide strings
of those characters.
The capitalized version of this variable makes it easier to override,
even though this is not technically part of the external API. There is
no known downside of using the capitalized version of the variable.
This addition requires a number of changes including:
- the addition of a new `_join` function
- reformatting of the `add` function to facilitate the longer lines
These comments can be found in the bash-boilerplate project and aren't
necessary here. Since the $DEFAULT_IFS doesn't appear to be used,
either, the $IFS setting can be reduced to a since simple assignment.
When disabled records are present, include them in a new section in the
default output of `list`. If no disabled records are present, don't
include the section.
These commands make it possible to disable records without fully
removing them. To 'disable' a record, it simply is commented out with
the following pattern `#disabled: ` prepended to the line.
Displaying a record pair for a hostname or IP address is likely a common
operation, and using the `show` name makes it clear what the primary
function of the command is. Since record pairs are very simple, the
easiest way to allow both hostname and ip address arguments is to use
grep, which also provides general search-like functionality. In order to
avoid doubling this functionality, use the `show` command in the `list`
command for search.
When using the pattern of blanking the lines first and then deleting
the blank lines, the program ends up deleting potentially intentional
blank lines. In order to avoid this, use a simple delete rather than the
blanking + blank line deleting pattern.
This program contains the same functionality as previous iterations,
with several changes:
- move to command-based structure using the bash boilerplate template,
- inlcude basic error handling,
- revise variable naming and options for clarity,
- prefer `printf` over `echo`,
- misc other revisions.