aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/clog.sh3
-rw-r--r--bin/dmp.sh31
-rw-r--r--bin/gscr.sh9
-rw-r--r--bin/han.bash23
-rw-r--r--bin/mked.sh1
-rw-r--r--bin/mktd.sh2
-rw-r--r--bin/mkvi.sh1
-rw-r--r--bin/msc.sh12
-rw-r--r--bin/osc.sh2
-rw-r--r--[-rwxr-xr-x]bin/phpcsff.mi50
-rw-r--r--bin/plmu.sh27
-rw-r--r--bin/qat.sh11
-rw-r--r--bin/rndi.awk3
-rw-r--r--bin/sls.sh3
-rw-r--r--bin/slsf.awk29
-rw-r--r--bin/td.sh2
-rw-r--r--bin/tm.sh9
-rw-r--r--bin/urlmt.sh16
-rw-r--r--bin/uts.awk1
-rw-r--r--bin/xgo.sh15
-rw-r--r--bin/xsnap.sh24
21 files changed, 112 insertions, 112 deletions
diff --git a/bin/clog.sh b/bin/clog.sh
index 3269c508..a5c777e8 100644
--- a/bin/clog.sh
+++ b/bin/clog.sh
@@ -3,7 +3,8 @@
# Build the cat(1) command we'll run, wrapping it in rlwrap(1) if available and
# applicable.
if [ "$#" -eq 0 ] && [ -t 0 ] && command -v rlwrap >/dev/null 2>&1 ; then
- set -- rlwrap --history-filename=/dev/null cat -- "${@:--}"
+ set -- rlwrap --history-filename=/dev/null --no-warnings \
+ cat -- "${@:--}"
else
set -- cat -- "${@:--}"
fi
diff --git a/bin/dmp.sh b/bin/dmp.sh
deleted file mode 100644
index ab09c20e..00000000
--- a/bin/dmp.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-# Pick a pass(1) password with dmenu(1)
-
-# Get the password store directory, bail if we can't
-pwsd=${PASSWORD_STORE_DIR:-"$HOME"/.password-store}
-pwsd=${pwsd%/}
-[ -n "$pwsd" ] || exit
-
-# Get the password; get all the names from find(1)
-# shellcheck disable=SC2016
-pw=$(
- cd -- "$pwsd" || exit
- # Get all the names from find(1)
- find ./ -name \*.gpg |
- # Sort them
- sort |
- # Strip the leading directory and the trailing .gpg
- sed 's_^\./__;s_\.gpg$__' |
- # Use dmenu(1) to prompt the user to select one
- dmenu
-) || exit
-
-# Bail if we don't have a password
-[ -n "$pw" ] || exit
-
-# Pump the first line of the password into the clipboard
-pass show "$pw" | sed 1q | xsel -ib || exit
-
-# If we have notify-send(1), alert that the password has been copied
-if command -v notify-send >/dev/null >&2 ; then
- notify-send "$(printf '%s in clipboard' "$pw")"
-fi
diff --git a/bin/gscr.sh b/bin/gscr.sh
index 2fbee05a..26eafb12 100644
--- a/bin/gscr.sh
+++ b/bin/gscr.sh
@@ -16,11 +16,16 @@ for arg in "${@:-.}" ; do (
;;
esac
+ # Remove any original refs from a prior rewrite
+ if [ -e refs/original ] ; then
+ rm -r -- refs/original || exit
+ fi
+
# Check for bad references or other integrity/sanity problems
- git fsck || exit
+ git fsck --full --no-reflogs || exit
# Expire dangling references
- git reflog expire --expire=now || exit
+ git reflog expire --all --expire=now --expire-unreachable=now || exit
# Remove dangling references
git gc --prune=now --aggressive || exit
diff --git a/bin/han.bash b/bin/han.bash
index 6ab0b3e7..5e5d67c2 100644
--- a/bin/han.bash
+++ b/bin/han.bash
@@ -1,5 +1,4 @@
# Abstract calls to Bash help vs man(1)
-self=han
# Ensure we're using at least version 3.0
# shellcheck disable=SC2128
@@ -13,22 +12,6 @@ if ((BASH_VERSINFO[0] >= 4)) ; then
helpopts=(-m)
fi
-# Create a temporary directory with name in $td, and a trap to remove it when
-# the script exits
-td=
-cleanup() {
- [[ -n $td ]] && rm -fr -- "$td"
-}
-trap cleanup EXIT
-td=$(mktd "$self") || exit
-
-# If we have exactly one argument and a call to the help builtin with that
-# argument succeeds, display its output with `pager -s`
-if (($# == 1)) &&
- help "${helpopts[@]}" "$1" >"$td"/"$1".help 2>/dev/null ; then
- (cd -- "$td" && "$PAGER" -s -- "$1".help)
-
-# Otherwise, just pass all the arguments to man(1)
-else
- man "$@"
-fi
+# Call `help`, with the `-m` flag if available; if it errors out (discard
+# stderr), run `man` instead
+help "${helpopts[@]}" -- "$@" 2>/dev/null || man -- "$@"
diff --git a/bin/mked.sh b/bin/mked.sh
index 93e21573..24a61de8 100644
--- a/bin/mked.sh
+++ b/bin/mked.sh
@@ -1,4 +1,3 @@
-#!/bin/sh
# Create paths to all files before invoking editor
for file do
mkdir -p -- "${file%/*}" || exit
diff --git a/bin/mktd.sh b/bin/mktd.sh
index 72375873..c2ba2ee2 100644
--- a/bin/mktd.sh
+++ b/bin/mktd.sh
@@ -2,7 +2,7 @@
# Build the intended directory name, with the last element a random integer
# from 1..2^31
-lim=$((2 << 31))
+lim=2147483648
dn=${TMPDIR:-/tmp}/${1:-mktd}.$$.$(rndi 1 "$lim")
# Create the directory and print its name if successful
diff --git a/bin/mkvi.sh b/bin/mkvi.sh
index c5974383..ac5c6229 100644
--- a/bin/mkvi.sh
+++ b/bin/mkvi.sh
@@ -1,4 +1,3 @@
-#!/bin/sh
# Create paths to all files before invoking editor
for file do
mkdir -p -- "${file%/*}" || exit
diff --git a/bin/msc.sh b/bin/msc.sh
new file mode 100644
index 00000000..051f104a
--- /dev/null
+++ b/bin/msc.sh
@@ -0,0 +1,12 @@
+# Crudely but quickly count mail in the user's inbox, if we can find it
+username=$(id -nu)
+if [ "$#" -eq 0 ] ; then
+ set -- "$MAIL" /var/mail/"$username" /var/spool/mail/"$username"
+fi
+for path do
+ [ -e "$path" ] || continue
+ grep -ch -- '^From ' "$path"
+ exit
+done
+printf >&2 'Couldn'\''t find user mail spool; provide it as an argument...?\n'
+exit 1
diff --git a/bin/osc.sh b/bin/osc.sh
index 5def12ff..2853f1a5 100644
--- a/bin/osc.sh
+++ b/bin/osc.sh
@@ -17,7 +17,7 @@ serv=${2:-https}
set --
## If we have rlwrap, use it, but don't complain if we don't
if command -v rlwrap >/dev/null 2>&1 ; then
- set -- "$@" rlwrap --history-filename=/dev/null
+ set -- "$@" rlwrap --history-filename=/dev/null --no-warnings
fi
## The actual openssl(1ssl) and subcommand call
set -- "$@" openssl s_client
diff --git a/bin/phpcsff.mi5 b/bin/phpcsff.mi5
index 49f00759..49f00759 100755..100644
--- a/bin/phpcsff.mi5
+++ b/bin/phpcsff.mi5
diff --git a/bin/plmu.sh b/bin/plmu.sh
deleted file mode 100644
index 3f237ae2..00000000
--- a/bin/plmu.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-# Upgrade plenv modules with cpanm(1)
-
-# Set up exceptions file if it exists
-def="$HOME"/.plenv/non-cpanm-modules
-if [ -e "$def" ] ; then
- ef=$def
-else
- ef=/dev/null
-fi
-
-# Check that exceptions file is sorted
-if ! LC_COLLATE=C sort -c -- "$ef" ; then
- printf >&2 '%s not sorted\n' "$ef"
- exit 1
-fi
-
-# Get the list of modules; sort them in case our current locale disagrees on
-# the existing sorting
-plenv list-modules | LC_COLLATE=C sort |
-
-# Exclude any modules in ~/.plenv/non-cpanm-modules if it exists
-LC_COLLATE=C comm -23 -- - "$ef" |
-
-# Read that list of modules to upgrade and upgrade them one by one
-while read -r module ; do
- cpanm --notest --quiet -- "$module"
-done
diff --git a/bin/qat.sh b/bin/qat.sh
new file mode 100644
index 00000000..19acbf5a
--- /dev/null
+++ b/bin/qat.sh
@@ -0,0 +1,11 @@
+restore() {
+ if [ -n "$stty" ] ; then
+ stty "$stty"
+ fi
+}
+trap restore EXIT
+if [ -t 0 ] ; then
+ stty=$(stty -g)
+ stty -echo
+fi
+cat
diff --git a/bin/rndi.awk b/bin/rndi.awk
index 7d9c640b..44989d11 100644
--- a/bin/rndi.awk
+++ b/bin/rndi.awk
@@ -30,9 +30,6 @@ BEGIN {
# Print a random integer bounded by the first and second arguments
print int(lower + rand() * (upper - lower + 1))
-
- # Bail before processing any lines
- exit
}
# Bailout function
diff --git a/bin/sls.sh b/bin/sls.sh
index 55c1dfc7..9741144a 100644
--- a/bin/sls.sh
+++ b/bin/sls.sh
@@ -3,7 +3,8 @@
# If we weren't given a file explicitly, we'll try to read both /etc/ssh_config
# and ~/.ssh_config in that order if they exist
if [ "$#" -eq 0 ] ; then
- for cfg in /etc/ssh_config "$HOME"/.ssh/config ; do
+ for cfg in /etc/ssh_config.d/*.conf /etc/ssh_config \
+ "$HOME"/.ssh/config.d/*.conf "$HOME"/.ssh/config ; do
[ -e "$cfg" ] || continue
set -- "$@" "$cfg"
done
diff --git a/bin/slsf.awk b/bin/slsf.awk
index 3d5c190f..75efe7a4 100644
--- a/bin/slsf.awk
+++ b/bin/slsf.awk
@@ -1,9 +1,28 @@
-# Print the first non-glob "Host" name from each line of ssh_config(5) files
+# Print all the hosts from ssh_config(1) files
# Manage the processing flag (starts set in each file)
-FNR == 1 || /### sls/ { sls = 1 }
+BEGIN { sls = 1 }
+FNR == 1 { sls = 1 }
+/### sls/ { sls = 1 }
/### nosls/ { sls = 0 }
-# If processing flag set, directive is "Host", and hostname has no wildcards,
-# then print it
-sls && $1 == "Host" && $2 !~ /\*/ { print $2 }
+# Skip if we're ignoring hosts
+!sls { next }
+# Skip if this isn't a host line
+$1 != "Host" { next }
+
+# Add all the patterns after the keyword that don't have wildcards
+{
+ for (i = 2; i <= NF; i++) {
+ if ($i !~ /[?*]/) {
+ hosts[$i]++
+ }
+ }
+}
+
+# Print the complete list of hosts, sorted
+END {
+ for (host in hosts) {
+ print host | "sort"
+ }
+}
diff --git a/bin/td.sh b/bin/td.sh
index a5a4ab30..6dfbebc0 100644
--- a/bin/td.sh
+++ b/bin/td.sh
@@ -1,7 +1,7 @@
# Manage to-do files with just $EDITOR and git(1)
# Specify the path and file
-dir=${TODO_DIR:-"$HOME"/Todo}
+dir=${TODO_DIR:-"$HOME"/todo}
# If the directory doesn't exist, create it
[ -d "$dir" ] || mkdir -p -- "$dir" || exit
diff --git a/bin/tm.sh b/bin/tm.sh
index d5422869..6bdce20b 100644
--- a/bin/tm.sh
+++ b/bin/tm.sh
@@ -1,5 +1,10 @@
# Attach to existing tmux session rather than create a new one if possible
+# Source config if it exists (just the session name, really)
+if [ -e "${XDG_CONFIG_HOME:-"$HOME"/.config}"/tm/config ] ; then
+ . "${XDG_CONFIG_HOME:-"$HOME"/.config}"/tm/config || exit
+fi
+
# If given any arguments, just use them as they are
if [ "$#" -gt 0 ] ; then
:
@@ -10,8 +15,8 @@ elif tmux has-session 2>/dev/null ; then
# Create a new session with an appropriate name
else
- set -- new-session -s "${TMUX_SESSION:-default}"
+ set -- new-session -s "${default_session_name:-default}"
fi
# Execute with concluded arguments
-tmux "$@"
+exec tmux "$@"
diff --git a/bin/urlmt.sh b/bin/urlmt.sh
index cd71b0fd..69bef5f7 100644
--- a/bin/urlmt.sh
+++ b/bin/urlmt.sh
@@ -1,8 +1,10 @@
# Get the MIME type for a given URL
-urlh "$1" Content-Type |
-
-# Use last line only, remove any charset suffix
-sed '
-$!d
-s/;.*//
-'
+self=urlmt
+if [ "$#" -ne 1 ] || [ -z "$1" ] ; then
+ printf >&2 '%s: Need a single URL\n' \
+ "$self"
+ exit 2
+fi
+url=$1
+curl --head --output /dev/null --write-out '%{content_type}\n' "$url" |
+ awk -F\; '{print $1}'
diff --git a/bin/uts.awk b/bin/uts.awk
index 3aaec2ab..a7b3ef5d 100644
--- a/bin/uts.awk
+++ b/bin/uts.awk
@@ -2,5 +2,4 @@
BEGIN {
srand()
print srand()
- exit
}
diff --git a/bin/xgo.sh b/bin/xgo.sh
index 6d6586ef..c59409a5 100644
--- a/bin/xgo.sh
+++ b/bin/xgo.sh
@@ -39,7 +39,7 @@ for url do (
# mpv(1)
(*[/.]youtube.com/watch*[?\&]t=) ;;
(*[/.]youtube.com/watch*)
- exec mpv -- "$url"
+ exec mpv --force-window --no-terminal -- "$url"
;;
esac
@@ -59,14 +59,15 @@ for url do (
)
;;
- # Open audio and video in mpv(1); force a window even for audio so I
- # can control it
+ # Open audio and video in mpv(1)
(audio/*|video/*)
- exec mpv --force-window -- "$url"
+ exec mpv --force-window --no-terminal -- "$url"
;;
- # If the MIME type is an image that is not a GIF, load it in feh(1)
- (image/gif) ;;
+ # Open GIFs with a looping mpv(1), and all other images with feh(1)
+ (image/gif)
+ exec mpv --force-window --loop=inf --no-terminal -- "$url"
+ ;;
(image/*)
exec curl -- "$url" | feh -
;;
@@ -74,7 +75,7 @@ for url do (
# Open plain text in a terminal view(1)
(text/plain)
# shellcheck disable=SC2016
- exec urxvt -e sh -c 'curl -- "$1" | view -' _ "$url"
+ exec x-terminal-emulator -e sh -c 'curl -- "$1" | view -' _ "$url"
;;
# Otherwise, just pass it to br(1df)
diff --git a/bin/xsnap.sh b/bin/xsnap.sh
new file mode 100644
index 00000000..7a9d0c38
--- /dev/null
+++ b/bin/xsnap.sh
@@ -0,0 +1,24 @@
+# Wrapper for scrot(1) for use in recording screenshots
+date=$(date +%Y/%m/%d) || exit
+dir=${XDG_DATA_HOME:-"$HOME"/.local/share}/scrot/screenshots/$date
+mkdir -p -- "$dir" || exit
+cd -- "$dir" || exit
+for ent in * ; do
+ [ -e "$ent" ] || continue
+ case $ent in
+ *.png) ;;
+ *) continue ;;
+ esac
+ basename=${ent%.png}
+ case $basename in
+ *[!0-9]*) continue ;;
+ esac
+ last=$basename
+done
+number=$(printf '%s' "$last" | sed 's/^0*//') # Avoid octal
+id=$((number + 1))
+name=$(printf '%05d' "$id").png
+path=$dir/$name
+scrot --file="$path" --overwrite "$@" || exit
+xclip -selection clipboard -target image/png "$path" || exit
+notify-send "Saved: $date/$name"