diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-12-03 00:22:17 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-12-03 00:22:17 +1300 |
commit | 3135b4ce8d5974e1dee530928a8aacffe7eac433 (patch) | |
tree | f836bd76271f7c313286bc3ebe69376a0cf45f80 | |
parent | Color compatibility fixes for tlcs(1df) (diff) | |
download | dotfiles-3135b4ce8d5974e1dee530928a8aacffe7eac433.tar.gz dotfiles-3135b4ce8d5974e1dee530928a8aacffe7eac433.zip |
Split ~/.shrc off stub ~/.shinit file
NetBSD sh(1) and possible others don't tolerate a `return` short-circuit
for ENV, which means that because that implementation also sources ENV
if set regardless of whether the shell is interactive or not, all of the
interactive stuff in ~/.shrc and ~/.shrc.d gets uselessly sourced and
loaded up for non-interactive invocations of sh(1).
To work around this, I've set ENV to be a new ~/.shinit file instead,
which sources the ~/.shrc file only if the shell is interactive.
~/.shinit is the filename suggested in the man page for NetBSD sh(1) and
Debian dash(1) as well.
NetBSD's documented behaviour seems to be contrary to POSIX 2003:
> ENV: This variable, when and only when an interactive shell is
> invoked, shall be subjected to parameter expansion (see Parameter
> Expansion ) by the shell, and the resulting value shall be used as a
> pathname of a file containing shell commands to execute in the
> current environment.
No matter; this works fine, and makes non-interactive invocations of
sh(1) on NetBSD much faster.
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | README.markdown | 5 | ||||
-rw-r--r-- | sh/profile | 6 | ||||
-rw-r--r-- | sh/shinit | 4 | ||||
-rw-r--r-- | sh/shrc | 6 |
5 files changed, 11 insertions, 11 deletions
@@ -307,6 +307,7 @@ install-sh : check-sh "$(HOME)"/.shrc.d install -pm 0644 -- sh/profile "$(HOME)"/.profile install -pm 0644 -- sh/profile.d/* "$(HOME)"/.profile.d + install -pm 0644 -- sh/shinit "$(HOME)"/.shinit install -pm 0644 -- sh/shrc "$(HOME)"/.shrc install -pm 0644 -- sh/shrc.d/* "$(HOME)"/.shrc.d diff --git a/README.markdown b/README.markdown index 22f02d42..fc248800 100644 --- a/README.markdown +++ b/README.markdown @@ -97,8 +97,9 @@ they should work in most `sh(1)` implementations. Individual scripts called by management. Most of these boil down to exporting variables appropriate to the system and the software it has available. -Configuration that should be sourced for all POSIX-fearing shells is kept in -`~/.shrc`, with subscripts read from `~/.shrc.d`. +Configuration that should be sourced for all POSIX-fearing interactive shells +is kept in `~/.shrc`, with subscripts read from `~/.shrc.d`. There's a shim in +`~/.shinit` to act as `ENV`. I make an effort to target POSIX for my functions and scripts where I can, but Bash is my interactive shell of choice. My `.bash_profile` calls `.profile`, @@ -7,8 +7,8 @@ for sh in "$HOME"/.profile.d/*.sh ; do done unset -v sh -# If ENV is unset after running those scripts and ~/.shrc exists, set it as ENV -if [ -z "$ENV" ] && [ -f "$HOME"/.shrc ] ; then - ENV=$HOME/.shrc +# If ENV is still unset, and ~/.shinit exists, use that +if [ -z "$ENV" ] && [ -f "$HOME"/.shinit ] ; then + ENV=$HOME/.shinit export ENV fi diff --git a/sh/shinit b/sh/shinit new file mode 100644 index 00000000..fe770a70 --- /dev/null +++ b/sh/shinit @@ -0,0 +1,4 @@ +# If the shell is interactive, source ~/.shrc +case $- in *i*) + [ -f "$HOME"/.shrc ] && . "$HOME"/.shrc ;; +esac @@ -1,9 +1,3 @@ -# Make sure the shell is interactive -case $- in - *i*) ;; - *) return ;; -esac - # Don't let anyone write(1) to my terminal command -p mesg n |