aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.markdown4
-rwxr-xr-xbin/exm6
-rw-r--r--ksh/shrc.d/ksh.sh1
-rw-r--r--man/man1/exm.1df4
-rw-r--r--sh/shrc.d/gt.sh28
-rw-r--r--sh/shrc.d/lgt.sh28
-rw-r--r--sh/shrc.d/path.sh1
m---------vim/bundle/targets0
8 files changed, 65 insertions, 7 deletions
diff --git a/README.markdown b/README.markdown
index 8b95e1a9..43dddf0c 100644
--- a/README.markdown
+++ b/README.markdown
@@ -180,10 +180,12 @@ in `sh/shrc.d` to be loaded by any POSIX interactive shell. Those include:
* `gd()` goes to the marked directory.
* `pmd()` prints the marked directory.
* `xd()` swaps the current and marked directories.
-* Nine other directory management and navigation functions:
+* Ten other directory management and navigation functions:
* `ad()` is a `cd` shortcut accepting targets like `/u/l/b` for
`/usr/local/bin`, as long as they are unique.
* `bd()` changes into a named ancestor of the current directory.
+ * `gt()` changes into a directory or into a file's directory.
+ * `lgt()` runs `gt()` on the first result from a `loc(1df)` search.
* `mkcd()` creates a directory and changes into it.
* `pd()` changes to the argument's parent directory.
* `rd()` replaces the first instance of its first argument with its
diff --git a/bin/exm b/bin/exm
index 4631c8fa..3f4b4c1b 100755
--- a/bin/exm
+++ b/bin/exm
@@ -4,8 +4,10 @@ if [ -t 0 ] ; then
ver=$(ex --version 2>/dev/null | sed '1{s/ .*//;q;}')
case $ver in
# Lie to Vim; tell it it's a dumb terminal, and that its required "cm"
- # feature is invoked with a newline character.
- VIM) set -- -T dumb --cmd 'exe "set t_cm=\<C-M>"' "$@" ;;
+ # feature is invoked with a carriage return.
+ VIM)
+ cmd=$(printf 'set t_cm=\r|')
+ set -- -T dumb --cmd "${cmd%|}" "$@" ;;
esac
fi
exec ex "$@"
diff --git a/ksh/shrc.d/ksh.sh b/ksh/shrc.d/ksh.sh
index 6101fc84..aa5c4cbc 100644
--- a/ksh/shrc.d/ksh.sh
+++ b/ksh/shrc.d/ksh.sh
@@ -21,7 +21,6 @@ if [ -z "$KSH_VERSION" ] ; then
# Test whether we have content in the .sh.version variable. Suppress errors
# and run it in a subshell to work around parsing error precedence.
- # shellcheck disable=SC2154
( test -n "${.sh.version}" ) 2>/dev/null || return
# If that peculiarly named variable was set, then that's our KSH_VERSION
diff --git a/man/man1/exm.1df b/man/man1/exm.1df
index 7a68a031..25b3cf4a 100644
--- a/man/man1/exm.1df
+++ b/man/man1/exm.1df
@@ -8,8 +8,8 @@
.SH DESCRIPTION
.B exm
works around a quirk of Vim that causes it to clear the screen when invoked as
-ex(1) interactively. It applies Vim's -T option to force the terminal to the
-builtin "dumb" terminal.
+ex(1) interactively. It applies Vim's -T option to force the terminal to a
+"dumb" terminal.
.SH CAVEATS
This breaks switching to visual mode with :visual completely, as the terminal
will persist in its dumb state. I'm not sure there's a way to fix this. If
diff --git a/sh/shrc.d/gt.sh b/sh/shrc.d/gt.sh
new file mode 100644
index 00000000..d18a4ab8
--- /dev/null
+++ b/sh/shrc.d/gt.sh
@@ -0,0 +1,28 @@
+# If the argument is a directory, change to it. If it's a file, change to its
+# parent. Stands for "get to".
+gt() {
+
+ # Check argument count
+ if [ "$#" -gt 1 ] ; then
+ printf >&2 'gd(): Too many arguments\n'
+ return 2
+ fi
+
+ # Strip trailing slash
+ set -- "${1%/}"
+
+ # If target doesn't have a leading slash, add PWD prefix
+ case $1 in
+ /*) ;;
+ *) set -- "${PWD%/}"/"$1"
+ esac
+
+ # If target isn't a directory, chop to its parent
+ [ -d "$1" ] || set -- "${1%/*}"
+
+ # If target is now empty, go to the root
+ [ -n "$1" ] || set -- /
+
+ # Try to change into the determined directory
+ command cd -- "$@"
+}
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 "$@"
+}
diff --git a/sh/shrc.d/path.sh b/sh/shrc.d/path.sh
index 79b48fd5..b6b1820f 100644
--- a/sh/shrc.d/path.sh
+++ b/sh/shrc.d/path.sh
@@ -6,7 +6,6 @@ path() {
# List current directories in PATH
list|'') (
- # shellcheck disable=SC2030
path=$PATH:
while [ -n "$path" ] ; do
dir=${path%%:*}
diff --git a/vim/bundle/targets b/vim/bundle/targets
-Subproject f8b2d4bd21ea73ebe8eaa3e9f9bdc1b42d1b7b4
+Subproject 050335f848d57cb1c59bffe6f32f901307b7e50