aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/path.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-06-06 14:54:33 +1200
committerTom Ryder <tom@sanctum.geek.nz>2015-06-06 14:54:33 +1200
commitfdfe1fe72f8fe358d2b64ddc9e1b58dda4d3ba90 (patch)
tree75374be5bee4e0f36f3020958fb99e8fb46e4385 /bash/bashrc.d/path.bash
parentAvoid command substitution inline declaration (diff)
downloaddotfiles-fdfe1fe72f8fe358d2b64ddc9e1b58dda4d3ba90.tar.gz
dotfiles-fdfe1fe72f8fe358d2b64ddc9e1b58dda4d3ba90.zip
Separate declaration from assignment
Diffstat (limited to 'bash/bashrc.d/path.bash')
-rw-r--r--bash/bashrc.d/path.bash22
1 files changed, 14 insertions, 8 deletions
diff --git a/bash/bashrc.d/path.bash b/bash/bashrc.d/path.bash
index f993830c..d81190de 100644
--- a/bash/bashrc.d/path.bash
+++ b/bash/bashrc.d/path.bash
@@ -2,10 +2,12 @@
path() {
# Figure out command being called
- local pathcmd=list
+ local pathcmd
if (($#)) ; then
pathcmd=$1
shift
+ else
+ pathcmd=list
fi
# Switch between commands
@@ -48,7 +50,8 @@ path() {
insert|i)
local -a patharr
IFS=: read -a patharr < <(printf '%s\n' "$PATH")
- local dir=$1
+ local dir
+ dir=$1
if [[ -z "$dir" ]] ; then
printf 'bash: %s: need a directory path to insert\n' \
"$FUNCNAME" >&2
@@ -77,7 +80,8 @@ path() {
append|add|a)
local -a patharr
IFS=: read -a patharr < <(printf '%s\n' "$PATH")
- local dir=$1
+ local dir
+ dir=$1
if [[ -z "$dir" ]] ; then
printf 'bash: %s: need a directory path to append\n' \
"$FUNCNAME" >&2
@@ -106,7 +110,8 @@ path() {
remove|rm|r)
local -a patharr
IFS=: read -a patharr < <(printf '%s\n' "$PATH")
- local dir=$1
+ local dir
+ dir=$1
if [[ -z "$dir" ]] ; then
printf 'bash: %s: need a directory path to remove\n' \
"$FUNCNAME" >&2
@@ -134,15 +139,15 @@ path() {
for part in "$@" ; do
newpatharr=("${newpatharr[@]}" "${part%/}")
done
- local IFS=:
- PATH="${newpatharr[*]}"
+ PATH=$(IFS=: ; printf '%s' "${newpatharr[*]}")
;;
# Return whether directory is a component of PATH
check|c)
local -a patharr
IFS=: read -a patharr < <(printf '%s\n' "$PATH")
- local dir=$1
+ local dir
+ dir=$1
if [[ -z "$dir" ]] ; then
printf 'bash: %s: need a directory path to check\n' \
"$FUNCNAME" >&2
@@ -169,7 +174,8 @@ path() {
# Completion for path
_path() {
- local word=${COMP_WORDS[COMP_CWORD]}
+ local word
+ word=${COMP_WORDS[COMP_CWORD]}
# Complete operation as first word
if ((COMP_CWORD == 1)) ; then