diff options
| author | Miquel Sabaté <msabate@suse.com> | 2015-07-29 10:24:14 +0200 |
|---|---|---|
| committer | Miquel Sabaté <msabate@suse.com> | 2015-07-29 10:24:14 +0200 |
| commit | ebe139b64189e75f0fb163095c5069fc5094d235 (patch) | |
| tree | 9efa9fc802e7aabe06e82e0961e8ed9aceff2e2d | |
| parent | e554081033930579134b0ca42ff80e269e10beb8 (diff) | |
| download | g-ebe139b64189e75f0fb163095c5069fc5094d235.tar.gz g-ebe139b64189e75f0fb163095c5069fc5094d235.zip | |
Allow relative paths after the given shortcut
If we have a directory /home/mssola/a/b/c, and we have a shortcut named 'b'
that points to b, then the following now works:
$ g b/c
Note that the completion script is yet to be updated
| -rw-r--r-- | g.sh | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -1,4 +1,3 @@ -# # Copyright (C) 2013-2015 Miquel Sabaté Solà <mikisabate@gmail.com> # # This program is free software; you can redistribute it and/or modify @@ -74,9 +73,15 @@ __g_is_keyword() { esac } +# It returns a string with all the elements of the given array joined by slash +# characters. +__g_join_path() { + local IFS="/"; echo "$*"; +} + # The main function for this script. g() { - version="0.3.6" + version="0.3.7" cmd="$1" __g_file=$HOME/.gfile declare -A __g_shortcuts @@ -139,12 +144,20 @@ g() { ;; *) __g_get_shortcuts - if [ -z ${__g_shortcuts[$cmd]} ]; then - echo -e "Unknown shortcut \`$cmd'.\n" + + # Split the path and check whether the first element is a shortcut or + # not. + IFS='/' read -a path <<< $cmd + init=${path[0]} + + if [ -z ${__g_shortcuts[$init]} ]; then + echo -e "Unknown shortcut \`$init'.\n" __g_usage return 1 else - cd ${__g_shortcuts[$cmd]} + # Expand the shortcut and append the remaining parts of the path. + path[0]="${__g_shortcuts[$init]}" + cd $(__g_join ${path[@]}) fi ;; esac |
