aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-11-30 14:17:01 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-11-30 14:17:01 +1300
commitf02abc131991a754a9aabed14c6acdbed253a1de (patch)
tree800027c8a3460f911a68db65bf330a2fbcf471e7
parentMerge branch 'hotfix/v2.1.1' (diff)
parentBump VERSION (diff)
downloaddotfiles-f02abc131991a754a9aabed14c6acdbed253a1de.tar.gz
dotfiles-f02abc131991a754a9aabed14c6acdbed253a1de.zip
Merge branch 'release/v2.2.0'v2.2.0
* release/v2.2.0: Bump VERSION Add `abort` attribute to new autoload function Suppress a couple of ShellCheck errors Remove redundant return short-circuit Add explanatory comments for version check Use ||/&& short-circuiting only for flow control Drop support for Bash <= 3.0
-rw-r--r--README.md9
-rw-r--r--VERSION4
-rw-r--r--bash/bash_completion.d/chgrp.bash8
-rw-r--r--bash/bash_completion.d/ftp.bash8
-rw-r--r--bash/bash_completion.d/git.bash9
-rw-r--r--bash/bash_completion.d/gpg.bash6
-rw-r--r--bash/bash_completion.d/mail.bash6
-rw-r--r--bash/bash_completion.d/make.bash8
-rw-r--r--bash/bash_completion.d/man.bash8
-rw-r--r--bash/bash_completion.d/mutt.bash8
-rw-r--r--bash/bash_completion.d/mysql.bash8
-rw-r--r--bash/bash_completion.d/openssl.bash8
-rw-r--r--bash/bash_completion.d/sftp.bash8
-rw-r--r--bash/bash_completion.d/ssh-copy-id.bash8
-rw-r--r--bash/bash_completion.d/ssh.bash8
-rw-r--r--bash/bash_logout4
-rw-r--r--bash/bash_profile10
-rw-r--r--bash/bashrc27
-rw-r--r--bash/bashrc.d/prompt.bash58
-rw-r--r--bash/bashrc.d/pushd.bash3
-rw-r--r--vim/autoload/htmlcomplete.vim2
21 files changed, 86 insertions, 132 deletions
diff --git a/README.md b/README.md
index 8a2f412d..ae9b4319 100644
--- a/README.md
+++ b/README.md
@@ -75,7 +75,7 @@ Configuration is included for:
* Bourne-style POSIX shells, sharing a `.profile`, an `ENV` file, and some
helper functions:
- * [GNU Bash](https://www.gnu.org/software/bash/) (2.05a or higher)
+ * [GNU Bash](https://www.gnu.org/software/bash/) (3.0 or higher)
* [Korn shell](http://www.kornshell.com/) (`ksh93`, `pdksh`, `mksh`)
* [Z shell](https://www.zsh.org/)
* [Abook](http://abook.sourceforge.net/) -- curses address book program
@@ -137,8 +137,7 @@ and scripts where I can so that the same files can be loaded for all shells.
On GNU/Linux I use Bash, on BSD I use some variant of Korn Shell, preferably
`ksh93` if it's available.
-As I occasionally have work on very old internal systems, my Bash is written to
-work with [any version 2.05a or
+My Bash is written to work with [any version 3.0 or
newer](http://wiki.bash-hackers.org/scripting/bashchanges). This is why I use
older syntax for certain things such as appending items to arrays:
@@ -150,8 +149,8 @@ actually works for arrays with sparse indices, unlike the above syntax:
array+=("$item")
Where I do use features that are only available in versions of Bash newer than
-2.05a, such as newer `shopt` options or `PROMPT_DIRTRIM`, they are only run
-after testing `BASH_VERSINFO` appropriately.
+3.0, such as newer `shopt` options or `PROMPT_DIRTRIM`, they are only run after
+testing `BASH_VERSINFO` appropriately.
#### Prompt
diff --git a/VERSION b/VERSION
index aae83bc2..85f95d68 100644
--- a/VERSION
+++ b/VERSION
@@ -1,2 +1,2 @@
-tejr dotfiles v2.1.1
-Thu Nov 29 20:36:00 UTC 2018
+tejr dotfiles v2.2.0
+Fri Nov 30 01:17:01 UTC 2018
diff --git a/bash/bash_completion.d/chgrp.bash b/bash/bash_completion.d/chgrp.bash
index d047f97f..5e93ccee 100644
--- a/bash/bash_completion.d/chgrp.bash
+++ b/bash/bash_completion.d/chgrp.bash
@@ -11,10 +11,4 @@ _chgrp() {
COMPREPLY[${#COMPREPLY[@]}]=$group
done < <(compgen -A group -- "${COMP_WORDS[COMP_CWORD]}")
}
-
-# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _chgrp -o bashdefault -o default chgrp
-else
- complete -F _chgrp -o default chgrp
-fi
+complete -F _chgrp -o bashdefault -o default chgrp
diff --git a/bash/bash_completion.d/ftp.bash b/bash/bash_completion.d/ftp.bash
index 335d711a..d7ee8963 100644
--- a/bash/bash_completion.d/ftp.bash
+++ b/bash/bash_completion.d/ftp.bash
@@ -30,10 +30,4 @@ _ftp() {
COMPREPLY[${#COMPREPLY[@]}]=$machine
done
}
-
-# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _ftp -o bashdefault -o default ftp
-else
- complete -F _ftp -o default ftp
-fi
+complete -F _ftp -o bashdefault -o default ftp
diff --git a/bash/bash_completion.d/git.bash b/bash/bash_completion.d/git.bash
index 2bee169a..2fd1bb98 100644
--- a/bash/bash_completion.d/git.bash
+++ b/bash/bash_completion.d/git.bash
@@ -198,11 +198,4 @@ _git() {
;;
esac
}
-
-# Defaulting to directory/file completion is important in Git's case;
-# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _git -o bashdefault -o default git
-else
- complete -F _git -o default git
-fi
+complete -F _git -o bashdefault -o default git
diff --git a/bash/bash_completion.d/gpg.bash b/bash/bash_completion.d/gpg.bash
index 6d4cf345..f98cb193 100644
--- a/bash/bash_completion.d/gpg.bash
+++ b/bash/bash_completion.d/gpg.bash
@@ -16,8 +16,4 @@ _gpg() {
}
# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _gpg -o bashdefault -o default gpg
-else
- complete -F _gpg -o default gpg
-fi
+complete -F _gpg -o bashdefault -o default gpg
diff --git a/bash/bash_completion.d/mail.bash b/bash/bash_completion.d/mail.bash
index 4476df12..65c4ae80 100644
--- a/bash/bash_completion.d/mail.bash
+++ b/bash/bash_completion.d/mail.bash
@@ -3,8 +3,4 @@ declare -F _abook_addresses >/dev/null ||
source "$HOME"/.bash_completion.d/_abook_addresses.bash
# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _abook_addresses -o bashdefault -o default mail
-else
- complete -F _abook_addresses -o default mail
-fi
+complete -F _abook_addresses -o bashdefault -o default mail
diff --git a/bash/bash_completion.d/make.bash b/bash/bash_completion.d/make.bash
index bb01b36a..c36a039a 100644
--- a/bash/bash_completion.d/make.bash
+++ b/bash/bash_completion.d/make.bash
@@ -48,10 +48,4 @@ _make() {
esac
done < "$mf"
}
-
-# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _make -o bashdefault -o default make
-else
- complete -F _make -o default make
-fi
+complete -F _make -o bashdefault -o default make
diff --git a/bash/bash_completion.d/man.bash b/bash/bash_completion.d/man.bash
index 3e2cc5be..1efa7c52 100644
--- a/bash/bash_completion.d/man.bash
+++ b/bash/bash_completion.d/man.bash
@@ -84,10 +84,4 @@ _man() {
fi
)
}
-
-# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _man -o bashdefault -o default man
-else
- complete -F _man -o default man
-fi
+complete -F _man -o bashdefault -o default man
diff --git a/bash/bash_completion.d/mutt.bash b/bash/bash_completion.d/mutt.bash
index d8bcc15d..c7f02ac7 100644
--- a/bash/bash_completion.d/mutt.bash
+++ b/bash/bash_completion.d/mutt.bash
@@ -1,10 +1,4 @@
# Completion for mutt(1) with abook(1) email addresses
declare -F _abook_addresses >/dev/null ||
source "$HOME"/.bash_completion.d/_abook_addresses.bash
-
-# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _abook_addresses -o bashdefault -o default mutt
-else
- complete -F _abook_addresses -o default mutt
-fi
+complete -F _abook_addresses -o bashdefault -o default mutt
diff --git a/bash/bash_completion.d/mysql.bash b/bash/bash_completion.d/mysql.bash
index 5604b3bb..ad153adc 100644
--- a/bash/bash_completion.d/mysql.bash
+++ b/bash/bash_completion.d/mysql.bash
@@ -50,10 +50,4 @@ _mysql() {
fi
)
}
-
-# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _mysql -o bashdefault -o default mysql
-else
- complete -F _mysql -o default mysql
-fi
+complete -F _mysql -o bashdefault -o default mysql
diff --git a/bash/bash_completion.d/openssl.bash b/bash/bash_completion.d/openssl.bash
index b2bc1b7d..86650770 100644
--- a/bash/bash_completion.d/openssl.bash
+++ b/bash/bash_completion.d/openssl.bash
@@ -23,10 +23,4 @@ _openssl() {
;;
esac
}
-
-# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _openssl -o bashdefault -o default openssl
-else
- complete -F _openssl -o default openssl
-fi
+complete -F _openssl -o bashdefault -o default openssl
diff --git a/bash/bash_completion.d/sftp.bash b/bash/bash_completion.d/sftp.bash
index 60044e41..ad4d406f 100644
--- a/bash/bash_completion.d/sftp.bash
+++ b/bash/bash_completion.d/sftp.bash
@@ -1,10 +1,4 @@
# Completion for sftp(1) with ssh_config(5) hostnames
declare -F _ssh_config_hosts >/dev/null ||
source "$HOME"/.bash_completion.d/_ssh_config_hosts.bash
-
-# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _ssh_config_hosts -o bashdefault -o default sftp
-else
- complete -F _ssh_config_hosts -o default sftp
-fi
+complete -F _ssh_config_hosts -o bashdefault -o default sftp
diff --git a/bash/bash_completion.d/ssh-copy-id.bash b/bash/bash_completion.d/ssh-copy-id.bash
index 5e4fe99b..336df4ea 100644
--- a/bash/bash_completion.d/ssh-copy-id.bash
+++ b/bash/bash_completion.d/ssh-copy-id.bash
@@ -1,10 +1,4 @@
# Completion for ssh-copy-id(1) with ssh_config(5) hostnames
declare -F _ssh_config_hosts >/dev/null ||
source "$HOME"/.bash_completion.d/_ssh_config_hosts.bash
-
-# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _ssh_config_hosts -o bashdefault -o default ssh-copy-id
-else
- complete -F _ssh_config_hosts -o default ssh-copy-id
-fi
+complete -F _ssh_config_hosts -o bashdefault -o default ssh-copy-id
diff --git a/bash/bash_completion.d/ssh.bash b/bash/bash_completion.d/ssh.bash
index c8212614..7ec82596 100644
--- a/bash/bash_completion.d/ssh.bash
+++ b/bash/bash_completion.d/ssh.bash
@@ -1,10 +1,4 @@
# Completion for ssh(1) with ssh_config(5) hostnames
declare -F _ssh_config_hosts >/dev/null ||
source "$HOME"/.bash_completion.d/_ssh_config_hosts.bash
-
-# bashdefault requires Bash >=3.0
-if ((BASH_VERSINFO[0] >= 3)) ; then
- complete -F _ssh_config_hosts -o bashdefault -o default ssh
-else
- complete -F _ssh_config_hosts -o default ssh
-fi
+complete -F _ssh_config_hosts -o bashdefault -o default ssh
diff --git a/bash/bash_logout b/bash/bash_logout
index 911b4f66..ab3f573d 100644
--- a/bash/bash_logout
+++ b/bash/bash_logout
@@ -1,2 +1,4 @@
# Clear console if possible when logging out
-[ "$SHLVL" = 1 ] && clear_console -q 2>/dev/null
+if [ "$SHLVL" = 1 ] ; then
+ clear_console -q 2>/dev/null
+fi
diff --git a/bash/bash_profile b/bash/bash_profile
index 0376ee57..1f5a633a 100644
--- a/bash/bash_profile
+++ b/bash/bash_profile
@@ -1,5 +1,7 @@
# Load ~/.profile regardless of shell version
-[ -e "$HOME"/.profile ] && . "$HOME"/.profile
+if [ -e "$HOME"/.profile ] ; then
+ . "$HOME"/.profile
+fi
# If POSIXLY_CORRECT is set after doing that, force the `posix` option on and
# don't load the rest of this stuff--so, just ~/.profile and ENV
@@ -9,5 +11,7 @@ if [ -n "$POSIXLY_CORRECT" ] ; then
fi
# If ~/.bashrc exists, source that too; the tests for both interactivity and
-# >=2.05a (for features like [[) are in there
-[ -f "$HOME"/.bashrc ] && . "$HOME"/.bashrc
+# minimum version numbers are in there
+if [ -f "$HOME"/.bashrc ] ; then
+ . "$HOME"/.bashrc
+fi
diff --git a/bash/bashrc b/bash/bashrc
index 8462e5c2..dcf3df53 100644
--- a/bash/bashrc
+++ b/bash/bashrc
@@ -6,8 +6,9 @@ esac
# Don't do anything if restricted, not even sourcing the ENV file
# Testing $- for "r" doesn't work
-# shellcheck disable=SC2128
-[ -n "$BASH_VERSINFO" ] && shopt -q restricted_shell && return
+if shopt -q restricted_shell >/dev/null 2>&1 ; then
+ return
+fi
# Clear away all aliases; we do this here rather than in the $ENV file shared
# between POSIX shells, because ksh relies on aliases to implement certain
@@ -16,16 +17,14 @@ unalias -a
# If ENV is set, source it to get all the POSIX-compatible interactive stuff;
# we should be able to do this even if we're running a truly ancient Bash
-[ -n "$ENV" ] && . "$ENV"
+if [ -n "$ENV" ] ; then
+ . "$ENV"
+fi
-# Ensure we're using at least version 2.05. Weird arithmetic syntax needed here
-# due to leading zeroes and trailing letters in some 2.x version numbers (e.g.
-# 2.05a).
+# Ensure we're using at least version 3.0
# shellcheck disable=SC2128
-[ -n "$BASH_VERSINFO" ] || return
-((BASH_VERSINFO[0] == 2)) &&
- ((10#${BASH_VERSINFO[1]%%[!0-9]*} < 5)) &&
- return
+[ -n "$BASH_VERSINFO" ] || return # Check version array exists (>=2.0)
+((BASH_VERSINFO[0] >= 3)) || return # Check actual major version number
# Clear away command_not_found_handle if a system bashrc file set it up
unset -f command_not_found_handle
@@ -86,11 +85,15 @@ if ((BASH_VERSINFO[0] >= 4)) ; then
# Warn me about stopped jobs when exiting
# Available since 4.0, but only set it if >=4.1 due to bug:
# <https://lists.gnu.org/archive/html/bug-bash/2009-02/msg00176.html>
- ((BASH_VERSINFO[1] >= 1)) && shopt -s checkjobs
+ if ((BASH_VERSINFO[1] >= 1)) ; then
+ shopt -s checkjobs
+ fi
# Expand variables in directory completion
# Only available since 4.3
- ((BASH_VERSINFO[1] >= 3)) && shopt -s direxpand
+ if ((BASH_VERSINFO[1] >= 3)) ; then
+ shopt -s direxpand
+ fi
fi
# Load Bash-specific startup files
diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash
index a6506a60..26e10cd4 100644
--- a/bash/bashrc.d/prompt.bash
+++ b/bash/bashrc.d/prompt.bash
@@ -10,7 +10,9 @@ prompt() {
PROMPT_COMMAND='history -a'
# If Bash 4.0 is available, trim very long paths in prompt
- ((BASH_VERSINFO[0] >= 4)) && PROMPT_DIRTRIM=4
+ if ((BASH_VERSINFO[0] >= 4)) ; then
+ PROMPT_DIRTRIM=4
+ fi
# Basic prompt shape depends on whether we're in SSH or not
PS1=
@@ -118,44 +120,55 @@ prompt() {
# Check various files in .git to flag processes
local proc
- [[ -d .git/rebase-merge || -d .git/rebase-apply ]] &&
+ if [[ -d .git/rebase-merge || -d .git/rebase-apply ]] ; then
proc=${proc:+"$proc",}'REBASE'
- [[ -f .git/MERGE_HEAD ]] &&
+ fi
+ if [[ -f .git/MERGE_HEAD ]] ; then
proc=${proc:+"$proc",}'MERGE'
- [[ -f .git/CHERRY_PICK_HEAD ]] &&
+ fi
+ if [[ -f .git/CHERRY_PICK_HEAD ]] ; then
proc=${proc:+"$proc",}'PICK'
- [[ -f .git/REVERT_HEAD ]] &&
+ fi
+ if [[ -f .git/REVERT_HEAD ]] ; then
proc=${proc:+"$proc",}'REVERT'
- [[ -f .git/BISECT_LOG ]] &&
+ fi
+ if [[ -f .git/BISECT_LOG ]] ; then
proc=${proc:+"$proc",}'BISECT'
+ fi
# Collect symbols representing repository state
local state
# Upstream HEAD has commits after local HEAD; we're "behind"
- (($(git rev-list --count 'HEAD..@{u}'))) &&
+ if (($(git rev-list --count 'HEAD..@{u}'))) ; then
state=${state}'<'
+ fi
# Local HEAD has commits after upstream HEAD; we're "ahead"
- (($(git rev-list --count '@{u}..HEAD'))) &&
+ if (($(git rev-list --count '@{u}..HEAD'))) ; then
state=${state}'>'
+ fi
# Tracked files are modified
- git diff-files --no-ext-diff --quiet ||
+ if ! git diff-files --no-ext-diff --quiet ; then
state=${state}'!'
+ fi
# Changes are staged
- git diff-index --cached --no-ext-diff --quiet HEAD ||
+ if ! git diff-index --cached --no-ext-diff --quiet HEAD ; then
state=${state}'+'
+ fi
# There are some untracked and unignored files
- git ls-files --directory --error-unmatch --exclude-standard \
- --no-empty-directory --others -- ':/*' &&
+ if git ls-files --directory --error-unmatch --exclude-standard \
+ --no-empty-directory --others -- ':/*' ; then
state=${state}'?'
+ fi
# There are stashed changes
- git rev-parse --quiet --verify refs/stash &&
+ if git rev-parse --quiet --verify refs/stash ; then
state=${state}'^'
+ fi
} >/dev/null 2>&1
@@ -186,7 +199,8 @@ prompt() {
# Exit if we couldn't get either--or, implicitly, if we don't have
# svn(1).
- [[ -n $url && -n $root ]] || return
+ [[ -n $url ]] || return
+ [[ -n $root ]] || return
# Remove the root from the URL to get what's hopefully the branch
# name, removing leading slashes and the 'branches' prefix, and any
@@ -196,7 +210,7 @@ prompt() {
branch=${branch#/}
branch=${branch#branches/}
branch=${branch%%/*}
- [[ -n $branch ]] || branch=unknown
+ branch=${branch:-unknown}
# Parse the output of svn status to determine working copy state
local symbol
@@ -210,8 +224,12 @@ prompt() {
# Add appropriate state flags
local state
- ((modified)) && state=${state}'!'
- ((untracked)) && state=${state}'?'
+ if ((modified)) ; then
+ state=${state}'!'
+ fi
+ if ((untracked)) ; then
+ state=${state}'?'
+ fi
# Print the state in brackets with an svn: prefix
printf '(svn:%s%s)' \
@@ -230,7 +248,8 @@ prompt() {
# Show return status of previous command in angle brackets, if not zero
ret)
# shellcheck disable=SC2154
- ((ret)) && printf '<%u>' "${ret//\\/\\\\}"
+ ((ret)) || return
+ printf '<%u>' "${ret//\\/\\\\}"
;;
# Show the count of background jobs in curly brackets, if not zero
@@ -239,7 +258,8 @@ prompt() {
while read -r ; do
((jobc++))
done < <(jobs -p)
- ((jobc)) && printf '{%u}' "${jobc//\\/\\\\}"
+ ((jobc)) || return
+ printf '{%u}' "${jobc//\\/\\\\}"
;;
# No argument given, print prompt strings and vars
diff --git a/bash/bashrc.d/pushd.bash b/bash/bashrc.d/pushd.bash
index 4a6e4be3..e708d3e8 100644
--- a/bash/bashrc.d/pushd.bash
+++ b/bash/bashrc.d/pushd.bash
@@ -1,4 +1,5 @@
# Make pushd default to $HOME if no arguments given, much like cd
pushd() {
- builtin pushd "${@:-"$HOME"}" || return
+ # shellcheck disable=SC2164
+ builtin pushd "${@:-"$HOME"}"
}
diff --git a/vim/autoload/htmlcomplete.vim b/vim/autoload/htmlcomplete.vim
index d4e52cd6..37ffa288 100644
--- a/vim/autoload/htmlcomplete.vim
+++ b/vim/autoload/htmlcomplete.vim
@@ -1,5 +1,5 @@
" Override expensive HTML version detection for 'omnifunc', that I don't use
" and can't otherwise disable
-function! htmlcomplete#DetectOmniFlavor()
+function! htmlcomplete#DetectOmniFlavor() abort
return
endfunction