From efd95c34c7db7686600571243ca00196276fa0ad Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 12 Apr 2017 09:51:27 +1200 Subject: Use more logical ~/.cache subpath --- sh/profile.d/options.sh | 2 +- sh/shrc.d/bc.sh | 4 ++-- sh/shrc.d/ed.sh | 2 +- sh/shrc.d/grep.sh | 14 +++++++------- sh/shrc.d/la.sh | 2 +- sh/shrc.d/ll.sh | 2 +- sh/shrc.d/ls.sh | 8 ++++---- 7 files changed, 17 insertions(+), 17 deletions(-) (limited to 'sh') diff --git a/sh/profile.d/options.sh b/sh/profile.d/options.sh index 1a511d75..89b5d245 100644 --- a/sh/profile.d/options.sh +++ b/sh/profile.d/options.sh @@ -5,7 +5,7 @@ options() { # Check or create the directory to cache the options # Shift the program name off; remaining arguments are the options to check - dir=$HOME/.cache/$1 + dir=$HOME/.cache/sh/opt/$1 prog=$1 shift diff --git a/sh/shrc.d/bc.sh b/sh/shrc.d/bc.sh index 41331ff9..aee88e09 100644 --- a/sh/shrc.d/bc.sh +++ b/sh/shrc.d/bc.sh @@ -1,12 +1,12 @@ # Our ~/.profile should already have made a directory with the supported # options for us; if not, we won't be wrapping bc(1) with a function at all -[ -d "$HOME"/.cache/bc ] || return +[ -d "$HOME"/.cache/sh/opt/bc ] || return # Define function proper bc() { # Add --quiet to stop the annoying welcome banner - [ -e "$HOME"/.cache/bc/quiet ] && + [ -e "$HOME"/.cache/sh/opt/bc/quiet ] && set -- --quiet "$@" # Run bc(1) with the concluded arguments diff --git a/sh/shrc.d/ed.sh b/sh/shrc.d/ed.sh index d7d3fa2f..a2b7818e 100644 --- a/sh/shrc.d/ed.sh +++ b/sh/shrc.d/ed.sh @@ -8,7 +8,7 @@ ed() { fi # Add --verbose to explain errors - [ -e "$HOME"/.cache/ed/verbose ] && + [ -e "$HOME"/.cache/sh/opt/ed/verbose ] && set -- --verbose "$@" # Add an asterisk prompt (POSIX feature) diff --git a/sh/shrc.d/grep.sh b/sh/shrc.d/grep.sh index fc8f62c0..dd85a198 100644 --- a/sh/shrc.d/grep.sh +++ b/sh/shrc.d/grep.sh @@ -1,6 +1,6 @@ # Our ~/.profile should already have made a directory with the supported # options for us; if not, we won't be wrapping grep(1) with a function at all -[ -d "$HOME"/.cache/grep ] || return +[ -d "$HOME"/.cache/sh/opt/grep ] || return # Discard GNU grep(1) environment variables if the environment set them unset -v GREP_OPTIONS @@ -9,31 +9,31 @@ unset -v GREP_OPTIONS grep() { # Add --binary-files=without-match to gracefully skip binary files - [ -e "$HOME"/.cache/grep/binary-files ] && + [ -e "$HOME"/.cache/sh/opt/grep/binary-files ] && set -- --binary-files=without-match "$@" # Add --color=auto if the terminal has at least 8 colors - [ -e "$HOME"/.cache/grep/color ] && + [ -e "$HOME"/.cache/sh/opt/grep/color ] && [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] && set -- --color=auto "$@" # Add --devices=skip to gracefully skip devices - [ -e "$HOME"/.cache/grep/devices ] && + [ -e "$HOME"/.cache/sh/opt/grep/devices ] && set -- --devices=skip "$@" # Add --directories=skip to gracefully skip directories - [ -e "$HOME"/.cache/grep/directories ] && + [ -e "$HOME"/.cache/sh/opt/grep/directories ] && set -- --directories=skip "$@" # Add --exclude to ignore .gitignore and .gitmodules files - [ -e "$HOME"/.cache/grep/exclude ] && + [ -e "$HOME"/.cache/sh/opt/grep/exclude ] && set -- \ --exclude=.gitignore \ --exclude=.gitmodules \ "$@" # Add --exclude-dir to ignore version control dot-directories - [ -e "$HOME"/.cache/grep/exclude-dir ] && + [ -e "$HOME"/.cache/sh/opt/grep/exclude-dir ] && set -- \ --exclude-dir=.cvs \ --exclude-dir=.git \ diff --git a/sh/shrc.d/la.sh b/sh/shrc.d/la.sh index e21ad8fb..1ac44b8e 100644 --- a/sh/shrc.d/la.sh +++ b/sh/shrc.d/la.sh @@ -1,7 +1,7 @@ # Run ls -A if we can (-A is not POSIX), ls -a otherwise la() { # Prefer --almost-all (exclude "." and "..") if available - if [ -e "$HOME"/.cache/ls/almost-all ] ; then + if [ -e "$HOME"/.cache/sh/opt/ls/almost-all ] ; then set -- -A "$@" else set -- -a "$@" diff --git a/sh/shrc.d/ll.sh b/sh/shrc.d/ll.sh index c8c95d3b..e9737c62 100644 --- a/sh/shrc.d/ll.sh +++ b/sh/shrc.d/ll.sh @@ -1,7 +1,7 @@ # Run ls -Al if we can (-A is not POSIX), ls -al otherwise ll() { # Prefer -A/--almost-all (exclude "." and "..") if available - if [ -e "$HOME"/.cache/ls/almost-all ] ; then + if [ -e "$HOME"/.cache/sh/opt/ls/almost-all ] ; then set -- -Al "$@" else set -- -al "$@" diff --git a/sh/shrc.d/ls.sh b/sh/shrc.d/ls.sh index 18f50a8b..b5acfcf9 100644 --- a/sh/shrc.d/ls.sh +++ b/sh/shrc.d/ls.sh @@ -1,6 +1,6 @@ # Our ~/.profile should already have made a directory with the supported # options for us; if not, we won't be wrapping ls(1) with a function at all -[ -d "$HOME"/.cache/ls ] || return +[ -d "$HOME"/.cache/sh/opt/ls ] || return # If the system has already aliased ls(1) for us, like Slackware or OpenBSD # does, just get rid of it @@ -20,17 +20,17 @@ ls() { [ -t 1 ] && set -- -x "$@" # Add --block-size=K to always show the filesize in kibibytes - [ -e "$HOME"/.cache/ls/block-size ] && + [ -e "$HOME"/.cache/sh/opt/ls/block-size ] && set -- --block-size=1024 "$@" # Add --color if the terminal has at least 8 colors - [ -e "$HOME"/.cache/ls/color ] && + [ -e "$HOME"/.cache/sh/opt/ls/color ] && [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] && set -- --color=auto "$@" # Add --time-style='+%Y-%m-%d %H:%M:%S' to show the date in my preferred # (fixed) format - [ -e "$HOME"/.cache/ls/time-style ] && + [ -e "$HOME"/.cache/sh/opt/ls/time-style ] && set -- --time-style='+%Y-%m-%d %H:%M:%S' "$@" # Run ls(1) with the concluded arguments -- cgit v1.2.3 From 57daf35a76506de41dfaf94af78376717943957b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 14 May 2017 22:58:25 +1200 Subject: Move exm(1df) test into EDITOR selection Merely checking for vim(1) is a poor test; we specifically need to know if the ex(1) implementation is Vim, so test it while making the EDITOR decision. --- sh/profile.d/editor.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'sh') diff --git a/sh/profile.d/editor.sh b/sh/profile.d/editor.sh index 307879fe..debb93b6 100644 --- a/sh/profile.d/editor.sh +++ b/sh/profile.d/editor.sh @@ -3,12 +3,21 @@ if command -v ed >/dev/null 2>&1 ; then EDITOR=ed -# Failing that, if we have both vim(1) and exm(1df) in our $PATH, use the -# latter to work around Vim's ex mode screen-clearing -elif { command -v vim && command -v exm ; } >/dev/null 2>&1 ; then +# Failing that, if the system's implementation of ex(1) looks like Vim and we +# have exm(1df) in our $PATH, use the latter to work around Vim's ex mode +# screen-clearing +elif ( + command -v ex >/dev/null 2>&1 || exit 1 + command -v exm >/dev/null 2>&1 || exit 1 + ver=$(ex --version 2>/dev/null | awk 'NR==1{print $1;exit}') + case $ver in + (VIM) exit 0 ;; + (*) exit 1 ;; + esac +) >/dev/null 2>&1 ; then EDITOR=exm -# Otherwise, just call ex(1) directly +# Otherwise, we can just call ex(1) directly else EDITOR=ex fi -- cgit v1.2.3 From 3e0a391732350157ab06bb14ac685160416573fa Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 14 May 2017 22:59:13 +1200 Subject: Just use whichever vi(1) we need as VISUAL This avoids an unwanted situation on e.g. Debian minimal where the default Vi implementation is a stripped-down Vim that doesn't use vim(1) as a name, so stuff like sudoedit(8) breaks looking for it and falls back on EDITOR. --- sh/profile.d/visual.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'sh') diff --git a/sh/profile.d/visual.sh b/sh/profile.d/visual.sh index d03da255..38ab9893 100644 --- a/sh/profile.d/visual.sh +++ b/sh/profile.d/visual.sh @@ -1,7 +1,3 @@ -# Set visual editor; vim if we've got it, but vi will do fine -if command -v vim >/dev/null 2>&1 ; then - VISUAL=vim -else - VISUAL=vi -fi +# Use first found implementation of vi(1) +VISUAL=vi export VISUAL -- cgit v1.2.3