aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-07-21 23:20:37 -0400
committerTeddy Wing2016-07-21 23:20:37 -0400
commit30fcb9ed86d95be7c33f527f04e167682728627a (patch)
tree4627a2acc8eced19ca86775962e9dbebbf12fc15
parentf0189d6dc374b4238892e3309e116317a6d8c48c (diff)
downloadqcd-30fcb9ed86d95be7c33f527f04e167682728627a.tar.bz2
qcd: Enable `cd` into paths with spaces
Previously, the `awk` command would only print out the second column, meaning that if we had a database entry like: qproj /Users/user/code/Q Proj `awk` would give us: /Users/user/code/Q (missing the " Proj" part). Output all columns except the first using this `awk` substitution by Ed Morton on Stack Overflow: http://stackoverflow.com/questions/2626274/print-all-but-the-first-three-columns/18819899#18819899
-rwxr-xr-xqcd6
1 files changed, 4 insertions, 2 deletions
diff --git a/qcd b/qcd
index 8f97611..0afce74 100755
--- a/qcd
+++ b/qcd
@@ -68,10 +68,12 @@ function change_directory () {
local shortcut=$1
if shortcut_exists $shortcut; then
- cd $(awk -v shortcut="$shortcut" '{
+ local directory=$(awk -v shortcut="$shortcut" '{
if ($1 == shortcut)
- { print $2 }
+ { sub(/[[:space:]]*([^[:space:]]+[[:space:]]+)/,""); print }
}' $QCD_DATABASE_FILE)
+
+ cd "$directory"
fi
}