aboutsummaryrefslogtreecommitdiff
path: root/g.sh
diff options
context:
space:
mode:
authorMiquel Sabaté <msabate@suse.com>2015-08-24 14:45:52 +0200
committerMiquel Sabaté <msabate@suse.com>2015-08-24 14:45:52 +0200
commit0fb2e6602de1719e643954fe707961ff6cbbd201 (patch)
treeffe77f22becb1dffafb5ca46016045eb42ee2a22 /g.sh
parentdeefef53041e15eb3e0c42dc9374179735f760fd (diff)
downloadg-0fb2e6602de1719e643954fe707961ff6cbbd201.tar.gz
g-0fb2e6602de1719e643954fe707961ff6cbbd201.zip
More fixes bash vs zsh
Diffstat (limited to 'g.sh')
-rw-r--r--g.sh12
1 files changed, 9 insertions, 3 deletions
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] <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")"
}