aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/lgt.sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-03-29 15:27:56 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-03-29 15:27:56 +1300
commitfb2b15e272e7c29348f1d23bd717d52cd6b69660 (patch)
treea2c9a933d7e9a8cce6d68d59b6612216a357a0b9 /sh/shrc.d/lgt.sh
parentMerge branch 'master' into port/bsd/freebsd (diff)
parentRemove SC2030 ignore for path logic (diff)
downloaddotfiles-fb2b15e272e7c29348f1d23bd717d52cd6b69660.tar.gz
dotfiles-fb2b15e272e7c29348f1d23bd717d52cd6b69660.zip
Merge branch 'master' into port/bsd/freebsd
Diffstat (limited to 'sh/shrc.d/lgt.sh')
-rw-r--r--sh/shrc.d/lgt.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/sh/shrc.d/lgt.sh b/sh/shrc.d/lgt.sh
new file mode 100644
index 00000000..fbe43369
--- /dev/null
+++ b/sh/shrc.d/lgt.sh
@@ -0,0 +1,28 @@
+# Run loc(1df) with given arguments and then run gt() to get to the first
+# argument found
+lgt() {
+
+ # Check argument count
+ if [ "$#" -eq 0 ] ; then
+ printf >&2 'lgt(): Need a search term\n'
+ return 2
+ fi
+
+ # Change the positional parameters from the loc(1df) arguments to the first
+ # result with a trailing slash
+ set -- "$(
+ loc "$@" | {
+ IFS= read -r target
+ printf '%s/' "$target"
+ }
+ )"
+
+ # Strip the trailing slash
+ set -- "${1%/}"
+
+ # If the subshell printed nothing, return with failure
+ [ -n "$1" ] || return
+
+ # Run gt() with the new arguments
+ gt "$@"
+}