aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-20 13:52:55 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-20 13:54:09 +1200
commita4e4cf23ca984e1fc7633b48f94c1795a5bc7ec8 (patch)
tree4084793d32dcc0264846cf8f1207722c56cec99c /bash
parentCorrectly bail from failed subshell (diff)
downloaddotfiles-a4e4cf23ca984e1fc7633b48f94c1795a5bc7ec8.tar.gz
dotfiles-a4e4cf23ca984e1fc7633b48f94c1795a5bc7ec8.zip
Port pd() to POSIX sh
Diffstat (limited to 'bash')
-rw-r--r--bash/bashrc.d/pd.bash53
1 files changed, 0 insertions, 53 deletions
diff --git a/bash/bashrc.d/pd.bash b/bash/bashrc.d/pd.bash
deleted file mode 100644
index 47a317e0..00000000
--- a/bash/bashrc.d/pd.bash
+++ /dev/null
@@ -1,53 +0,0 @@
-# Attempt to change into the argument's parent directory; preserve any options
-# and pass them to cd. This is intended for use when you've got a file path in
-# a variable, or in history, or in Alt+., and want to quickly move to its
-# containing directory. In the absence of an argument, this just shifts up a
-# directory, i.e. `cd ..`
-pd() {
-
- # For completeness' sake, we'll pass any options to cd
- local arg
- local -a opts
- for arg ; do
- case $arg in
- --)
- shift
- break
- ;;
- -*)
- shift
- opts[${#opts[@]}]=$arg
- ;;
- *)
- break
- ;;
- esac
- done
-
- # Determine target directory
- local target
- case $# in
- 0)
- target=..
- ;;
- 1)
- target=$1
- target=${target%/}
- target=${target%/*}
- ;;
- *)
- printf 'bash: %s: too many arguments\n' \
- "$FUNCNAME" >&2
- return 2
- ;;
- esac
-
- # If we have a target directory, try to change into it
- if [[ -n $target ]] ; then
- builtin cd "${opts[@]}" -- "$target"
- else
- printf 'bash: %s: error calculating parent directory\n' \
- "$FUNCNAME" >&2
- return 2
- fi
-}