From 0fb2e6602de1719e643954fe707961ff6cbbd201 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Date: Mon, 24 Aug 2015 14:45:52 +0200 Subject: More fixes bash vs zsh --- g.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'g.sh') diff --git a/g.sh b/g.sh index b3cc3cc..8a487a9 100644 --- a/g.sh +++ b/g.sh @@ -14,7 +14,6 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - # Print the usage string. __g_usage() { echo "usage: g [-h | --help] [-v | --version] []" @@ -55,8 +54,15 @@ __g_save_shortcuts() { # Erase the contents of the __g_file. :>$__g_file + # Bash vs zsh + if [ -n "$ZSH_VERSION" ]; then + keys="${(@i)__g_shortcuts}" + else + keys="${!__g_shortcuts[@]}" + fi + # Finally write the hash into the __g_file. - for i in "${!__g_shortcuts[@]}"; do + for i in $keys; do echo "$i" >> $__g_file echo "${__g_shortcuts[$i]}" >> $__g_file done @@ -82,7 +88,7 @@ __g_join_path() { # Replacement for the non-standard `realpath` command. Implemented taken from # https://github.com/travis-ci/gimme. __g_realpath() { - [ -d "$1" ] && echo "$(cd "$1" && pwd)" || echo "$(cd "$(dirname "$1")" + [ -d "$1" ] && echo "$(cd "$1" && pwd)" || echo "$(cd "$(dirname "$1")" \ && pwd)/$(basename "$1")" } -- cgit v1.2.3