From 5759ade2eb4c0c5ce24add4c9554cd1235f04bba Mon Sep 17 00:00:00 2001 From: William Melody Date: Mon, 29 Jun 2015 19:58:17 -0700 Subject: [PATCH 1/5] Add `brew tap` command to `brew install` in Readme. --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 7d1b80d..e4d229a 100644 --- a/Readme.md +++ b/Readme.md @@ -14,7 +14,7 @@ A command line program with shortcuts for managing hosts file entries. To install with [Homebrew](http://brew.sh/): - brew install alphabetum/taps/hosts + brew tap alphabetum/taps && brew install alphabetum/taps/hosts ### bpkg From 12d11c2dc38fe45e88f8d6086fdc38ca8b63f20c Mon Sep 17 00:00:00 2001 From: William Melody Date: Fri, 11 Sep 2015 19:43:56 -0700 Subject: [PATCH 2/5] Declare and assign separately to avoid masking return values. ShellCheck SC2155 --- hosts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/hosts b/hosts index 97b7de0..893f05b 100755 --- a/hosts +++ b/hosts @@ -679,7 +679,8 @@ add() { else if [[ -n ${comment} ]] then - local formatted_comment=$(_join " " "${comment[@]}") + local formatted_comment + formatted_comment=$(_join " " "${comment[@]}") printf "%s\t%s\t# %s\n" \ "${ip}" \ "${hostname}" \ @@ -712,7 +713,8 @@ disable() { else _debug printf "disable() \$search_term: %s\n" "$search_term" - local targets=$( + local targets + targets=$( sed -n "s/^\([^#]*${search_term}.*\)$/\1/p" "${HOSTS_PATH}" ) _debug printf "disable() \$targets: %s\n" "$targets" @@ -777,7 +779,8 @@ enable() { else local target_regex="s/^\#disabled: \(.*${search_term}.*\)$/\1/" - local targets=$(sed -n "${target_regex}p" "${HOSTS_PATH}") + local targets + targets=$(sed -n "${target_regex}p" "${HOSTS_PATH}") printf "Enabling:\n%s\n" "${targets}" # -i '' - in place edit. BSD sed requires extension argument, for GNU @@ -825,7 +828,8 @@ Description: EOM list() { # Get the disabled records up front for the two cases where they are needed. - local disabled_records=$( + local disabled_records + disabled_records=$( sed -n "s/^\#disabled: \(.*\)$/\1/p" "${HOSTS_PATH}" ) @@ -872,7 +876,8 @@ remove() { $_ME help remove exit 1 else - local target_records=$( + local target_records + target_records=$( sed -n "s/^\(.*${search_string}.*\)$/\1/p" "${HOSTS_PATH}" ) @@ -921,10 +926,12 @@ show() { if [[ -n "$1" ]] then # Run `sed` before `grep` to avoid conflict that supress `sed` output. - local disabled_records=$( + local disabled_records + disabled_records=$( sed -n "s/^\#\(disabled: .*$1.*\)$/\1/p" "${HOSTS_PATH}" ) - local enabled_records=$( + local enabled_records + enabled_records=$( grep "^[^#]*$1" "${HOSTS_PATH}" ) # Output disabled records secondly for better organization. From 590d75096fa0a7503784584598c8362626bea846 Mon Sep 17 00:00:00 2001 From: William Melody Date: Fri, 11 Sep 2015 19:47:52 -0700 Subject: [PATCH 3/5] Print confirmation feedback in `add` on success. --- hosts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hosts b/hosts index 893f05b..ebc8d19 100755 --- a/hosts +++ b/hosts @@ -685,10 +685,17 @@ add() { "${ip}" \ "${hostname}" \ "${formatted_comment}" >> "${HOSTS_PATH}" + printf "Added:\n%s\t%s\t# %s\n" \ + "${ip}" \ + "${hostname}" \ + "${formatted_comment}" else printf "%s\t%s\n" \ "${ip}" \ "${hostname}" >> "${HOSTS_PATH}" + printf "Added:\n%s\t%s\n" \ + "${ip}" \ + "${hostname}" fi fi } From 62f200574d1839acc061beb332570556264018ab Mon Sep 17 00:00:00 2001 From: William Melody Date: Fri, 11 Sep 2015 19:51:02 -0700 Subject: [PATCH 4/5] Bump version to 1.5.0 --- hosts | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hosts b/hosts index ebc8d19..3eb6a2d 100755 --- a/hosts +++ b/hosts @@ -36,7 +36,7 @@ IFS=$'\n\t' # Globals ############################################################################### -_VERSION="1.4.3" +_VERSION="1.5.0" # DEFAULT_COMMAND # diff --git a/package.json b/package.json index 86fd0b2..a4e2e3a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hosts", - "version": "1.4.3", + "version": "1.5.0", "description": "A command line tool for managing hosts file entries.", "global": true, "install": "make install" From 8465c2bdf84c4e7836d33032d541ead75456e686 Mon Sep 17 00:00:00 2001 From: William Melody Date: Sat, 12 Sep 2015 13:19:17 -0700 Subject: [PATCH 5/5] Exit with "Not found" message on failed search in `enable`/`disable` When the search string in `enable` or `disable` is not found, exit the program and provide feedback rather than silently failing. --- hosts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hosts b/hosts index 3eb6a2d..b726772 100755 --- a/hosts +++ b/hosts @@ -725,6 +725,10 @@ disable() { sed -n "s/^\([^#]*${search_term}.*\)$/\1/p" "${HOSTS_PATH}" ) _debug printf "disable() \$targets: %s\n" "$targets" + if [[ -z "${targets}" ]] + then + _die printf "Not found: %s\n" "${search_term}" + fi printf "Disabling:\n%s\n" "${targets}" @@ -788,6 +792,12 @@ enable() { local targets targets=$(sed -n "${target_regex}p" "${HOSTS_PATH}") + _debug printf "enable() \$targets: %s\n" "$targets" + if [[ -z "${targets}" ]] + then + _die printf "Not found: %s\n" "${search_term}" + fi + printf "Enabling:\n%s\n" "${targets}" # -i '' - in place edit. BSD sed requires extension argument, for GNU