From ca20e3e759d168a9f4dacdb05dad2a2b295f458b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 2 Jan 2017 15:50:52 +1300 Subject: Add marked-dir tools --- sh/shrc.d/xd.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 sh/shrc.d/xd.sh (limited to 'sh/shrc.d/xd.sh') diff --git a/sh/shrc.d/xd.sh b/sh/shrc.d/xd.sh new file mode 100644 index 00000000..01b8fd3a --- /dev/null +++ b/sh/shrc.d/xd.sh @@ -0,0 +1,24 @@ +# Swap current directory with marked directory +xd() { + + # Refuse to deal with unwanted arguments + if [ "$#" -gt 0 ] ; then + printf >&2 'gd(): Unspecified argument\n' + return 2 + fi + + # Complain if mark not actually set yet + if ! [ -n "$PMD" ] ; then + printf >&2 'gd(): Mark not set\n' + return 2 + fi + + # Put the current and marked directories into positional params + set -- "$PMD" "$PWD" + + # Try to change into the marked directory + cd -- "$1" || return + + # If that worked, we can swap the mark, and we're done + PMD=$2 +} -- cgit v1.2.3