From 536b1db6c63dee464724c80b62f7441f0e330e22 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 31 Dec 2018 13:02:49 +1300 Subject: Correct error message from sd() --- sh/shrc.d/sd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/shrc.d/sd.sh b/sh/shrc.d/sd.sh index 04b50f6d..814dcffc 100644 --- a/sh/shrc.d/sd.sh +++ b/sh/shrc.d/sd.sh @@ -43,7 +43,7 @@ sd() { # Slashes aren't allowed */*) - printf >&2 'bd(): Illegal slash\n' + printf >&2 'sd(): Illegal slash\n' return 2 ;; -- cgit v1.2.3 From 32b73502e66a20e638177badfbfbd5a65d0d7383 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 31 Dec 2018 13:04:48 +1300 Subject: Strip trailing slashes from sd() target --- sh/shrc.d/sd.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sh/shrc.d/sd.sh b/sh/shrc.d/sd.sh index 814dcffc..a901bb51 100644 --- a/sh/shrc.d/sd.sh +++ b/sh/shrc.d/sd.sh @@ -38,6 +38,14 @@ sd() { return 2 fi + # Strip trailing slashes + while : ; do + case $1 in + *?/) set -- "${1%/}" ;; + *) break ;; + esac + done + # Read sole optional argument case $1 in -- cgit v1.2.3 From 870ccd17ef1b1d4b94ba13b5140130306dac51c7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 31 Dec 2018 13:12:17 +1300 Subject: Add a cheeky error message to sd() --- sh/shrc.d/sd.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sh/shrc.d/sd.sh b/sh/shrc.d/sd.sh index a901bb51..10597832 100644 --- a/sh/shrc.d/sd.sh +++ b/sh/shrc.d/sd.sh @@ -49,6 +49,12 @@ sd() { # 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 'sd(): Illegal slash\n' -- cgit v1.2.3 From 5c942c0f64847bf0d6f85c4513ab94de902e0f14 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 31 Dec 2018 13:52:25 +1300 Subject: Translate a short-circuit into a conditional I only want to use the `||` short-circuits for control flow changes (return, continue, break etc). --- sh/shrc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sh/shrc b/sh/shrc index 808e944d..fa44892b 100644 --- a/sh/shrc +++ b/sh/shrc @@ -8,7 +8,9 @@ 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 -- cgit v1.2.3 From d32e82ab7e8baef31a1edeb4bc032352dea40020 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 31 Dec 2018 13:52:49 +1300 Subject: Add clarifying comment --- sh/shrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/shrc b/sh/shrc index fa44892b..26f69c0c 100644 --- a/sh/shrc +++ b/sh/shrc @@ -16,7 +16,7 @@ fi 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" -- cgit v1.2.3 From 0c84989ca0b97ca1d075e7a304a407553e34381d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 31 Dec 2018 14:19:57 +1300 Subject: Clarify control flow in shell scripts --- bin/bcq.sh | 4 +++- bin/eds.sh | 5 ++++- bin/fnp.sh | 8 ++++++-- bin/gms.sh | 7 +++++-- bin/grc.sh | 2 +- bin/osc.sh | 8 ++++++-- bin/plmu.sh | 8 ++++++-- bin/td.sh | 2 +- bin/umake.sh | 3 ++- bin/xgo.sh | 23 +++++++++++++---------- ksh/kshrc.d/prompt.ksh | 40 +++++++++++++++++++++++++++------------- ksh/shrc.d/ksh.sh | 4 +++- zsh/zshrc.d/prompt.zsh | 39 ++++++++++++++++++++++++++------------- 13 files changed, 103 insertions(+), 50 deletions(-) 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..63e1a772 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/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 -- cgit v1.2.3 From cc1e3c80824c5f641ff12adeb2eb2b84018e08d6 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 31 Dec 2018 14:31:47 +1300 Subject: Trim some trailing whitespace --- bash/bash_completion.d/git.bash | 2 +- bin/eds.sh | 2 +- vim/autoload/filetype.vim | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) 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/eds.sh b/bin/eds.sh index 63e1a772..134fbdcb 100644 --- a/bin/eds.sh +++ b/bin/eds.sh @@ -24,7 +24,7 @@ esac # Prepend the path to each of the names given if they don't look like options for arg do if [ -z "$reset" ] ; then - set -- + set -- reset=1 fi case $arg in 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 - - -- cgit v1.2.3 From 36f7528137c18a16c842525f69ff0a3d445d8e46 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 1 Jan 2019 01:06:17 +1300 Subject: Switch to using GNU Emacs on development machines > Andromeda, by Perseus sav'd and wed, > Hanker'd each day to see the Gorgon's head: > Till o'er a fount he held it, bade her lean, > And mirror'd in the wave was safely seen > That death she liv'd by. > Let not thine eyes know > Any forbidden thing itself, although > It once should save as well as kill: but be > Its shadow upon life enough for thee. > > --Dante Gabriel Rossetti --- sh/profile.d/visual.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 -- cgit v1.2.3 From d7b70487ecddd2b31ec0aa42ba425942a0c0d071 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 1 Jan 2019 01:11:08 +1300 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 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 -- cgit v1.2.3