support multiple paths in pathmunge
parent
4365fa8d69
commit
79ca9a708d
|
|
@ -680,12 +680,18 @@ then
|
||||||
example 'pathmunge /path/to/dir is equivalent to PATH=/path/to/dir:$PATH'
|
example 'pathmunge /path/to/dir is equivalent to PATH=/path/to/dir:$PATH'
|
||||||
example 'pathmunge /path/to/dir after is equivalent to PATH=$PATH:/path/to/dir'
|
example 'pathmunge /path/to/dir after is equivalent to PATH=$PATH:/path/to/dir'
|
||||||
|
|
||||||
if ! [[ $PATH =~ (^|:)$1($|:) ]] ; then
|
IFS=':' local -a 'a=($1)'
|
||||||
if [ "$2" = "after" ] ; then
|
local i=${#a[@]}
|
||||||
export PATH=$PATH:$1
|
while [[ $i -gt 0 ]] ; do
|
||||||
else
|
i=$(( i - 1 ))
|
||||||
export PATH=$1:$PATH
|
p=${a[i]}
|
||||||
|
if ! [[ $PATH =~ (^|:)$p($|:) ]] ; then
|
||||||
|
if [[ "$2" = "after" ]] ; then
|
||||||
|
export PATH=$PATH:$p
|
||||||
|
else
|
||||||
|
export PATH=$p:$PATH
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
done
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,39 @@ function local_setup {
|
||||||
assert_failure
|
assert_failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test 'helpers: pathmunge: ensure function is defined' {
|
||||||
|
run type -t pathmunge
|
||||||
|
assert_line 'function'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'helpers: pathmunge: single path' {
|
||||||
|
new_paths='/tmp/fake-pathmunge-path'
|
||||||
|
old_path="${PATH}"
|
||||||
|
pathmunge "${new_paths}"
|
||||||
|
assert_equal "${new_paths}:${old_path}" "${PATH}"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'helpers: pathmunge: single path, with space' {
|
||||||
|
new_paths='/tmp/fake pathmunge path'
|
||||||
|
old_path="${PATH}"
|
||||||
|
pathmunge "${new_paths}"
|
||||||
|
assert_equal "${new_paths}:${old_path}" "${PATH}"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'helpers: pathmunge: multiple paths' {
|
||||||
|
new_paths='/tmp/fake-pathmunge-path1:/tmp/fake-pathmunge-path2'
|
||||||
|
old_path="${PATH}"
|
||||||
|
pathmunge "${new_paths}"
|
||||||
|
assert_equal "${new_paths}:${old_path}" "${PATH}"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'helpers: pathmunge: multiple paths, with space' {
|
||||||
|
new_paths='/tmp/fake pathmunge path1:/tmp/fake pathmunge path2'
|
||||||
|
old_path="${PATH}"
|
||||||
|
pathmunge "${new_paths}"
|
||||||
|
assert_equal "${new_paths}:${old_path}" "${PATH}"
|
||||||
|
}
|
||||||
|
|
||||||
@test "helpers: bash-it help aliases ag" {
|
@test "helpers: bash-it help aliases ag" {
|
||||||
run bash-it help aliases "ag"
|
run bash-it help aliases "ag"
|
||||||
assert_line -n 0 "ag='ag --smart-case --pager=\"less -MIRFX'"
|
assert_line -n 0 "ag='ag --smart-case --pager=\"less -MIRFX'"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue