aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-01-25 12:29:38 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-01-25 12:29:38 +1300
commitca762232041168ab7f6f02c66fb6b36bd0a582dd (patch)
treee7d9d68a0e0e68209857ec0d0373f766d8c8ec93 /sh
parentMerge branch 'master' into port/bsd/freebsd (diff)
parentBe more specific in ref name trimming (diff)
downloaddotfiles-ca762232041168ab7f6f02c66fb6b36bd0a582dd.tar.gz
dotfiles-ca762232041168ab7f6f02c66fb6b36bd0a582dd.zip
Merge branch 'master' into port/bsd/freebsd
Diffstat (limited to 'sh')
-rw-r--r--sh/profile.d/lang.sh4
-rw-r--r--sh/profile.d/options.sh11
-rw-r--r--sh/shrc.d/gd.sh2
-rw-r--r--sh/shrc.d/grep.sh3
-rw-r--r--sh/shrc.d/less.sh2
-rw-r--r--sh/shrc.d/ls.sh28
-rw-r--r--sh/shrc.d/md.sh13
-rw-r--r--sh/shrc.d/path.sh55
-rw-r--r--sh/shrc.d/pmd.sh2
-rw-r--r--sh/shrc.d/prompt.sh5
-rw-r--r--sh/shrc.d/tmux.sh19
-rw-r--r--sh/shrc.d/vr.sh15
-rw-r--r--sh/shrc.d/xd.sh2
13 files changed, 93 insertions, 68 deletions
diff --git a/sh/profile.d/lang.sh b/sh/profile.d/lang.sh
new file mode 100644
index 00000000..21f67d5b
--- /dev/null
+++ b/sh/profile.d/lang.sh
@@ -0,0 +1,4 @@
+# Always use bytewise sorting if not already set
+[ -z "$LC_COLLATE" ] || return
+LC_COLLATE=C
+export LC_COLLATE
diff --git a/sh/profile.d/options.sh b/sh/profile.d/options.sh
index aa7e9ace..345888d0 100644
--- a/sh/profile.d/options.sh
+++ b/sh/profile.d/options.sh
@@ -46,12 +46,9 @@ options grep \
# Cache options for ls(1)
options ls \
- almost-all \
- block-size \
- classify \
- color \
- format \
- hide-control-chars \
- human-readable \
+ almost-all \
+ block-size \
+ color \
+ human-readable \
time-style
)
diff --git a/sh/shrc.d/gd.sh b/sh/shrc.d/gd.sh
index 5a3f54b0..fa5776f2 100644
--- a/sh/shrc.d/gd.sh
+++ b/sh/shrc.d/gd.sh
@@ -10,7 +10,7 @@ gd() {
# Complain if mark not actually set yet
if ! [ -n "$PMD" ] ; then
printf >&2 'gd(): Mark not set\n'
- return 2
+ return 1
fi
# Go to the marked directory
diff --git a/sh/shrc.d/grep.sh b/sh/shrc.d/grep.sh
index a52b6f90..fc8f62c0 100644
--- a/sh/shrc.d/grep.sh
+++ b/sh/shrc.d/grep.sh
@@ -2,6 +2,9 @@
# options for us; if not, we won't be wrapping grep(1) with a function at all
[ -d "$HOME"/.cache/grep ] || return
+# Discard GNU grep(1) environment variables if the environment set them
+unset -v GREP_OPTIONS
+
# Define function proper
grep() {
diff --git a/sh/shrc.d/less.sh b/sh/shrc.d/less.sh
new file mode 100644
index 00000000..2778ce65
--- /dev/null
+++ b/sh/shrc.d/less.sh
@@ -0,0 +1,2 @@
+# Unset stupid env vars to avoid interfering with my less(1) setup
+unset -v LESS LESSOPEN
diff --git a/sh/shrc.d/ls.sh b/sh/shrc.d/ls.sh
index 7e916239..58263e96 100644
--- a/sh/shrc.d/ls.sh
+++ b/sh/shrc.d/ls.sh
@@ -2,34 +2,32 @@
# options for us; if not, we won't be wrapping ls(1) with a function at all
[ -d "$HOME"/.cache/ls ] || return
+# If the system has already aliased ls(1) for us, like Slackware or OpenBSD
+# does, just get rid of it
+unalias ls >/dev/null 2>&1
+
+# Discard GNU ls(1) environment variables if the environment set them
+unset -v LS_OPTIONS LS_COLORS
+
# Define function proper
ls() {
+ # -F to show trailing indicators of the filetype
+ # -q to replace control chars with '?'
+ # -x to format entries across, not down
+ set -- -Fqx "$@"
+
# Add --block-size=K to always show the filesize in kibibytes
[ -e "$HOME"/.cache/ls/block-size ] &&
set -- --block-size=1024 "$@"
- # Add --classify to show trailing indicators of the filetype
- [ -e "$HOME"/.cache/ls/classify ] &&
- set -- --classify "$@"
-
# Add --color if the terminal has at least 8 colors
[ -e "$HOME"/.cache/ls/color ] &&
[ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] &&
set -- --color=auto "$@"
- # Add --format=horizontal to print entries in a saner way
- [ -e "$HOME"/.cache/ls/format ] &&
- set -- --format=horizontal "$@"
-
- # Add --hide-control-chars if present; we always want this interactively,
- # even if the output is to a pager; we shouldn't be trying to script ls(1)
- # output anyway
- [ -e "$HOME"/.cache/ls/hide-control-chars ] &&
- set -- --hide-control-chars "$@"
-
# Add --time-style='+%Y-%m-%d %H:%M:%S' to show the date in my preferred
- # format
+ # (fixed) format
[ -e "$HOME"/.cache/ls/time-style ] &&
set -- --time-style='+%Y-%m-%d %H:%M:%S' "$@"
diff --git a/sh/shrc.d/md.sh b/sh/shrc.d/md.sh
index 6fd3d7ca..a7134931 100644
--- a/sh/shrc.d/md.sh
+++ b/sh/shrc.d/md.sh
@@ -7,11 +7,14 @@ md() {
return 2
fi
- # If first arg unset or empty, assume the user means the current dir
- [ -n "$1" ] || set -- "$PWD"
-
- # Jump to the dir and emit PWD from a subshell to get an absolute path
- set -- "$(cd -- "$1" && printf %s "$PWD")"
+ # If argument given, change to it in subshell to get absolute path.
+ # If not, use current working directory.
+ if [ -n "$1" ] ; then
+ set -- "$(cd -- "$1" && printf '%s/' "$PWD")"
+ set -- "${1%%/}"
+ else
+ set -- "$PWD"
+ fi
# If that turned up empty, we have failed; the cd call probably threw an
# error for us too
diff --git a/sh/shrc.d/path.sh b/sh/shrc.d/path.sh
index 3caabbc9..23eec75b 100644
--- a/sh/shrc.d/path.sh
+++ b/sh/shrc.d/path.sh
@@ -24,10 +24,28 @@ path() {
done
) ;;
+ # Helper function checks directory argument makes sense
+ _argcheck)
+ shift
+ if [ "$#" -gt 2 ] ; then
+ printf >&2 'path(): %s: too many arguments\n' "$1"
+ return 2
+ fi
+ case $2 in
+ *:*)
+ printf >&2 'path(): %s: %s contains colon\n' "$@"
+ return 2
+ ;;
+ esac
+ return 0
+ ;;
+
# Add a directory at the start of $PATH
insert)
+ [ "$#" -eq 2 ] || set -- "$1" "$PWD"
+ path _argcheck "$@" || return
if path check "$2" ; then
- printf >&2 'path(): %s already in PATH\n' "$2"
+ printf >&2 'path(): %s: %s already in PATH\n' "$@"
return 1
fi
PATH=${2}${PATH:+:"$PATH"}
@@ -35,8 +53,10 @@ path() {
# Add a directory to the end of $PATH
append)
+ [ "$#" -eq 2 ] || set -- "$1" "$PWD"
+ path _argcheck "$@" || return
if path check "$2" ; then
- printf >&2 'path(): %s already in PATH\n' "$2"
+ printf >&2 'path(): %s: %s already in PATH\n' "$@"
return 1
fi
PATH=${PATH:+"$PATH":}${2}
@@ -44,21 +64,25 @@ path() {
# Remove a directory from $PATH
remove)
+ [ "$#" -eq 2 ] || set -- "$1" "$PWD"
+ path _argcheck "$@" || return
if ! path check "$2" ; then
- printf >&2 'path(): %s not in PATH\n' "$2"
+ printf >&2 'path(): %s: %s not in PATH\n' "$@"
return 1
fi
PATH=$(
path=:$PATH:
path=${path%%:"$2":*}:${path#*:"$2":}
path=${path#:}
- path=${path%:}
- printf '%s\n' "$path"
+ printf '%s:' "$path"
)
+ PATH=${PATH%%:}
;;
# Check whether a directory is in PATH
check)
+ path _argcheck "$@" || return
+ [ "$#" -eq 2 ] || set -- "$1" "$PWD"
case :$PATH: in
*:"$2":*) return 0 ;;
esac
@@ -73,23 +97,22 @@ path(): Manage contents of PATH variable
USAGE:
path [list]
Print the current directories in PATH, one per line (default command)
- path insert DIR
- Add a directory to the front of PATH
- path append DIR
- Add a directory to the end of PATH
- path remove DIR
- Remove directory from PATH
- path check DIR
- Return whether DIR is a component of PATH
+ path insert [DIR]
+ Add directory DIR (default $PWD) to the front of PATH
+ path append [DIR]
+ Add directory DIR (default $PWD) to the end of PATH
+ path remove [DIR]
+ Remove directory DIR (default $PWD) from PATH
+ path check [DIR]
+ Return whether directory DIR (default $PWD) is a component of PATH
path help
- Print this help message (also done if command not found)
+ Print this help message
EOF
;;
# Command not found
*)
- printf >&2 'path(): Unknown command\n'
- path help >&2
+ printf >&2 'path(): %s: Unknown command (try "help")\n' "$1"
return 2
;;
esac
diff --git a/sh/shrc.d/pmd.sh b/sh/shrc.d/pmd.sh
index 03f18b7b..c96a50bd 100644
--- a/sh/shrc.d/pmd.sh
+++ b/sh/shrc.d/pmd.sh
@@ -2,7 +2,7 @@
pmd() {
if ! [ -n "$PMD" ] ; then
printf >&2 'pmd(): Mark not set\n'
- return 2
+ return 1
fi
printf '%s\n' "$PMD"
}
diff --git a/sh/shrc.d/prompt.sh b/sh/shrc.d/prompt.sh
new file mode 100644
index 00000000..a481b5bb
--- /dev/null
+++ b/sh/shrc.d/prompt.sh
@@ -0,0 +1,5 @@
+# Some systems' /etc/profile setups export PS1, which really fouls things up
+# when switching between non-login shells; let's put things right by unsetting
+# it to break the export and then just setting them as simple variables
+unset PS1 PS2 PS3 PS4
+PS1='$ ' PS2='> ' PS3='? ' PS4='+ '
diff --git a/sh/shrc.d/tmux.sh b/sh/shrc.d/tmux.sh
deleted file mode 100644
index bd954be8..00000000
--- a/sh/shrc.d/tmux.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-# Attach to existing tmux session rather than create a new one if possible
-tmux() {
-
- # If given any arguments, just use them as they are
- if [ "$#" -gt 0 ] ; then
- :
-
- # If a session exists, just attach to it
- elif command tmux has-session 2>/dev/null ; then
- set -- attach-session -d
-
- # Create a new session with an appropriate name
- else
- set -- new-session -s "${TMUX_SESSION:-default}"
- fi
-
- # Execute with concluded arguments
- command tmux "$@"
-}
diff --git a/sh/shrc.d/vr.sh b/sh/shrc.d/vr.sh
index 1902e3ba..8b35357c 100644
--- a/sh/shrc.d/vr.sh
+++ b/sh/shrc.d/vr.sh
@@ -19,10 +19,16 @@ vr() {
cd -- "$path" || exit
# Ask Git the top level (good)
- git rev-parse --show-toplevel 2>/dev/null && exit
+ if git rev-parse --show-toplevel 2>/dev/null ; then
+ printf /
+ exit
+ fi
# Ask Mercurial the top level (great)
- hg root 2>/dev/null && exit
+ if hg root 2>/dev/null ; then
+ printf /
+ exit
+ fi
# If we can get SVN info, iterate upwards until we cannot; hopefully
# that is the root (bad)
@@ -32,7 +38,7 @@ vr() {
cd .. || exit
done
if [ -n "$root" ] ; then
- printf '%s\n' "$root"
+ printf '%s\n/' "$root"
exit
fi
@@ -41,6 +47,9 @@ vr() {
exit 1
)"
+ # Chop the trailing newline and slash
+ set -- "${1%?/}"
+
# Check we figured out a target, or bail
[ -n "$1" ] || return
diff --git a/sh/shrc.d/xd.sh b/sh/shrc.d/xd.sh
index 01b8fd3a..40319cf2 100644
--- a/sh/shrc.d/xd.sh
+++ b/sh/shrc.d/xd.sh
@@ -10,7 +10,7 @@ xd() {
# Complain if mark not actually set yet
if ! [ -n "$PMD" ] ; then
printf >&2 'gd(): Mark not set\n'
- return 2
+ return 1
fi
# Put the current and marked directories into positional params