aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-01-01 01:11:08 +1300
committerTom Ryder <tom@sanctum.geek.nz>2019-01-01 01:11:08 +1300
commite19bb8fb3c8350bee288327abd978a59eb3dc0f7 (patch)
tree754d2d883b27477f53f0fece44ef9edc7e4238f0
parentMerge branch 'release/v4.2.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-e19bb8fb3c8350bee288327abd978a59eb3dc0f7.tar.gz
dotfiles-e19bb8fb3c8350bee288327abd978a59eb3dc0f7.zip
Merge branch 'release/v4.3.0'v4.3.0
* release/v4.3.0: Bump VERSION Switch to using GNU Emacs on development machines Trim some trailing whitespace Clarify control flow in shell scripts Add clarifying comment Translate a short-circuit into a conditional Add a cheeky error message to sd() Strip trailing slashes from sd() target Correct error message from sd()
-rw-r--r--VERSION4
-rw-r--r--bash/bash_completion.d/git.bash2
-rw-r--r--bin/bcq.sh4
-rw-r--r--bin/eds.sh5
-rw-r--r--bin/fnp.sh8
-rw-r--r--bin/gms.sh7
-rw-r--r--bin/grc.sh2
-rw-r--r--bin/osc.sh8
-rw-r--r--bin/plmu.sh8
-rw-r--r--bin/td.sh2
-rw-r--r--bin/umake.sh3
-rw-r--r--bin/xgo.sh23
-rw-r--r--ksh/kshrc.d/prompt.ksh40
-rw-r--r--ksh/shrc.d/ksh.sh4
-rw-r--r--sh/profile.d/visual.sh10
-rw-r--r--sh/shrc6
-rw-r--r--sh/shrc.d/sd.sh16
-rw-r--r--vim/autoload/filetype.vim2
-rw-r--r--zsh/zshrc.d/prompt.zsh39
19 files changed, 133 insertions, 60 deletions
diff --git a/VERSION b/VERSION
index 8c8f6bc7..8550a5e5 100644
--- a/VERSION
+++ b/VERSION
@@ -1,2 +1,2 @@
-tejr dotfiles v4.2.0
-Sat Dec 29 12:21:40 UTC 2018
+tejr dotfiles v4.3.0
+Mon Dec 31 12:11:08 UTC 2018
diff --git a/bash/bash_completion.d/git.bash b/bash/bash_completion.d/git.bash
index c3a4d49c..fbd182b1 100644
--- a/bash/bash_completion.d/git.bash
+++ b/bash/bash_completion.d/git.bash
@@ -8,7 +8,7 @@
# Define and set helper function
_git() {
- # What completion to do
+ # What completion to do
case $COMP_KEY in
# Complete with branch names if C-x,B is pressed
diff --git a/bin/bcq.sh b/bin/bcq.sh
index a6c0fe60..1f4f3f9e 100644
--- a/bin/bcq.sh
+++ b/bin/bcq.sh
@@ -1,3 +1,5 @@
# Fire up bc(1), hushing it if it looks like GNU
-[ -e "$HOME"/.cache/sh/opt/bc/quiet ] && set -- --quiet "$@"
+if [ -e "$HOME"/.cache/sh/opt/bc/quiet ] ; then
+ set -- --quiet "$@"
+fi
exec bc "$@"
diff --git a/bin/eds.sh b/bin/eds.sh
index 7e719e9d..134fbdcb 100644
--- a/bin/eds.sh
+++ b/bin/eds.sh
@@ -23,7 +23,10 @@ esac
# Prepend the path to each of the names given if they don't look like options
for arg do
- [ -n "$reset" ] || set -- && reset=1
+ if [ -z "$reset" ] ; then
+ set --
+ reset=1
+ fi
case $arg in
--)
optend=1
diff --git a/bin/fnp.sh b/bin/fnp.sh
index bc0c7e21..c5beddc6 100644
--- a/bin/fnp.sh
+++ b/bin/fnp.sh
@@ -1,7 +1,9 @@
# Print input, but include filenames as headings
# Assume stdin if no options given
-[ "$#" -gt 0 ] || set -- -
+if [ "$#" -eq 0 ] ; then
+ set -- -
+fi
# Iterate through arguments
for arg do
@@ -13,7 +15,9 @@ for arg do
*) fn=$arg ;;
esac
- [ -n "$tail" ] && printf '\n'
+ if [ -n "$tail" ] ; then
+ printf '\n'
+ fi
tail=1
# Form the underline; is there a nicer way to do this in POSIX sh?
diff --git a/bin/gms.sh b/bin/gms.sh
index b77da6fa..c33c747e 100644
--- a/bin/gms.sh
+++ b/bin/gms.sh
@@ -3,7 +3,9 @@
# Trap to remove whatever's set in lockdir if we're killed
lockdir=
cleanup() {
- [ -n "$lockdir" ] && rm -fr -- "$lockdir"
+ if [ -n "$lockdir" ] ; then
+ rm -fr -- "$lockdir"
+ fi
if [ "$1" != EXIT ] ; then
trap - "$1"
kill "-$1" "$$"
@@ -23,7 +25,8 @@ for rcfile in "${GETMAIL:-"$HOME"/.getmail}"/getmailrc.* ; do (
lockdir=${TMPDIR:-/tmp}/getmail.$uid.${rcfile##*/}.lock
mkdir -m 0700 -- "$lockdir" 2>/dev/null || exit
try -n 3 -s 15 getmail --rcfile "$rcfile" "$@"
- rm -fr -- "$lockdir" && lockdir=
+ rm -fr -- "$lockdir"
+ lockdir=
) & done
# Wait for all of the enqueued tasks to finish
diff --git a/bin/grc.sh b/bin/grc.sh
index 184baf8e..bfcb648d 100644
--- a/bin/grc.sh
+++ b/bin/grc.sh
@@ -12,4 +12,4 @@ fi
# Exit 0 if the first command gives any output (added files) or the second one
# exits 1 (inverted; differences in tracked files)
[ -n "$(git ls-files --others --exclude-standard)" ] ||
-! git diff-index --quiet HEAD
+ ! git diff-index --quiet HEAD
diff --git a/bin/osc.sh b/bin/osc.sh
index 86923f12..5def12ff 100644
--- a/bin/osc.sh
+++ b/bin/osc.sh
@@ -57,8 +57,12 @@ set -- "$@" -connect "$host":"$serv"
td='' fil=''
cleanup() {
trap - EXIT "$1"
- [ -n "$fil" ] && kill -TERM "$fil"
- [ -n "$td" ] && rm -fr -- "$td"
+ if [ -n "$fil" ] ; then
+ kill -TERM "$fil"
+ fi
+ if [ -n "$td" ] ; then
+ rm -fr -- "$td"
+ fi
if [ "$1" != EXIT ] ; then
kill -"$1" "$$"
fi
diff --git a/bin/plmu.sh b/bin/plmu.sh
index 5c599828..3f237ae2 100644
--- a/bin/plmu.sh
+++ b/bin/plmu.sh
@@ -1,8 +1,12 @@
# Upgrade plenv modules with cpanm(1)
# Set up exceptions file if it exists
-ef=$HOME/.plenv/non-cpanm-modules
-[ -e "$ef" ] || ef=/dev/null
+def="$HOME"/.plenv/non-cpanm-modules
+if [ -e "$def" ] ; then
+ ef=$def
+else
+ ef=/dev/null
+fi
# Check that exceptions file is sorted
if ! LC_COLLATE=C sort -c -- "$ef" ; then
diff --git a/bin/td.sh b/bin/td.sh
index fb5610c5..ef0be618 100644
--- a/bin/td.sh
+++ b/bin/td.sh
@@ -28,4 +28,4 @@ git add -- "$file"
# If there are changes to commit, commit them
git diff-index --quiet HEAD 2>/dev/null ||
-git commit --message 'Changed by td(1df)' --quiet
+ git commit --message 'Changed by td(1df)' --quiet
diff --git a/bin/umake.sh b/bin/umake.sh
index 21073328..3c381e09 100644
--- a/bin/umake.sh
+++ b/bin/umake.sh
@@ -2,7 +2,8 @@
# any given args
while [ "$PWD" != / ] ; do
for mf in makefile Makefile ; do
- [ -f "$mf" ] && exec make "$@"
+ [ -f "$mf" ] || continue
+ exec make "$@"
done
cd .. || exit
done
diff --git a/bin/xgo.sh b/bin/xgo.sh
index 1b9f83da..6d6586ef 100644
--- a/bin/xgo.sh
+++ b/bin/xgo.sh
@@ -15,7 +15,8 @@ for url do (
# If this is a GitHub or GitLab link, swap "blob" for "raw" to get the
# actual file
(*://github.com/*/blob/*|*://gitlab.com/*/blob/*)
- url=$(printf '%s\n' "$url" | sed 's_/blob/_/raw/_')
+ url=$(printf '%s\n' "$url" |
+ sed 's_/blob/_/raw/_')
;;
# Dig out the plain text for pastebin.com links
@@ -38,7 +39,7 @@ for url do (
# mpv(1)
(*[/.]youtube.com/watch*[?\&]t=) ;;
(*[/.]youtube.com/watch*)
- mpv -- "$url" && exit
+ exec mpv -- "$url"
;;
esac
@@ -54,30 +55,32 @@ for url do (
(
cd -- "$HOME"/Downloads || exit
curl -O -- "$url" || exit
- xpdf -- "${url##*/}"
- ) && exit
+ exec xpdf -- "${url##*/}"
+ )
;;
# Open audio and video in mpv(1); force a window even for audio so I
# can control it
(audio/*|video/*)
- mpv --force-window -- "$url" && exit
+ exec mpv --force-window -- "$url"
;;
# If the MIME type is an image that is not a GIF, load it in feh(1)
(image/gif) ;;
(image/*)
- curl -- "$url" | feh - && exit
+ exec curl -- "$url" | feh -
;;
# Open plain text in a terminal view(1)
(text/plain)
# shellcheck disable=SC2016
- urxvt -e sh -c 'curl -- "$1" | view -' _ "$url" && exit
+ exec urxvt -e sh -c 'curl -- "$1" | view -' _ "$url"
;;
- esac
- # Otherwise, just pass it to br(1df)
- br "$url"
+ # Otherwise, just pass it to br(1df)
+ (*)
+ exec br "$url"
+ ;;
+ esac
) & done
diff --git a/ksh/kshrc.d/prompt.ksh b/ksh/kshrc.d/prompt.ksh
index c5f3ee1b..99e6238d 100644
--- a/ksh/kshrc.d/prompt.ksh
+++ b/ksh/kshrc.d/prompt.ksh
@@ -117,27 +117,34 @@ function prompt {
# Check various files in .git to flag processes
typeset 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
typeset 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
if ! git diff-files --no-ext-diff --quiet ; then
@@ -164,17 +171,20 @@ function prompt {
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
@@ -214,13 +224,17 @@ function prompt {
# Show return status of previous command in angle brackets, if not zero
ret)
# shellcheck disable=SC2154
- ((ret)) && printf '<%u>' "$ret"
+ if ((ret)) ; then
+ printf '<%u>' "$ret"
+ fi
;;
# Show the count of background jobs in curly brackets, if not zero
job)
# shellcheck disable=SC2154
- ((jobc)) && printf '{%u}' "$jobc"
+ if ((jobc)) ; then
+ printf '{%u}' "$jobc"
+ fi
;;
# Print error
diff --git a/ksh/shrc.d/ksh.sh b/ksh/shrc.d/ksh.sh
index 5ad14b9c..9e032756 100644
--- a/ksh/shrc.d/ksh.sh
+++ b/ksh/shrc.d/ksh.sh
@@ -29,4 +29,6 @@ if [ -z "$KSH_VERSION" ] ; then
fi
# If ENV_EXT isn't already set, set it
-[ -n "$ENV_EXT" ] || ENV_EXT=$HOME/.kshrc
+if [ -z "$ENV_EXT" ] ; then
+ ENV_EXT=$HOME/.kshrc
+fi
diff --git a/sh/profile.d/visual.sh b/sh/profile.d/visual.sh
index 119d81c7..94aee963 100644
--- a/sh/profile.d/visual.sh
+++ b/sh/profile.d/visual.sh
@@ -1,3 +1,9 @@
-# Use first found implementation of vi(1)
-VISUAL='vi'
+# If emacs is installed, and ~/.emacs exists, use emacs as the visual editor;
+# otherwise, use the system's vi
+if command -v emacs >/dev/null 2>&1 &&
+ [ -f "$HOME"/.emacs ] ; then
+ VISUAL=emacs
+else
+ VISUAL=vi
+fi
export VISUAL
diff --git a/sh/shrc b/sh/shrc
index 808e944d..26f69c0c 100644
--- a/sh/shrc
+++ b/sh/shrc
@@ -8,13 +8,15 @@ command -p stty -ixon -ctlecho 2>/dev/null
HISTSIZE=$((1 << 12))
# If HOSTNAME isn't set by this shell, we'll do it
-[ -n "$HOSTNAME" ] || HOSTNAME=$(uname -n)
+if [ -z "$HOSTNAME" ] ; then
+ HOSTNAME=$(uname -n)
+fi
# Don't warn me about new mail
unset -v MAILCHECK
# Load all the POSIX-compatible functions from ~/.shrc.d; more advanced shells
-# like bash will have their own functions
+# like bash will have their own functions in addition to these
for sh in "$HOME"/.shrc.d/*.sh ; do
[ -e "$sh" ] || continue
. "$sh"
diff --git a/sh/shrc.d/sd.sh b/sh/shrc.d/sd.sh
index 04b50f6d..10597832 100644
--- a/sh/shrc.d/sd.sh
+++ b/sh/shrc.d/sd.sh
@@ -38,12 +38,26 @@ sd() {
return 2
fi
+ # Strip trailing slashes
+ while : ; do
+ case $1 in
+ *?/) set -- "${1%/}" ;;
+ *) break ;;
+ esac
+ done
+
# Read sole optional argument
case $1 in
+ # Root has no siblings
+ /)
+ printf >&2 'sd(): Radical misunderstanding\n'
+ return 2
+ ;;
+
# Slashes aren't allowed
*/*)
- printf >&2 'bd(): Illegal slash\n'
+ printf >&2 'sd(): Illegal slash\n'
return 2
;;
diff --git a/vim/autoload/filetype.vim b/vim/autoload/filetype.vim
index d1e4e3d7..e33dfcbc 100644
--- a/vim/autoload/filetype.vim
+++ b/vim/autoload/filetype.vim
@@ -72,5 +72,3 @@ function! filetype#CheckShebang() abort
doautocmd filetypedetect BufRead
endif
endfunction
-
-
diff --git a/zsh/zshrc.d/prompt.zsh b/zsh/zshrc.d/prompt.zsh
index b612c704..689866e3 100644
--- a/zsh/zshrc.d/prompt.zsh
+++ b/zsh/zshrc.d/prompt.zsh
@@ -81,44 +81,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
@@ -154,7 +165,9 @@ prompt() {
branch=${branch#/}
branch=${branch#branches/}
branch=${branch%%/*}
- [[ -n $branch ]] || branch=unknown
+ if [[ -z $branch ]] ; then
+ branch=unknown
+ fi
# Parse the output of svn status to determine working copy state
local symbol