diff options
| author | Teddy Wing | 2016-07-21 18:39:48 -0400 |
|---|---|---|
| committer | Teddy Wing | 2016-07-21 18:39:48 -0400 |
| commit | 70fc8f255abee76abd646ff6dd8c7b1cd87f264e (patch) | |
| tree | 0b0790b662054a743f3f965d934ad2cd5a8615cd | |
| parent | e22a48f0d375d84fd22e7c4156ba224ec3d49275 (diff) | |
| download | qcd-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-x | qcd | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -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) ;; |
