aboutsummaryrefslogtreecommitdiff
path: root/g.sh
diff options
context:
space:
mode:
authorMiquel Sabaté <msabate@suse.com>2015-07-28 10:01:01 +0200
committerMiquel Sabaté <msabate@suse.com>2015-07-28 10:01:01 +0200
commit8b873f3d5e4b9f01634fdc886109d7ba90d2e545 (patch)
treeaa16741245daf2b4644472ba9bd3e37ee41ba91d /g.sh
parente7acbf93173469f8dd450961419a1f36c5adf555 (diff)
downloadg-8b873f3d5e4b9f01634fdc886109d7ba90d2e545.tar.gz
g-8b873f3d5e4b9f01634fdc886109d7ba90d2e545.zip
Don't allow the user to add shortcuts whose name conflict with commands
Diffstat (limited to 'g.sh')
-rw-r--r--g.sh17
1 files changed, 16 insertions, 1 deletions
diff --git a/g.sh b/g.sh
index 7066319..4713780 100644
--- a/g.sh
+++ b/g.sh
@@ -63,9 +63,20 @@ save_shortcuts() {
done
}
+# Returns true if the given parameter is a keyword, false otherwise.
+is_keyword() {
+ case "$1" in
+ add | rm | list | -v | --version | -h | --help)
+ return 0
+ ;;
+ *)
+ return 1
+ esac
+}
+
# The main function for this script.
g() {
- version="0.3.3"
+ version="0.3.4"
cmd="$1"
gfile=$HOME/.gfile
declare -A gshortcuts
@@ -95,6 +106,10 @@ g() {
return
fi
fi
+ if is_keyword $2; then
+ echo "Cannot use '$2': keyword."
+ return
+ fi
get_shortcuts
gshortcuts[$2]=$path
save_shortcuts