aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-20 12:29:24 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-20 12:43:48 +1200
commit416fc33ff1e9e034cf2bb4a58bb177f46606afd5 (patch)
treee067bc1c8c7af4bb7267b0b691b8b1a7fe832bb7 /bash/bashrc.d
parentRemove option term spec from bd() (diff)
downloaddotfiles-416fc33ff1e9e034cf2bb4a58bb177f46606afd5.tar.gz
dotfiles-416fc33ff1e9e034cf2bb4a58bb177f46606afd5.zip
Port ud() to POSIX sh
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r--bash/bashrc.d/ud.bash50
1 files changed, 0 insertions, 50 deletions
diff --git a/bash/bashrc.d/ud.bash b/bash/bashrc.d/ud.bash
deleted file mode 100644
index e23de1fa..00000000
--- a/bash/bashrc.d/ud.bash
+++ /dev/null
@@ -1,50 +0,0 @@
-# Shortcut to step up the directory tree with an arbitrary number of steps,
-# like cd .., cd ../.., etc
-ud() {
-
- # 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
-
- # Check and save optional first argument, number of steps upward; default
- # to 1 if absent
- local -i steps
- steps=${1:-1}
- if ! ((steps > 0)) ; then
- printf 'bash: %s: Invalid step count %s\n' "$FUNCNAME" "$1" >&2
- return 2
- fi
-
- # Check and save optional second argument, target directory; default to
- # $PWD (typical usage case)
- local dirname
- dirname=${2:-"$PWD"}
- if [[ ! -e $dirname ]] ; then
- printf 'bash: %s: Target directory %s does not exist\n' "$FUNCNAME" "$2" >&2
- return 1
- fi
-
- # Append /.. to the target the specified number of times
- local -i i
- for (( i = 0 ; i < steps ; i++ )) ; do
- dirname=${dirname%/}/..
- done
-
- # Try to change into it
- cd "${opts[@]}" -- "$dirname"
-}