aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-07-31 17:26:30 +1200
committerTom Ryder <tom@sanctum.geek.nz>2013-07-31 17:26:30 +1200
commitf5ed4cd090b321064039441e40fe46a6995abf9a (patch)
tree371166922ae8e079eca565322496068d658b00ba /bash
parentPlace missing quotes (diff)
downloaddotfiles-f5ed4cd090b321064039441e40fe46a6995abf9a.tar.gz
dotfiles-f5ed4cd090b321064039441e40fe46a6995abf9a.zip
Use standard structure for if/for in shell
Mostly for clarity reasons; using this syntax: if [ condition ]; then commands fi As opposed to: if [ condition ] then commands fi Or: [ condition ] && command
Diffstat (limited to 'bash')
-rw-r--r--bash/bash_logout7
-rw-r--r--bash/bash_profile8
-rw-r--r--bash/bashrc14
-rw-r--r--bash/bashrc.d/grep.bash15
-rw-r--r--bash/bashrc.d/ls.bash5
-rw-r--r--bash/bashrc.d/prompt.bash55
6 files changed, 66 insertions, 38 deletions
diff --git a/bash/bash_logout b/bash/bash_logout
index 15168ec8..c9b0ec6f 100644
--- a/bash/bash_logout
+++ b/bash/bash_logout
@@ -1,5 +1,6 @@
# Clear console if possible when logging out
-[[ "$SHLVL" = 1 ]] \
- && command -v clear_console &>/dev/null \
- && clear_console -q
+if [[ "$SHLVL" = 1 ]]; then
+ command -v clear_console &>/dev/null \
+ && clear_console -q
+fi
diff --git a/bash/bash_profile b/bash/bash_profile
index aa87667d..3b391209 100644
--- a/bash/bash_profile
+++ b/bash/bash_profile
@@ -1,6 +1,10 @@
# Source Bourne shell profile if it exists
-[[ -r "$HOME/.profile" ]] && source $HOME/.profile
+if [[ -r "$HOME/.profile" ]]; then
+ source $HOME/.profile
+fi
# Source interactive Bash config if it exists
-[[ -r "$HOME/.bashrc" ]] && source $HOME/.bashrc
+if [[ -r "$HOME/.bashrc" ]]; then
+ source $HOME/.bashrc
+fi
diff --git a/bash/bashrc b/bash/bashrc
index 5e37d3f4..280a47ca 100644
--- a/bash/bashrc
+++ b/bash/bashrc
@@ -1,5 +1,7 @@
# Don't do anything if not running interactively
-[[ -z "$PS1" ]] && return
+if [[ -z "$PS1" ]]; then
+ return
+fi
# Keep plenty of history
HISTFILESIZE=1000000
@@ -21,13 +23,13 @@ setterm -bfreq 0 &>/dev/null
stty -ixon &>/dev/null
# Use completion, if available
-[[ -r /etc/bash_completion ]] && source /etc/bash_completion
+if [[ -r /etc/bash_completion ]]; then
+ source /etc/bash_completion
+fi
# Load any supplementary scripts
-if [[ -d "$HOME/.bashrc.d" ]]
-then
- for file in $HOME/.bashrc.d/*
- do
+if [[ -d "$HOME/.bashrc.d" ]]; then
+ for file in $HOME/.bashrc.d/*; do
source $file
done
fi
diff --git a/bash/bashrc.d/grep.bash b/bash/bashrc.d/grep.bash
index f2586562..62acdb01 100644
--- a/bash/bashrc.d/grep.bash
+++ b/bash/bashrc.d/grep.bash
@@ -2,12 +2,15 @@
__grepopts() {
local grepopts='-I'
local grephelp="$(grep --help 2>/dev/null)"
- [[ "$grephelp" == *--color* ]] \
- && grepopts="${grepopts} --color=auto"
- [[ "$grephelp" == *--exclude* ]] \
- && grepopts="${grepopts} --exclude=.git{,ignore,modules}"
- [[ "$grephelp" == *--exclude-dir* ]] \
- && grepopts="${grepopts} --exclude-dir=.{cvs,git,hg,svn}"
+ if [[ "$grephelp" == *--color* ]]; then
+ grepopts="${grepopts} --color=auto"
+ fi
+ if [[ "$grephelp" == *--exclude* ]]; then
+ grepopts="${grepopts} --exclude=.git{,ignore,modules}"
+ fi
+ if [[ "$grephelp" == *--exclude-dir* ]]; then
+ grepopts="${grepopts} --exclude-dir=.{cvs,git,hg,svn}"
+ fi
printf '%s' "$grepopts"
}
diff --git a/bash/bashrc.d/ls.bash b/bash/bashrc.d/ls.bash
index 076f34df..c4be33c2 100644
--- a/bash/bashrc.d/ls.bash
+++ b/bash/bashrc.d/ls.bash
@@ -2,8 +2,9 @@
__lsopts() {
local lsopts=
local lshelp="$(ls --help 2>/dev/null)"
- [[ "$lshelp" == *--color* ]] \
- && lsopts="${lsopts} --color=auto"
+ if [[ "$lshelp" == *--color* ]]; then
+ lsopts="${lsopts} --color=auto"
+ fi
printf '%s' "$lsopts"
}
diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash
index 3243dd18..0d477cc7 100644
--- a/bash/bashrc.d/prompt.bash
+++ b/bash/bashrc.d/prompt.bash
@@ -29,37 +29,48 @@ prompt() {
# Git prompt function
git)
- $(git rev-parse --is-inside-git-dir 2>/dev/null) \
- && return 1
- $(git rev-parse --is-inside-work-tree 2>/dev/null) \
- || return 1
+ if $(git rev-parse --is-inside-git-dir 2>/dev/null); then
+ return 1
+ fi
+ if ! $(git rev-parse --is-inside-work-tree 2>/dev/null); then
+ return 1
+ fi
git status &>/dev/null
branch=$(git symbolic-ref --quiet HEAD 2>/dev/null) \
|| branch=$(git rev-parse --short HEAD 2>/dev/null) \
|| branch='unknown'
branch=${branch##*/}
- git diff --quiet --ignore-submodules --cached \
- || state=${state}+
- git diff-files --quiet --ignore-submodules -- \
- || state=${state}!
- $(git rev-parse --verify refs/stash &>/dev/null) \
- && state=${state}^
- [ -n "$(git ls-files --others --exclude-standard)" ] \
- && state=${state}?
+ if ! git diff --quiet --ignore-submodules --cached; then
+ state=${state}+
+ fi
+ if ! git diff-files --quiet --ignore-submodules --; then
+ state=${state}!
+ fi
+ if $(git rev-parse --verify refs/stash &>/dev/null); then
+ state=${state}^
+ fi
+ if [ -n "$(git ls-files --others --exclude-standard)" ]; then
+ state=${state}?
+ fi
printf '(git:%s)' "${branch:-unknown}${state}"
;;
# Mercurial prompt function
hg)
- hg branch &>/dev/null || return 1
- branch="$(hg branch 2>/dev/null)"
- [[ -n "$(hg status 2>/dev/null)" ]] && state="!"
+ if ! branch="$(hg branch 2>/dev/null)"; then
+ return 1
+ fi
+ if [[ -n "$(hg status 2>/dev/null)" ]]; then
+ state="!"
+ fi
printf '(hg:%s)' "${branch:-unknown}${state}"
;;
# Subversion prompt function
svn)
- svn info &>/dev/null || return 1
+ if ! svn info &>/dev/null; then
+ return 1
+ fi
url="$(svn info 2>/dev/null | \
awk -F': ' '$1 == "URL" {print $2}')"
root="$(svn info 2>/dev/null | \
@@ -68,7 +79,9 @@ prompt() {
branch=${branch#/}
branch=${branch#branches/}
branch=${branch%%/*}
- [[ -n "$(svn status 2>/dev/null)" ]] && state="!"
+ if [[ -n "$(svn status 2>/dev/null)" ]]; then
+ state="!"
+ fi
printf '(svn:%s)' "${branch:-unknown}${state}"
;;
@@ -79,12 +92,16 @@ prompt() {
# Return status prompt function
return)
- [[ $ret -ne 0 ]] && printf '<%d>' ${ret}
+ if [[ $ret -ne 0 ]]; then
+ printf '<%d>' ${ret}
+ fi
;;
# Job count prompt function
jobs)
- [[ -n "$(jobs)" ]] && printf '{%d}' $(jobs | sed -n '$=')
+ if [[ -n "$(jobs)" ]]; then
+ printf '{%d}' $(jobs | sed -n '$=')
+ fi
;;
esac
}