aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-07-21 21:20:55 -0400
committerTeddy Wing2016-07-21 21:20:55 -0400
commit594318f73b5188f3d3bebfbcd9f08b69993615fa (patch)
treee17a97233eb59cee38923c195a52bd415042e12a
parent260882fdaf5441140469a35ec954818b7b1100b2 (diff)
downloadqcd-594318f73b5188f3d3bebfbcd9f08b69993615fa.tar.bz2
qcd: Only add shortcut to database if it's new
If an existing shortcut in the database matches the one you're trying to add, it doesn't get added. In the future we might want to output an error message to let users know that there was a problem.
-rwxr-xr-xqcd10
1 files changed, 9 insertions, 1 deletions
diff --git a/qcd b/qcd
index 1b0cd3d..ebd68a4 100755
--- a/qcd
+++ b/qcd
@@ -30,6 +30,11 @@ function absolute_path () {
(cd "$(dirname '$1')" &>/dev/null && printf "%s/%s" "$PWD" "${1##*/}")
}
+function find_shortcut () {
+ local shortcut=$1
+ return $(awk '{ print $1 }' $QCD_DATABASE_FILE | grep "^${shortcut}$" >/dev/null 2>&1; echo $?)
+}
+
function qcd () {
if [[ $# < 1 ]]; then
print_usage
@@ -45,7 +50,10 @@ function qcd () {
local shortcut=$2
local path=$3
- echo "${shortcut} $(absolute_path ${path})" >> $QCD_DATABASE_FILE
+ # Don't add the shortcut if it already exists
+ if ! find_shortcut $shortcut; then
+ echo "${shortcut} $(absolute_path ${path})" >> $QCD_DATABASE_FILE
+ fi
;;
-c)
;;