diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2013-08-05 01:26:20 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2013-08-05 01:26:20 +1200 |
commit | 223e04485e67e3caa717430436e91e091d58551e (patch) | |
tree | 8d420389ffd90dd442bb69bc72ba351ad5a3e4a1 /bash | |
parent | Improve color detection logic for prompt/ls/grep (diff) | |
download | dotfiles-223e04485e67e3caa717430436e91e091d58551e.tar.gz dotfiles-223e04485e67e3caa717430436e91e091d58551e.zip |
Improve quoting around expansions
Diffstat (limited to 'bash')
-rw-r--r-- | bash/bashrc.d/prompt.bash | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index 2b675dad..d222691b 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -2,7 +2,7 @@ prompt() { # Variables for use only within this function - local -i ret=$? + local -i ret="$?" local color reset branch state info url root # What's done next depends on the first argument to the function @@ -62,32 +62,32 @@ prompt() { # Figure out the branch to show for HEAD, whether a symbolic # reference or a short SHA-1; chop off any leading path - branch=$(git symbolic-ref --quiet HEAD 2>/dev/null) \ - || branch=$(git rev-parse --short HEAD 2>/dev/null) \ + branch="$(git symbolic-ref --quiet HEAD 2>/dev/null)" \ + || branch="$(git rev-parse --short HEAD 2>/dev/null)" \ || branch='unknown' - branch=${branch##*/} + branch="${branch##*/}" # 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); 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 [ -n "$(git ls-files --others --exclude-standard)" ]; then - state=${state}? + state="${state}?" fi # Print the status in brackets with a git: prefix @@ -130,10 +130,10 @@ prompt() { # Remove the root from the URL to get what's hopefully the branch # name, removing leading slashes and the 'branches' prefix, and any # trailing content after a slash - branch=${url/$root} - branch=${branch#/} - branch=${branch#branches/} - branch=${branch%%/*} + branch="${url/$root}" + branch="${branch#/}" + branch="${branch#branches/}" + branch="${branch%%/*}" # If there are changes in the working directory, add an exclamation # mark to the state @@ -153,14 +153,14 @@ prompt() { # Show the return status of the last command in angle brackets return) if [[ $ret -ne 0 ]]; then - printf '<%d>' ${ret} + printf '<%d>' "$ret" fi ;; # Show the count of background jobs in curly brackets jobs) if [[ -n "$(jobs)" ]]; then - printf '{%d}' $(jobs | sed -n '$=') + printf '{%d}' "$(jobs | sed -n '$=')" fi ;; esac |