aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d
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
parentAvoid command substitution inline declaration (diff)
downloaddotfiles-fdfe1fe72f8fe358d2b64ddc9e1b58dda4d3ba90.tar.gz
dotfiles-fdfe1fe72f8fe358d2b64ddc9e1b58dda4d3ba90.zip
Separate declaration from assignment
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r--bash/bashrc.d/bd.bash3
-rw-r--r--bash/bashrc.d/ftp.bash8
-rw-r--r--bash/bashrc.d/git.bash5
-rw-r--r--bash/bashrc.d/gpg.bash6
-rw-r--r--bash/bashrc.d/make.bash3
-rw-r--r--bash/bashrc.d/mysql.bash12
-rw-r--r--bash/bashrc.d/pass.bash7
-rw-r--r--bash/bashrc.d/path.bash22
-rw-r--r--bash/bashrc.d/prompt.bash17
-rw-r--r--bash/bashrc.d/scp.bash3
-rw-r--r--bash/bashrc.d/ssh.bash3
-rw-r--r--bash/bashrc.d/ud.bash9
-rw-r--r--bash/bashrc.d/vr.bash6
13 files changed, 63 insertions, 41 deletions
diff --git a/bash/bashrc.d/bd.bash b/bash/bashrc.d/bd.bash
index 1c326c88..60b55580 100644
--- a/bash/bashrc.d/bd.bash
+++ b/bash/bashrc.d/bd.bash
@@ -20,7 +20,8 @@ bd() {
# Completion setup for bd
_bd() {
- local word=${COMP_WORDS[COMP_CWORD]}
+ local word
+ word=${COMP_WORDS[COMP_CWORD]}
# Build a list of dirs in $PWD
local -a dirs
diff --git a/bash/bashrc.d/ftp.bash b/bash/bashrc.d/ftp.bash
index 85130d7a..b57f307a 100644
--- a/bash/bashrc.d/ftp.bash
+++ b/bash/bashrc.d/ftp.bash
@@ -1,9 +1,11 @@
# Completion for ftp with .netrc machines
_ftp() {
- local word=${COMP_WORDS[COMP_CWORD]}
+ local word
+ word=${COMP_WORDS[COMP_CWORD]}
# Bail if the .netrc file is illegible
- local netrc=$HOME/.netrc
+ local netrc
+ netrc=$HOME/.netrc
if [[ ! -r $netrc ]] ; then
return 1
fi
@@ -14,7 +16,7 @@ _ftp() {
# Iterate through tokens and collect machine names
local -a machines
- local -i machine=0
+ local -i machine
local token
for token in "${tokens[@]}" ; do
if ((machine)) ; then
diff --git a/bash/bashrc.d/git.bash b/bash/bashrc.d/git.bash
index 76477fa9..5965607c 100644
--- a/bash/bashrc.d/git.bash
+++ b/bash/bashrc.d/git.bash
@@ -7,8 +7,9 @@ _git() {
fi
# Get current and previous word
- local word=${COMP_WORDS[COMP_CWORD]}
- local first=${COMP_WORDS[1]}
+ local word first
+ word=${COMP_WORDS[COMP_CWORD]}
+ first=${COMP_WORDS[1]}
# Switch on the previous word
case $first in
diff --git a/bash/bashrc.d/gpg.bash b/bash/bashrc.d/gpg.bash
index c1221d84..83bda3d7 100644
--- a/bash/bashrc.d/gpg.bash
+++ b/bash/bashrc.d/gpg.bash
@@ -1,6 +1,7 @@
# Wrapper around gpg(1) to stop ``--batch'' breaking things
gpg() {
- local argstring=$*
+ local argstring
+ argstring=$*
case $argstring in
*--ed*|*--gen-k*|*--sign-k*)
command gpg --no-batch "$@"
@@ -13,7 +14,8 @@ gpg() {
# Completion for gpg with long options
_gpg() {
- local word=${COMP_WORDS[COMP_CWORD]}
+ local word
+ word=${COMP_WORDS[COMP_CWORD]}
# Bail if no gpg(1)
if ! hash gpg 2>/dev/null ; then
diff --git a/bash/bashrc.d/make.bash b/bash/bashrc.d/make.bash
index 6e0f4185..df4c0f56 100644
--- a/bash/bashrc.d/make.bash
+++ b/bash/bashrc.d/make.bash
@@ -1,6 +1,7 @@
# Completion setup for Make, completing targets
_make() {
- local word=${COMP_WORDS[COMP_CWORD]}
+ local word
+ word=${COMP_WORDS[COMP_CWORD]}
# Quietly bail if no legible Makefile
if [[ ! -r Makefile ]] ; then
diff --git a/bash/bashrc.d/mysql.bash b/bash/bashrc.d/mysql.bash
index 97bb1764..973542b8 100644
--- a/bash/bashrc.d/mysql.bash
+++ b/bash/bashrc.d/mysql.bash
@@ -9,7 +9,8 @@
# password=SsJ2pICe226jM
#
mysql() {
- local config=$HOME/.mysql/$1.cnf
+ local config
+ config=$HOME/.mysql/$1.cnf
if [[ -r $config ]] ; then
shift
command mysql --defaults-extra-file="$config" "$@"
@@ -20,10 +21,12 @@ mysql() {
# Completion setup for MySQL for configured databases
_mysql() {
- local word=${COMP_WORDS[COMP_CWORD]}
+ local word
+ word=${COMP_WORDS[COMP_CWORD]}
# Check directory exists and has at least one .cnf file
- local dir=$HOME/.mysql
+ local dir
+ dir=$HOME/.mysql
if [[ ! -d $dir ]] || (
shopt -s nullglob dotglob
declare -a files=("$dir"/*.cnf)
@@ -33,7 +36,8 @@ _mysql() {
fi
# Return the names of the .cnf files sans prefix as completions
- local -a items=("$dir"/*.cnf)
+ local -a items
+ items=("$dir"/*.cnf)
items=("${items[@]##*/}")
items=("${items[@]%%.cnf}")
COMPREPLY=( $(compgen -W "${items[*]}" -- "$word") )
diff --git a/bash/bashrc.d/pass.bash b/bash/bashrc.d/pass.bash
index e173531f..d40a833f 100644
--- a/bash/bashrc.d/pass.bash
+++ b/bash/bashrc.d/pass.bash
@@ -8,7 +8,8 @@ fi
_pass()
{
# If we can't read the password directory, just bail
- local passdir=${PASSWORD_STORE_DIR:-$HOME/.password-store}
+ local passdir
+ passdir=${PASSWORD_STORE_DIR:-$HOME/.password-store}
if [[ ! -r $passdir ]] ; then
return 1
fi
@@ -16,8 +17,8 @@ _pass()
# Iterate through list of .gpg paths, extension stripped, null-delimited,
# and filter them down to the ones matching the completing word (compgen
# doesn't seem to do this properly with a null delimiter)
- local word=${COMP_WORDS[COMP_CWORD]}
- local entry
+ local word entry
+ word=${COMP_WORDS[COMP_CWORD]}
while read -d '' -r entry ; do
if [[ $entry == "$word"* ]] ; then
COMPREPLY=("${COMPREPLY[@]}" "$entry")
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
diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash
index f4a1b718..fa46a5dd 100644
--- a/bash/bashrc.d/prompt.bash
+++ b/bash/bashrc.d/prompt.bash
@@ -95,7 +95,7 @@ prompt() {
# Safely read status with -z --porcelain
local line
- local -i ready=0 modified=0 untracked=0
+ local -i ready modified untracked
while IFS= read -r -d '' line ; do
if [[ $line == [MADRCT]* ]] ; then
ready=1
@@ -126,8 +126,7 @@ prompt() {
fi
# Print the status in brackets with a git: prefix
- local IFS=
- printf '(git:%s%s)' "${branch:-unknown}" "${state[*]}"
+ (IFS= ; printf '(git:%s%s)' "${branch:-unknown}" "${state[*]}")
;;
# Mercurial prompt function
@@ -148,7 +147,7 @@ prompt() {
# Safely read status with -0
local line
- local -i modified=0 untracked=0
+ local -i modified untracked
while IFS= read -r -d '' line ; do
if [[ $line == '?'* ]] ; then
untracked=1
@@ -167,8 +166,7 @@ prompt() {
fi
# Print the status in brackets with an hg: prefix
- local IFS=
- printf '(hg:%s%s)' "${branch:-unknown}" "${state[*]}"
+ (IFS= ; printf '(hg:%s%s)' "${branch:-unknown}" "${state[*]}")
;;
# Subversion prompt function
@@ -207,7 +205,7 @@ prompt() {
# Parse the output of svn status to determine working copy state
local symbol
- local -i modified=0 untracked=0
+ local -i modified untracked
while read -r symbol _ ; do
if [[ $symbol == *'?'* ]] ; then
untracked=1
@@ -226,8 +224,7 @@ prompt() {
fi
# Print the state in brackets with an svn: prefix
- local IFS=
- printf '(svn:%s%s)' "${branch:-unknown}" "${state[*]}"
+ (IFS= ; printf '(svn:%s%s)' "${branch:-unknown}" "${state[*]}")
;;
# VCS wrapper prompt function; print the first relevant prompt, if any
@@ -244,7 +241,7 @@ prompt() {
# Show the count of background jobs in curly brackets, if not zero
job)
- local -i jobc=0
+ local -i jobc
while read -r _ ; do
((jobc++))
done < <(jobs -p)
diff --git a/bash/bashrc.d/scp.bash b/bash/bashrc.d/scp.bash
index 819c6f26..0b3e34db 100644
--- a/bash/bashrc.d/scp.bash
+++ b/bash/bashrc.d/scp.bash
@@ -1,6 +1,7 @@
# Wrap scp to check for missing colons
scp() {
- local argstring=$*
+ local argstring
+ argstring=$*
if (($# >= 2)) && [[ $argstring != *:* ]] ; then
printf 'bash: %s: Missing colon, probably an error\n' \
"$FUNCNAME" >&2
diff --git a/bash/bashrc.d/ssh.bash b/bash/bashrc.d/ssh.bash
index 696e9b34..ea3c70a6 100644
--- a/bash/bashrc.d/ssh.bash
+++ b/bash/bashrc.d/ssh.bash
@@ -1,6 +1,7 @@
# Completion for ssh/sftp/ssh-copy-id with config hostnames
_ssh() {
- local word=${COMP_WORDS[COMP_CWORD]}
+ local word
+ word=${COMP_WORDS[COMP_CWORD]}
# Read hostnames from existent config files, no asterisks
local -a hosts
diff --git a/bash/bashrc.d/ud.bash b/bash/bashrc.d/ud.bash
index 16a79cba..2428ba54 100644
--- a/bash/bashrc.d/ud.bash
+++ b/bash/bashrc.d/ud.bash
@@ -4,7 +4,8 @@ ud() {
# Check and save optional first argument, number of steps upward; default
# to 1 if absent
- local -i steps=${1:-1}
+ local -i steps
+ steps=${1:-1}
if ! ((steps > 0)) ; then
printf 'bash: %s: Invalid step count %s\n' "$FUNCNAME" "$1" >&2
return 2
@@ -12,7 +13,8 @@ ud() {
# Check and save optional second argument, target directory; default to
# $PWD (typical usage case)
- local dir=${2:-$PWD}
+ local dir
+ dir=${2:-$PWD}
if [[ ! -e $dir ]] ; then
printf 'bash: %s: Target dir %s does not exist\n' "$FUNCNAME" "$2" >&2
return 1
@@ -31,7 +33,8 @@ ud() {
# Completion is only useful for the second argument
_ud() {
if ((COMP_CWORD == 2)) ; then
- local word=${COMP_WORDS[COMP_CWORD]}
+ local word
+ word=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -A directory -- "$word" ) )
else
return 1
diff --git a/bash/bashrc.d/vr.bash b/bash/bashrc.d/vr.bash
index 4289c15c..a8d836a3 100644
--- a/bash/bashrc.d/vr.bash
+++ b/bash/bashrc.d/vr.bash
@@ -1,6 +1,7 @@
# Move to the root directory of a VCS working copy
vr() {
- local path=${1:-$PWD}
+ local path
+ path=${1:-$PWD}
path=${path%/}
# Raise some helpful errors
@@ -39,7 +40,8 @@ vr() {
# If we have a .svn dir, iterate upwards until we find an ancestor that
# doesn't; hopefully that's the root
if [[ -d $path/.svn ]] ; then
- local search=$path
+ local search
+ search=$path
while [[ -n $search ]] ; do
if [[ -d ${search%/*}/.svn ]] ; then
search=${search%/*}