diff options
| author | Miquel Sabaté <msabate@suse.com> | 2015-08-24 14:45:52 +0200 |
|---|---|---|
| committer | Miquel Sabaté <msabate@suse.com> | 2015-08-24 14:45:52 +0200 |
| commit | 0fb2e6602de1719e643954fe707961ff6cbbd201 (patch) | |
| tree | ffe77f22becb1dffafb5ca46016045eb42ee2a22 | |
| parent | deefef53041e15eb3e0c42dc9374179735f760fd (diff) | |
| download | g-0fb2e6602de1719e643954fe707961ff6cbbd201.tar.gz g-0fb2e6602de1719e643954fe707961ff6cbbd201.zip | |
More fixes bash vs zsh
| -rw-r--r-- | g.sh | 12 | ||||
| -rw-r--r-- | t/tests.sh | 2 |
2 files changed, 10 insertions, 4 deletions
@@ -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] <command> [<args>]" @@ -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")" } @@ -17,7 +17,7 @@ set -e # From g.sh __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")" } |
