From 8b873f3d5e4b9f01634fdc886109d7ba90d2e545 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Date: Tue, 28 Jul 2015 10:01:01 +0200 Subject: Don't allow the user to add shortcuts whose name conflict with commands --- g.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'g.sh') 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 -- cgit v1.2.3