aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-07-21 18:39:48 -0400
committerTeddy Wing2016-07-21 18:39:48 -0400
commit70fc8f255abee76abd646ff6dd8c7b1cd87f264e (patch)
tree0b0790b662054a743f3f965d934ad2cd5a8615cd
parente22a48f0d375d84fd22e7c4156ba224ec3d49275 (diff)
downloadqcd-70fc8f255abee76abd646ff6dd8c7b1cd87f264e.tar.bz2
qcd: Initial "add" command implementation
Add the specified shortcut and path to the database file. Expand the given path to an absolute path so that it can be used from any working directory. Used "andsens"' answer on Stack Overflow for getting the absolute path: http://stackoverflow.com/questions/7126580/expand-a-possible-relative-path-in-bash/17076258#17076258
-rwxr-xr-xqcd8
1 files changed, 8 insertions, 0 deletions
diff --git a/qcd b/qcd
index 5c5d1aa..a4ee215 100755
--- a/qcd
+++ b/qcd
@@ -22,6 +22,10 @@ Usage:
__EOF__
}
+function absolute_path () {
+ (cd "$(dirname '$1')" &>/dev/null && printf "%s/%s" "$PWD" "${1##*/}")
+}
+
function qcd () {
if [[ $# < 1 ]]; then
print_usage
@@ -32,6 +36,10 @@ function qcd () {
case $command in
-a)
+ local shortcut=$2
+ local path=$3
+
+ echo "${shortcut} $(absolute_path ${path})" >> $QCD_DATABASE_FILE
;;
-c)
;;