From 0b176721c3e82eafc467ba4a5e597f9cda8fa397 Mon Sep 17 00:00:00 2001 From: terminalforlife Date: Sat, 19 Dec 2020 02:15:42 +0000 Subject: [PATCH 1/3] Undo the `/bin/` prefix (see commit message) You can use an escape like \this to bypass an alias, running, just the command. I've also gone through each file (command) used, that I could see, at least, and done the same thing with those, to avoid aliases. --- bashmarks.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bashmarks.sh b/bashmarks.sh index b77a8c1..a613134 100644 --- a/bashmarks.sh +++ b/bashmarks.sh @@ -36,7 +36,7 @@ if [ ! -n "$SDIRS" ]; then SDIRS=~/.sdirs fi -touch $SDIRS +\touch $SDIRS RED="0;31m" GREEN="0;33m" @@ -102,15 +102,15 @@ function l { source $SDIRS # if color output is not working for you, comment out the line below '\033[1;32m' == "red" - env | sort | awk '/^DIR_.+/{split(substr($0,5),parts,"="); printf("\033[0;33m%-20s\033[0m %s\n", parts[1], parts[2]);}' + \env | \sort | \awk '/^DIR_.+/{split(substr($0,5),parts,"="); printf("\033[0;33m%-20s\033[0m %s\n", parts[1], parts[2]);}' # uncomment this line if color output is not working with the line above - # env | grep "^DIR_" | cut -c5- | sort |grep "^.*=" + # \env | \grep "^DIR_" | \cut -c5- | \sort | \grep "^.*=" } # list bookmarks without dirname function _l { source $SDIRS - env | grep "^DIR_" | cut -c5- | sort | grep "^.*=" | cut -f1 -d "=" + \env | \grep "^DIR_" | \cut -c5- | \sort | \grep "^.*=" | \cut -f1 -d "=" } # validate bookmark name @@ -144,14 +144,14 @@ function _purge_line { if [ -s "$1" ]; then # safely create a temp file t=$(mktemp -t bashmarks.XXXXXX) || exit 1 - trap "/bin/rm -f -- '$t'" EXIT + trap "\rm -f -- '$t'" EXIT # purge line sed "/$2/d" "$1" > "$t" - /bin/mv "$t" "$1" + \mv "$t" "$1" # cleanup temp file - /bin/rm -f -- "$t" + \rm -f -- "$t" trap - EXIT fi } From dea0aff520baff8149eb9d41d0eeafd2548f3073 Mon Sep 17 00:00:00 2001 From: terminalforlife Date: Sat, 19 Dec 2020 02:18:13 +0000 Subject: [PATCH 2/3] De-convolute test Double-negatives aren't fun; they should only be used if you must. The `-n` flag is for 'not empty' and `-z` is for 'empty'. --- bashmarks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bashmarks.sh b/bashmarks.sh index a613134..307b31a 100644 --- a/bashmarks.sh +++ b/bashmarks.sh @@ -33,7 +33,7 @@ # l - list all bookmarks # setup file to store bookmarks -if [ ! -n "$SDIRS" ]; then +if [ -z "$SDIRS" ]; then SDIRS=~/.sdirs fi \touch $SDIRS From 7843e8f82f50b1015343ceef4317dc8e28b6b611 Mon Sep 17 00:00:00 2001 From: terminalforlife Date: Sat, 19 Dec 2020 02:23:04 +0000 Subject: [PATCH 3/3] Remove trailing whitespaces & clean up a function --- bashmarks.sh | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/bashmarks.sh b/bashmarks.sh index 307b31a..29b7135 100644 --- a/bashmarks.sh +++ b/bashmarks.sh @@ -1,28 +1,28 @@ # Copyright (c) 2010, Huy Nguyen, http://www.huyng.com # All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, are permitted provided +# +# Redistribution and use in source and binary forms, with or without modification, are permitted provided # that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this list of conditions +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions # and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the # following disclaimer in the documentation and/or other materials provided with the distribution. # * Neither the name of Huy Nguyen nor the names of contributors -# may be used to endorse or promote products derived from this software without +# may be used to endorse or promote products derived from this software without # specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -# USAGE: +# USAGE: # s bookmarkname - saves the curr dir as bookmarkname # g bookmarkname - jumps to the that bookmark # g b[TAB] - tab completion is available @@ -85,32 +85,33 @@ function d { # print out help for the forgetful function check_help { - if [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ] ; then - echo '' - echo 's - Saves the current directory as "bookmark_name"' - echo 'g - Goes (cd) to the directory associated with "bookmark_name"' - echo 'p - Prints the directory associated with "bookmark_name"' - echo 'd - Deletes the bookmark' - echo 'l - Lists all available bookmarks' - kill -SIGINT $$ - fi + case $1 in + -h|-help|--help) + echo + echo 's - Saves the current directory as "bookmark_name"' + echo 'g - Goes (cd) to the directory associated with "bookmark_name"' + echo 'p - Prints the directory associated with "bookmark_name"' + echo 'd - Deletes the bookmark' + echo 'l - Lists all available bookmarks' + kill -SIGINT $$ ;; + esac } # list bookmarks with dirnam function l { check_help $1 source $SDIRS - + # if color output is not working for you, comment out the line below '\033[1;32m' == "red" \env | \sort | \awk '/^DIR_.+/{split(substr($0,5),parts,"="); printf("\033[0;33m%-20s\033[0m %s\n", parts[1], parts[2]);}' - + # uncomment this line if color output is not working with the line above - # \env | \grep "^DIR_" | \cut -c5- | \sort | \grep "^.*=" + # \env | \grep "^DIR_" | \cut -c5- | \sort | \grep "^.*=" } # list bookmarks without dirname function _l { source $SDIRS - \env | \grep "^DIR_" | \cut -c5- | \sort | \grep "^.*=" | \cut -f1 -d "=" + \env | \grep "^DIR_" | \cut -c5- | \sort | \grep "^.*=" | \cut -f1 -d "=" } # validate bookmark name