aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-08-05 15:01:55 +1200
committerTom Ryder <tom@sanctum.geek.nz>2015-08-05 15:01:55 +1200
commit9c836bdb8802086f68c2b8a31e84fc66d10a7e73 (patch)
treeec394f1129b99db179564708bcb5c2e8658022f9 /bash
parentPass options to cd from ud (diff)
downloaddotfiles-9c836bdb8802086f68c2b8a31e84fc66d10a7e73.tar.gz
dotfiles-9c836bdb8802086f68c2b8a31e84fc66d10a7e73.zip
More intelligent trailing-slash filtering
Diffstat (limited to 'bash')
-rw-r--r--bash/bashrc.d/bd.bash4
-rw-r--r--bash/bashrc.d/path.bash17
2 files changed, 11 insertions, 10 deletions
diff --git a/bash/bashrc.d/bd.bash b/bash/bashrc.d/bd.bash
index 9ea0e3ca..2b0f1a53 100644
--- a/bash/bashrc.d/bd.bash
+++ b/bash/bashrc.d/bd.bash
@@ -31,9 +31,7 @@ bd() {
# The requested pattern is the first argument; strip trailing slashes if
# there are any
local req=$1
- if [[ $req != / ]] ; then
- req=${req%%/}
- fi
+ [[ $req != / ]] || req=${req%/}
# What to do now depends on the request
local dir
diff --git a/bash/bashrc.d/path.bash b/bash/bashrc.d/path.bash
index 80e45cc9..b1a0f9f0 100644
--- a/bash/bashrc.d/path.bash
+++ b/bash/bashrc.d/path.bash
@@ -52,6 +52,7 @@ path() {
IFS=: read -a patharr < <(printf '%s\n' "$PATH")
local dir
dir=$1
+ [[ $dir == / ]] || dir=${dir%/}
if [[ -z $dir ]] ; then
printf 'bash: %s: need a directory path to insert\n' \
"$FUNCNAME" >&2
@@ -82,6 +83,7 @@ path() {
IFS=: read -a patharr < <(printf '%s\n' "$PATH")
local dir
dir=$1
+ [[ $dir == / ]] || dir=${dir%/}
if [[ -z $dir ]] ; then
printf 'bash: %s: need a directory path to append\n' \
"$FUNCNAME" >&2
@@ -112,6 +114,7 @@ path() {
IFS=: read -a patharr < <(printf '%s\n' "$PATH")
local dir
dir=$1
+ [[ $dir == / ]] || dir=${dir%/}
if [[ -z $dir ]] ; then
printf 'bash: %s: need a directory path to remove\n' \
"$FUNCNAME" >&2
@@ -125,9 +128,8 @@ path() {
local -a newpatharr
local part
for part in "${patharr[@]}" ; do
- if [[ ${dir%/} != "${part%/}" ]] ; then
- newpatharr=("${newpatharr[@]}" "$part")
- fi
+ [[ $dir == "$part" ]] && continue
+ newpatharr=("${newpatharr[@]}" "$part")
done
path set "${newpatharr[@]}"
;;
@@ -135,9 +137,9 @@ path() {
# Set the PATH to the given directories without checking existence or uniqueness
set|s)
local -a newpatharr
- local part
- for part ; do
- newpatharr=("${newpatharr[@]}" "${part%/}")
+ local dir
+ for dir ; do
+ newpatharr=("${newpatharr[@]}" "$dir")
done
PATH=$(IFS=: ; printf '%s' "${newpatharr[*]}")
;;
@@ -148,6 +150,7 @@ path() {
IFS=: read -a patharr < <(printf '%s\n' "$PATH")
local dir
dir=$1
+ [[ $dir == / ]] || dir=${dir%/}
if [[ -z $dir ]] ; then
printf 'bash: %s: need a directory path to check\n' \
"$FUNCNAME" >&2
@@ -155,7 +158,7 @@ path() {
fi
local part
for part in "${patharr[@]}" ; do
- if [[ ${dir%/} == "${part%/}" ]] ; then
+ if [[ $dir == "$part" ]] ; then
return 0
fi
done