From 899cb9446ed369efddae4303fe84e99a543bb8fe Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 9 Sep 2013 21:49:12 +1200 Subject: Better syntax for array append --- bash/bashrc.d/cd.bash | 2 +- bash/bashrc.d/prompt.bash | 12 ++++++------ bash/bashrc.d/ssh.bash | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'bash') diff --git a/bash/bashrc.d/cd.bash b/bash/bashrc.d/cd.bash index f16aad41..6d7e2573 100644 --- a/bash/bashrc.d/cd.bash +++ b/bash/bashrc.d/cd.bash @@ -4,7 +4,7 @@ cd() { local opt OPTIND=0 local -a opts while getopts elP opt; do - opts[${#opts[@]}]=-$opt + opts=("${opts[@]}" -"$opt") done shift $((OPTIND-1)) if (($# == 2)); then diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index 0009fe94..6ecf44ba 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -72,24 +72,24 @@ prompt() { # If there are staged changes in the working tree, add a plus sign # to the state if ! git diff --quiet --ignore-submodules --cached; then - state[${#state[@]}]='+' + state=("${state[@]}" '+') fi # If there are any modified tracked files in the working tree, add # an exclamation mark to the state if ! git diff-files --quiet --ignore-submodules --; then - state[${#state[@]}]='!' + state=("${state[@]}" '!') fi # If there are any stashed changes, add a circumflex to the state if git rev-parse --verify refs/stash >/dev/null 2>&1; then - state[${#state[@]}]='^' + state=("${state[@]}" '^') fi # If there are any new unignored files in the working tree, add a # question mark to the state if [[ $(git ls-files --others --exclude-standard) ]]; then - state[${#state[@]}]='?' + state=("${state[@]}" '?') fi # Print the status in brackets with a git: prefix @@ -111,7 +111,7 @@ prompt() { # If there are changes in the tree, add an exclamation mark to the # state if [[ $(hg status 2>/dev/null) ]]; then - state[${#state[@]}]='!' + state=("${state[@]}" '!') fi # Print the status in brackets with an hg: prefix @@ -146,7 +146,7 @@ prompt() { # If there are changes in the working directory, add an exclamation # mark to the state if [[ $(svn status 2>/dev/null) ]]; then - state[${#state[@]}]='!' + state=("${state[@]}" '!') fi # Print the state in brackets with an svn: prefix diff --git a/bash/bashrc.d/ssh.bash b/bash/bashrc.d/ssh.bash index 93aeecbd..9ac90b7d 100644 --- a/bash/bashrc.d/ssh.bash +++ b/bash/bashrc.d/ssh.bash @@ -13,7 +13,7 @@ _ssh() { local option value while read -r option value _; do if [[ $option == Host && $value != *'*'* ]]; then - hosts[${#hosts[@]}]=$value + hosts=("${hosts[@]}" "$value") fi done < "$config" -- cgit v1.2.3