diff options
Diffstat (limited to 'sh')
-rw-r--r-- | sh/profile | 41 | ||||
-rw-r--r-- | sh/profile.d/browser.sh | 4 | ||||
-rw-r--r-- | sh/profile.d/downloads.sh | 33 | ||||
-rw-r--r-- | sh/profile.d/editor.sh | 25 | ||||
-rw-r--r-- | sh/profile.d/games.sh | 3 | ||||
-rw-r--r-- | sh/profile.d/lang.sh | 4 | ||||
-rw-r--r-- | sh/profile.d/os.sh | 3 | ||||
-rw-r--r-- | sh/profile.d/pager.sh | 7 | ||||
-rw-r--r-- | sh/profile.d/timezone.sh | 3 | ||||
-rw-r--r-- | sh/profile.d/visual.sh | 14 | ||||
-rw-r--r-- | sh/profile.d/welcome.sh | 53 | ||||
-rw-r--r-- | sh/shrc | 4 | ||||
-rw-r--r-- | sh/shrc.d/ed.sh | 2 | ||||
-rw-r--r-- | sh/shrc.d/gdb.sh | 2 | ||||
-rw-r--r-- | sh/shrc.d/ls.sh | 10 | ||||
-rw-r--r-- | sh/shrc.d/path.sh | 8 | ||||
-rw-r--r-- | sh/shrc.d/pd.sh | 2 | ||||
-rw-r--r-- | sh/shrc.d/prompt.sh | 7 | ||||
-rw-r--r-- | sh/shrc.d/rd.sh | 1 | ||||
-rw-r--r-- | sh/shrc.d/sd.sh | 1 | ||||
-rw-r--r-- | sh/shrc.d/tor.sh | 33 | ||||
-rw-r--r-- | sh/shrc.d/which.sh | 2 | ||||
-rw-r--r-- | sh/shrc.d/x.sh | 7 |
23 files changed, 80 insertions, 189 deletions
@@ -1,17 +1,38 @@ -# Add ~/.local/bin to PATH if it exists -if [ -d "$HOME"/.local/bin ] ; then - PATH=$HOME/.local/bin:$PATH -fi +# Use lynx as our terminal browser +BROWSER=lynx +export BROWSER -# Load all supplementary scripts in ~/.profile.d +# Use ed as our line editor and vi as our visual editor +EDITOR=ed +VISUAL=vi +export EDITOR VISUAL + +# Set the POSIX interactive startup file to ~/.shinit +ENV=$HOME/.shinit +export ENV + +# Use NZ English, but bytewise sorting +LANG=en_NZ.UTF-8 +LANGUAGE=en_NZ:en +LC_COLLATE=C +export LANG LANGUAGE LC_COLLATE + +# Use less as my pager +PAGER=less +export PAGER + +# Assume I'm at home unless something overrides it +TZ=Pacific/Auckland +export TZ + +# Source all scripts in ~/.profile.d; many of them will be modifying $PATH, so +# we'll get that sorted out first for sh in "$HOME"/.profile.d/*.sh ; do [ -e "$sh" ] || continue . "$sh" done unset -v sh -# If ~/.shinit exists, set ENV to that -if [ -f "$HOME"/.shinit ] ; then - ENV=$HOME/.shinit - export ENV -fi +# Add ~/.local/bin and ~/.local/games to the very front of PATH, so that it +# overrides everything else +PATH=$HOME/.local/bin:$HOME/.local/games:$PATH diff --git a/sh/profile.d/browser.sh b/sh/profile.d/browser.sh deleted file mode 100644 index 2c724505..00000000 --- a/sh/profile.d/browser.sh +++ /dev/null @@ -1,4 +0,0 @@ -# Set command-line browser to lynx; ~/.xinitrc will change this to something -# graphical instead -BROWSER=lynx -export BROWSER diff --git a/sh/profile.d/downloads.sh b/sh/profile.d/downloads.sh deleted file mode 100644 index 1a89bc3f..00000000 --- a/sh/profile.d/downloads.sh +++ /dev/null @@ -1,33 +0,0 @@ -# Only if shell is interactive -case $- in - *i*) ;; - *) return ;; -esac - -# Only if not in a tmux window -[ -z "$TMUX" ] || return - -# Not if ~/.hushlogin exists -! [ -e "$HOME"/.hushlogin ] || return - -# Not if ~/.downloads doesn't -[ -f "$HOME"/.downloads ] || return - -# Count files in each directory, report if greater than zero -( - lc=0 - while IFS= read -r dir ; do - case $dir in - '#'*) continue ;; - esac - [ -d "$dir" ] || continue - set -- "$dir"/* - [ -e "$1" ] || shift - [ "$#" -gt 0 ] || continue - printf 'You have %u unsorted files in %s.\n' "$#" "$dir" - lc=$((lc+1)) - done < "$HOME"/.downloads - if [ "$lc" -gt 0 ] ; then - printf '\n' - fi -) diff --git a/sh/profile.d/editor.sh b/sh/profile.d/editor.sh deleted file mode 100644 index 37146fb9..00000000 --- a/sh/profile.d/editor.sh +++ /dev/null @@ -1,25 +0,0 @@ -# Ideally, we'd use plain old ed(1), but many Linux distributions don't install -# it by default -if command -v ed >/dev/null 2>&1 ; then - EDITOR='ed' - -# 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 '{print $1;exit}') - case $ver in - (VIM) exit 0 ;; - (*) exit 1 ;; - esac -) >/dev/null 2>&1 ; then - EDITOR='exm' - -# Otherwise, we can just call ex(1) directly -else - EDITOR='ex' -fi - -export EDITOR diff --git a/sh/profile.d/games.sh b/sh/profile.d/games.sh deleted file mode 100644 index 956d1de1..00000000 --- a/sh/profile.d/games.sh +++ /dev/null @@ -1,3 +0,0 @@ -# Add ~/.local/games to PATH if it exists -[ -d "$HOME"/.local/games ] || return -PATH=$PATH:$HOME/.local/games diff --git a/sh/profile.d/lang.sh b/sh/profile.d/lang.sh deleted file mode 100644 index 21f67d5b..00000000 --- a/sh/profile.d/lang.sh +++ /dev/null @@ -1,4 +0,0 @@ -# Always use bytewise sorting if not already set -[ -z "$LC_COLLATE" ] || return -LC_COLLATE=C -export LC_COLLATE diff --git a/sh/profile.d/os.sh b/sh/profile.d/os.sh deleted file mode 100644 index f9d5a79b..00000000 --- a/sh/profile.d/os.sh +++ /dev/null @@ -1,3 +0,0 @@ -# Store the operating system in an environment variable -OS=$(uname) -export OS diff --git a/sh/profile.d/pager.sh b/sh/profile.d/pager.sh deleted file mode 100644 index f0c4fab4..00000000 --- a/sh/profile.d/pager.sh +++ /dev/null @@ -1,7 +0,0 @@ -# If we don't have less(1), we'll just use whatever pager the application or -# system deems fit -command -v less >/dev/null 2>&1 || return - -# Use less(1) as my PAGER -PAGER=less -export PAGER diff --git a/sh/profile.d/timezone.sh b/sh/profile.d/timezone.sh deleted file mode 100644 index cbd33539..00000000 --- a/sh/profile.d/timezone.sh +++ /dev/null @@ -1,3 +0,0 @@ -# Timezone -TZ=Pacific/Auckland -export TZ diff --git a/sh/profile.d/visual.sh b/sh/profile.d/visual.sh deleted file mode 100644 index eb3c1143..00000000 --- a/sh/profile.d/visual.sh +++ /dev/null @@ -1,14 +0,0 @@ -# For a visual editor, use Vim explicitly if we've got it, but otherwise any vi -# implementation will be fine -if command -v vim >/dev/null 2>&1 ; then - VISUAL='vim' -else - VISUAL='vi' -fi -export VISUAL - -# If systemctl is installed, use $VISUAL as its editor, not $EDITOR -if command -v systemctl >/dev/null 2>&1 ; then - SYSTEMD_EDITOR=$VISUAL - export SYSTEMD_EDITOR -fi diff --git a/sh/profile.d/welcome.sh b/sh/profile.d/welcome.sh deleted file mode 100644 index 19231c2e..00000000 --- a/sh/profile.d/welcome.sh +++ /dev/null @@ -1,53 +0,0 @@ -# Only if shell is interactive -case $- in - *i*) ;; - *) return ;; -esac - -# Only if not in a tmux window -[ -z "$TMUX" ] || return - -# Only if ~/.hushlogin doesn't exist -! [ -e "$HOME"/.hushlogin ] || return - -# Run all of this in a subshell to clear it away afterwards -( - # Temporary helper function - welcome() { - test -e "${XDG_CONFIG_HOME:-"$HOME"/.config}"/welcome/"$1" - } - - # Show a fortune - if welcome fortune ; then - if [ -z "$FORTUNE_PATH" ] ; then - FORTUNE_PATH=${XDG_DATA_HOME:-$HOME}/.local/share/fortune - set -- "$FORTUNE_PATH"/*.dat - if ! [ -e "$1" ] ; then - FORTUNE_PATH= - fi - fi - fortune -s "$FORTUNE_PATH" - printf '\n' - fi - - # Print today's reminders with asterisks - if welcome rem ; then - rem -hq | sed 's/^/* /' - printf '\n' - fi - - # Run verse(1) if we haven't seen it already today - if welcome verse ; then - cache=${XDG_CACHE_HOME:-$HOME/.cache}/welcome - mkdir -p -- "$cache" || return - if [ -f "$cache"/verse ] ; then - read -r last <"$cache"/verse - fi - now=$(date +%Y%m%d) - if [ "$now" -gt "${last:-0}" ] ; then - verse - printf '\n' - printf '%s\n' "$now" >"$cache"/verse - fi - fi -) @@ -4,8 +4,8 @@ command -p mesg n 2>/dev/null # Turn off flow control and control character echo command -p stty -ixon -ctlecho 2>/dev/null -# Keep around 4K lines of history in memory -HISTSIZE=$((1 << 12)) +# Keep around 16K lines of history in memory +HISTSIZE=16384 # If HOSTNAME isn't set by this shell, we'll do it if [ -z "$HOSTNAME" ] ; then diff --git a/sh/shrc.d/ed.sh b/sh/shrc.d/ed.sh index dc8433f6..0591e18d 100644 --- a/sh/shrc.d/ed.sh +++ b/sh/shrc.d/ed.sh @@ -22,7 +22,7 @@ ed() { # Run in rlwrap(1) if available set -- ed "$@" if command -v rlwrap >/dev/null 2>&1 ; then - set -- rlwrap --history-filename=/dev/null "$@" + set -- rlwrap --history-filename=/dev/null --no-warnings "$@" fi # Run determined command diff --git a/sh/shrc.d/gdb.sh b/sh/shrc.d/gdb.sh index ec9d4137..4fb459cb 100644 --- a/sh/shrc.d/gdb.sh +++ b/sh/shrc.d/gdb.sh @@ -1,4 +1,4 @@ # Don't print the GDB copyright message on every invocation gdb() { - command gdb -q "$@" + command gdb --quiet "$@" } diff --git a/sh/shrc.d/ls.sh b/sh/shrc.d/ls.sh index c6558fc3..6fbfbf61 100644 --- a/sh/shrc.d/ls.sh +++ b/sh/shrc.d/ls.sh @@ -41,16 +41,6 @@ ls() { set -- --time-style='+%Y-%m-%d %H:%M:%S' "$@" fi - # If the operating system is FreeBSD, there are some specific options we - # can add that might mean different things to e.g. GNU ls(1) - case $OS in - FreeBSD) - # -D: Timestamp format - # -G: Use color - set -- -D '%Y-%m-%d %H:%M:%S' -G "$@" - ;; - esac - # Run ls(1) with the concluded arguments command ls "$@" } diff --git a/sh/shrc.d/path.sh b/sh/shrc.d/path.sh index a854e148..812f5f0f 100644 --- a/sh/shrc.d/path.sh +++ b/sh/shrc.d/path.sh @@ -130,7 +130,7 @@ path(): Manage contents of PATH variable USAGE: path [list] - Print the current directories in PATH, one per line (default command) + Print the current directories in PATH, one per line (default) path insert [DIR] Add directory DIR (default $PWD) to the front of PATH path append [DIR] @@ -142,7 +142,7 @@ USAGE: path pop Remove the last directory from PATH path check [DIR] - Return whether directory DIR (default $PWD) is a component of PATH + Return whether directory DIR (default $PWD) is in PATH path help Print this help message EOF @@ -150,7 +150,9 @@ EOF # Command not found *) - printf >&2 'path(): %s: Unknown command (try "help")\n' "$1" + printf >&2 \ + 'path(): %s: Unknown command (try "help")\n' \ + "$1" return 2 ;; esac diff --git a/sh/shrc.d/pd.sh b/sh/shrc.d/pd.sh index 77f6bae9..e99049d3 100644 --- a/sh/shrc.d/pd.sh +++ b/sh/shrc.d/pd.sh @@ -2,8 +2,6 @@ # use when you've got a file path in a variable, or in history, or in Alt+., # and want to quickly move to its containing directory. In the absence of an # argument, this just shifts up a directory, i.e. `cd ..` -# -# Note this is equivalent to `ud 1`. pd() { # Check arguments; default to $PWD diff --git a/sh/shrc.d/prompt.sh b/sh/shrc.d/prompt.sh index cb32c113..72cf59b6 100644 --- a/sh/shrc.d/prompt.sh +++ b/sh/shrc.d/prompt.sh @@ -11,8 +11,7 @@ PS3='? ' unset PS4 PS4='+ ' -# If we have an SSH_CLIENT or SSH_CONNECTION environment variable, put the -# hostname in PS1 too. -if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_CONNECTION" ] ; then - PS1=$(hostname -s)'$ ' +# Prompt has hostname via SSH outside of screen/tmux +if [ -n "$SSH_CLIENT" ] && [ -z "$STY" ] && [ -z "$TMUX" ] ; then + PS1=$(hostname -s)$PS1 fi diff --git a/sh/shrc.d/rd.sh b/sh/shrc.d/rd.sh index e6d761a6..3e1b4d9c 100644 --- a/sh/shrc.d/rd.sh +++ b/sh/shrc.d/rd.sh @@ -11,6 +11,7 @@ # $ rd usr opt # $ pwd # /opt/bin +# rd() { # Check argument count diff --git a/sh/shrc.d/sd.sh b/sh/shrc.d/sd.sh index 10597832..1fe748c4 100644 --- a/sh/shrc.d/sd.sh +++ b/sh/shrc.d/sd.sh @@ -30,6 +30,7 @@ # /tmp/tmp.ZSunna5Eup/a # # Seems to work for symbolic links. +# sd() { # Check argument count diff --git a/sh/shrc.d/tor.sh b/sh/shrc.d/tor.sh new file mode 100644 index 00000000..e6e31341 --- /dev/null +++ b/sh/shrc.d/tor.sh @@ -0,0 +1,33 @@ +# Manage Torsocks for the current shell +tor() { + + # Check first argument to figure out operation + case $1 in + + # Show whether Torsocks + show|'') + case $LD_PRELOAD: in + (*/libtorsocks.so:*) + printf 'on\n' + ;; + (*) + printf 'off\n' + ;; + esac + ;; + + # Turn Torsocks on or off + on|off) + command -v torsocks >/dev/null 2>&1 || return + . "$(command -v torsocks)" + ;; + + # Command not found + *) + printf >&2 \ + 'tor(): %s: Unknown command (try "help")\n' \ + "$1" + return 2 + ;; + esac +} diff --git a/sh/shrc.d/which.sh b/sh/shrc.d/which.sh index 9d8c899a..528e5048 100644 --- a/sh/shrc.d/which.sh +++ b/sh/shrc.d/which.sh @@ -1,3 +1,5 @@ +# Try to stop me using the non-standard `which`: +# <http://mywiki.wooledge.org/BadUtils#which> which() { printf >&2 'Whichcraft detected! Did you mean: command -v %s\n' "$*" return 2 diff --git a/sh/shrc.d/x.sh b/sh/shrc.d/x.sh deleted file mode 100644 index ed921c68..00000000 --- a/sh/shrc.d/x.sh +++ /dev/null @@ -1,7 +0,0 @@ -# Most systems won't have X, so we'll only define this if we have startx(1) -command -v startx >/dev/null 2>&1 || return - -# Quick one-key command to launch an X session -x() { - exec startx "$@" -} |