aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-07-21 22:13:52 -0400
committerTeddy Wing2016-07-21 22:13:52 -0400
commit8f564b8615336e15d5ffb01ee0bc8622a32e8031 (patch)
treebbd94a09790dd0831972cc4c994b246f515bc433
parentf4f96bd6be1bce5f4a5c3d128e1ce3e2f480595f (diff)
downloadqcd-8f564b8615336e15d5ffb01ee0bc8622a32e8031.tar.bz2
qcd: Move "add" and "change" commands to their own functions
To make things cleaner, don't put the body of these commands directly in the main `case` statement. Instead, put them in their own named functions.
-rwxr-xr-xqcd38
1 files changed, 24 insertions, 14 deletions
diff --git a/qcd b/qcd
index efb0f59..07a653b 100755
--- a/qcd
+++ b/qcd
@@ -35,6 +35,26 @@ function shortcut_exists () {
return $(awk '{ print $1 }' $QCD_DATABASE_FILE | grep "^${shortcut}$" >/dev/null 2>&1; echo $?)
}
+function add_shortcut () {
+ local shortcut=$1
+ local path=$2
+
+ # Don't add the shortcut if it already exists
+ if ! shortcut_exists $shortcut; then
+ echo "${shortcut} $(absolute_path ${path})" >> $QCD_DATABASE_FILE
+ fi
+}
+
+function change_shortcut () {
+ local shortcut=$1
+ local path=$2
+
+ if shortcut_exists $shortcut; then
+ path=$(absolute_path $path)
+ sed -i.bak -E "s/^${shortcut} .+$/${shortcut} ${path//\//\/}/" $QCD_DATABASE_FILE
+ fi
+}
+
function qcd () {
if [[ $# < 1 ]]; then
print_usage
@@ -44,25 +64,15 @@ function qcd () {
# setup
local command=$1
+ local shortcut=$2
+ local path=$3
case $command in
-a)
- local shortcut=$2
- local path=$3
-
- # Don't add the shortcut if it already exists
- if ! shortcut_exists $shortcut; then
- echo "${shortcut} $(absolute_path ${path})" >> $QCD_DATABASE_FILE
- fi
+ add_shortcut $shortcut $path
;;
-c)
- local shortcut=$2
- local path=$3
-
- if shortcut_exists $shortcut; then
- path=$(absolute_path $path)
- sed -i.bak -E "s/^${shortcut} .+$/${shortcut} ${path//\//\/}/" $QCD_DATABASE_FILE
- fi
+ change_shortcut $shortcut $path
;;
-r)
;;