diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-03-10 15:44:28 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-03-10 15:44:28 +1300 |
commit | 3a5d35f8f6d31ca5d848eb6556285a58df4ee682 (patch) | |
tree | 11e9fc34b35b9069218407f068383c0886d89460 | |
parent | Handle default case correctly (diff) | |
download | dotfiles-3a5d35f8f6d31ca5d848eb6556285a58df4ee682.tar.gz dotfiles-3a5d35f8f6d31ca5d848eb6556285a58df4ee682.zip |
Local func var, simpler conditional
-rw-r--r-- | bash/bashrc.d/pd.bash | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/bash/bashrc.d/pd.bash b/bash/bashrc.d/pd.bash index 76316560..346816a1 100644 --- a/bash/bashrc.d/pd.bash +++ b/bash/bashrc.d/pd.bash @@ -4,7 +4,7 @@ # containing directory. In the absence of an argument, this just shifts up a # directory, i.e. `cd ..` pd() { - local arg + local arg target local -a opts for arg in "$@" ; do case $arg in @@ -21,21 +21,20 @@ pd() { ;; esac done - if (($#)) ; then - case $# in - 1) - target=$1 - target=${target%/} - target=${target%/*} - ;; - *) - printf 'bash: pd: too many arguments\n' >&2 - return 1 - ;; - esac - else - target=.. - fi + case $# in + 0) + target=.. + ;; + 1) + target=$1 + target=${target%/} + target=${target%/*} + ;; + *) + printf 'bash: pd: too many arguments\n' >&2 + return 1 + ;; + esac if [[ $target ]] ; then builtin cd "${opts[@]}" -- "$target" else |