diff options
Diffstat (limited to 'bin')
-rw-r--r-- | bin/clog.sh | 3 | ||||
-rw-r--r-- | bin/dmp.sh | 31 | ||||
-rw-r--r-- | bin/gscr.sh | 9 | ||||
-rw-r--r-- | bin/han.bash | 23 | ||||
-rw-r--r-- | bin/mked.sh | 1 | ||||
-rw-r--r-- | bin/mktd.sh | 2 | ||||
-rw-r--r-- | bin/mkvi.sh | 1 | ||||
-rw-r--r--[-rwxr-xr-x] | bin/msc.sh | 0 | ||||
-rw-r--r-- | bin/osc.sh | 2 | ||||
-rwxr-xr-x | bin/plmu | 28 | ||||
-rw-r--r-- | bin/qat.sh | 1 | ||||
-rw-r--r-- | bin/rndi.awk | 3 | ||||
-rw-r--r-- | bin/sls.sh | 3 | ||||
-rw-r--r-- | bin/slsf.awk | 29 | ||||
-rw-r--r-- | bin/td.sh | 2 | ||||
-rw-r--r-- | bin/tm.sh | 9 | ||||
-rw-r--r-- | bin/uts.awk | 1 | ||||
-rw-r--r-- | bin/xgo.sh | 15 | ||||
-rw-r--r-- | bin/xsnap.sh | 24 |
19 files changed, 80 insertions, 107 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 index 051f104a..051f104a 100755..100644 --- a/bin/msc.sh +++ b/bin/msc.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/plmu b/bin/plmu deleted file mode 100755 index bac2e434..00000000 --- a/bin/plmu +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -# 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 @@ -1,4 +1,3 @@ -#!/bin/sh restore() { if [ -n "$stty" ] ; then stty "$stty" 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 @@ -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" + } +} @@ -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 @@ -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/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 } @@ -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" |