diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2022-11-23 23:35:59 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-11-24 12:42:27 -0700 |
commit | c67d4836f4d6d5e6c8ef4e2de38bd21ccb6ee1a1 (patch) | |
tree | fded906652b6bf03c60e0c133a368c5027cd4d1e /archive/.shenv | |
parent | aa5a315a0876431105f73da75de9ddfa89e907d3 (diff) | |
download | dotfiles-c67d4836f4d6d5e6c8ef4e2de38bd21ccb6ee1a1.tar.gz |
tidy and simplify shell init
Rely on SPWCRONTAB property to set PATH for cronjobs, and otherwise rely on
.profile, .xsessionrc etc. to set PATH, once, at login. Just archive scripts
I haven't used lately which might otherwise need more significant adjustments,
or appear to be broken in other ways.
Diffstat (limited to 'archive/.shenv')
-rwxr-xr-x | archive/.shenv | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/archive/.shenv b/archive/.shenv new file mode 100755 index 00000000..d461cc84 --- /dev/null +++ b/archive/.shenv @@ -0,0 +1,107 @@ +#!/bin/sh + +# Environment variables for X and all text-mode shells: bash, Xsession +# and scripts run by cron all source this. So POSIX only. + +# We have calls to `which` which we expect to fail +set +e + +# ---- choose editor depending on what's available + +if [ "$DESKTOP_SESSION" = "i3" ] \ + || [ "$DESKTOP_SESSION" = "xfce" ] \ + || [ "XDG_CURRENT_DESKTOP" = "sway" ]; then + ec_opt="-c" +else + ec_opt="-t" +fi + +# Either GNU Emacs, or UNIX vi -- lightweight Emacs alternatives like mg and +# zile are so rarely installed, so let's have a constant fallback which is +# almost certainly available and which I can use well enough. +# +# Rely on my ~/src/dotfiles/bin/emacsclient wrapper to start up an Emacs +# daemon: don't bother setting ALTERNATE_EDITOR. Check that there's an Emacs +# on (as yet unmodified) PATH, else that wrapper might fail. +if command -v emacs >/dev/null; then + EDITOR="emacsclient $ec_opt" +else + EDITOR="vi" +fi +unset ec_opt +export EDITOR +VISUAL="$EDITOR" +export VISUAL + +# ---- set $PATH + +# this function prepends $addition to $PATH iff $addition isn't +# already in $PATH and $addition is a directory +maybe_add_to_path () +{ + if ! echo $PATH | grep -q "$addition"; then + if [ -d "$addition" ]; then + PATH="$addition:$PATH" + fi + fi +} + +addition="/sbin"; maybe_add_to_path +addition="/usr/sbin"; maybe_add_to_path +addition="/usr/local/bin"; maybe_add_to_path +addition="/usr/pkg/bin"; maybe_add_to_path +addition="$HOME/local/pkg/bin"; maybe_add_to_path +addition="$HOME/local/pkg/sbin"; maybe_add_to_path +addition="$HOME/src/dotfiles/bin"; maybe_add_to_path +addition="$HOME/local/bin"; maybe_add_to_path +addition="$HOME/.cabal/bin"; maybe_add_to_path +addition="$HOME/.local/bin"; maybe_add_to_path +addition="/meta/s/spw/local/src/git-annex.linux"; maybe_add_to_path +unset addition + +export PATH + +# ---- package management by Nix: add to $PATH once more + +# # crude heuristic to determine if it's already been added +# if ! echo $PATH | grep -q "$HOME/.nix-profile/bin"; then +# if [ -e "/etc/profile.d/nix.sh" ]; then +# . /etc/profile.d/nix.sh +# fi +# fi + +# ---- set language (snippet from joeyh's home-etc.git repo) + +# TODO: according to <https://wiki.debian.org/Locale>, I ought not to +# be setting LC_ALL. Instead I could set most of LC_* to en_GB.UTF-8, +# and some e.g. LC_PAPER to en_US.UTF-8. + +# disabled: propellor setting it system-wide on my machines and that's +# enough + +# case " $(echo $(locale -a)) " in +# *\ en_GB.utf8\ *) LANG=en_GB.utf8 ;; +# *\ en_GB.UTF-8\ *) LANG=en_GB.UTF-8 ;; +# *\ C.UTF-8\ *) LANG=C.UTF-8 ;; +# *\ C.utf8\ *) LANG=C.utf8 ;; +# *) unset LANG ;; +# esac + +# LC_ALL=$LANG +# export LC_ALL +# export LANG + +# ---- further preferences + +# LD_RUN_PATH="$HOME/local/lib/" +# export LD_RUN_PATH +# LD_LIBRARY_PATH="$HOME/local/lib/" +# export LD_LIBRARY_PATH + +# "Setting the monitor port to 0 turns the monitoring function off, +# and autossh will only restart ssh upon ssh's exit." +# +# We rely on ServerAliveInterval and ServerAliveCountMax set in ~/.ssh/config +AUTOSSH_PORT=0 +export AUTOSSH_PORT + |