diff options
| author | Teddy Wing | 2016-07-21 21:20:55 -0400 |
|---|---|---|
| committer | Teddy Wing | 2016-07-21 21:20:55 -0400 |
| commit | 594318f73b5188f3d3bebfbcd9f08b69993615fa (patch) | |
| tree | e17a97233eb59cee38923c195a52bd415042e12a | |
| parent | 260882fdaf5441140469a35ec954818b7b1100b2 (diff) | |
| download | qcd-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-x | qcd | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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) ;; |
