diff options
author | Andrew Cady <d@jerkface.net> | 2024-01-19 12:01:49 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2024-01-19 12:01:49 -0500 |
commit | a74be3f9e73d9dd10eee890e673d00bfb44e5cfb (patch) | |
tree | d6ac57f28cdd7bf0283234e4730275c0b6afb565 /dot/local | |
parent | 66a483f0101ec54bd8db0f7d20ed83fe2f615cf4 (diff) | |
parent | f58705ed7c600a1d394c6949bb7e21cfd29e6260 (diff) |
Diffstat (limited to 'dot/local')
-rwxr-xr-x | dot/local/bin/latest | 36 | ||||
-rwxr-xr-x | dot/local/bin/lpdf | 44 | ||||
-rw-r--r-- | dot/local/bin/scan | 19 | ||||
-rwxr-xr-x | dot/local/bin/ssh-shellwrap | 19 |
4 files changed, 102 insertions, 16 deletions
diff --git a/dot/local/bin/latest b/dot/local/bin/latest index ef95cfe..12a0a9f 100755 --- a/dot/local/bin/latest +++ b/dot/local/bin/latest | |||
@@ -3,23 +3,45 @@ usage() | |||
3 | { | 3 | { |
4 | cat <<EOF | 4 | cat <<EOF |
5 | Usage: $0 [directory] [...] | 5 | Usage: $0 [directory] [...] |
6 | Usage: $0 --help | ||
6 | 7 | ||
7 | Print the filename of the newest file. | 8 | Searches the current directory if none is specified. |
9 | |||
10 | Print one filename: the single newest ordinary file from all (not each) | ||
11 | of the specified directories. | ||
12 | |||
13 | If there are no ordinary files, there is no output. | ||
14 | |||
15 | Symbolic links are not listed. | ||
8 | 16 | ||
9 | Searches the directories specified on the command line, | ||
10 | or else the current directory if none specified. | ||
11 | EOF | 17 | EOF |
12 | } | 18 | } |
13 | 19 | ||
14 | case $# in | 20 | case $# in |
15 | 0) set -- . ;; | 21 | 0) set -- . ;; |
16 | 1) if [ "$1" = --usage ]; then usage; exit 0; fi ;; | 22 | 1) if [ "$1" = --usage ] |
23 | then | ||
24 | usage | ||
25 | exit 0 | ||
26 | fi | ||
27 | ;; | ||
17 | esac | 28 | esac |
18 | 29 | ||
19 | extract() | 30 | drop_first_word() |
31 | { | ||
32 | sed -ne 's/^[^ ]* //p' | ||
33 | } | ||
34 | |||
35 | extract_newest() | ||
36 | { | ||
37 | sort -z -n -k1,1 -r | head -z -n 1 | xargs -r -0 printf '%s\n' | ||
38 | } | ||
39 | |||
40 | find_simple_files() | ||
20 | { | 41 | { |
21 | sort -z -n -k1,1 -r | head -z -n 1 | xargs -0 printf '%s\n' | perl -pe 's/.*? //' | 42 | pattern="%C@ %h/%f\0" |
43 | find "$@" -maxdepth 1 -name '.*' -o \( -type f -printf "$pattern" \) | ||
22 | } | 44 | } |
23 | 45 | ||
24 | find "$@" -maxdepth 1 -name '.*' -o \( -type f -printf "%C@ %h/%f\0" \) | extract | 46 | find_simple_files "$@" | extract_newest | drop_first_word |
25 | 47 | ||
diff --git a/dot/local/bin/lpdf b/dot/local/bin/lpdf new file mode 100755 index 0000000..41f52c4 --- /dev/null +++ b/dot/local/bin/lpdf | |||
@@ -0,0 +1,44 @@ | |||
1 | #!/bin/bash | ||
2 | # lpdf -- print with lp to a PDF file; output the filename to stdout | ||
3 | |||
4 | move_pdf() | ||
5 | { | ||
6 | local o f="$1" | ||
7 | o=$f | ||
8 | o=${o##*/} | ||
9 | o=${o%%__*} | ||
10 | o=${o%.txt}.pdf | ||
11 | mv -i -T -- "$f" "$o" | ||
12 | } | ||
13 | |||
14 | run_lp() | ||
15 | { | ||
16 | set -x | ||
17 | lp "$@" -d PDF | ||
18 | } | ||
19 | |||
20 | extract_lp_pdf_filename() | ||
21 | { | ||
22 | read _ _ _ pdf _ | ||
23 | case "$pdf" in | ||
24 | PDF-*) glob=$(printf "~/PDF/*-job_%s.pdf\n" "${pdf#PDF-}") ;; | ||
25 | *) exit 1 ;; | ||
26 | esac | ||
27 | |||
28 | sleep=1 | ||
29 | while true | ||
30 | do | ||
31 | if f=$(shopt -s failglob; 2>/dev/null eval "echo $glob") | ||
32 | then | ||
33 | printf "%s\n" "$f" | ||
34 | break | ||
35 | else | ||
36 | sleep $sleep | ||
37 | sleep=$((sleep + 1)) | ||
38 | fi | ||
39 | done | ||
40 | } | ||
41 | |||
42 | set -e | ||
43 | read pdf < <(run_lp "$@" | extract_lp_pdf_filename) | ||
44 | move_pdf "$pdf" | ||
diff --git a/dot/local/bin/scan b/dot/local/bin/scan index 2ba071b..2a7ac71 100644 --- a/dot/local/bin/scan +++ b/dot/local/bin/scan | |||
@@ -1,16 +1,17 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | NOW=$( TZ=UTC date -Ins | tr T . | tr -d : | sed -E 's/(..),(...).*/\1.\2/' ) | 2 | NOW=$( TZ=UTC date -Ins | tr T . | tr -d : | sed -E 's/(..),(...).*/\1.\2/' ) |
3 | 3 | ||
4 | if [ $# = 0 ] | 4 | if [ "$ACTUAL_BATCH" -a $# = 0 ] |
5 | then | 5 | then |
6 | ACTUAL_BATCH= | 6 | FORMAT=scan_${NOW}_%.3d.png |
7 | fi | ||
8 | |||
9 | if $ACTUAL_BATCH | ||
10 | then | ||
11 | format=scan_${NOW}_%.3d.png | ||
12 | else | 7 | else |
13 | format=scan_${NOW}.png | 8 | FORMAT=scan_${NOW}.png |
14 | fi | 9 | fi |
15 | 10 | ||
16 | scanimage --progress --format=png --batch="$format" | 11 | RESOLUTION=600 |
12 | |||
13 | scanimage --progress \ | ||
14 | --mode=Color \ | ||
15 | --resolution="$RESOLUTION" \ | ||
16 | --format=png \ | ||
17 | --batch="$FORMAT" | ||
diff --git a/dot/local/bin/ssh-shellwrap b/dot/local/bin/ssh-shellwrap new file mode 100755 index 0000000..e0d537e --- /dev/null +++ b/dot/local/bin/ssh-shellwrap | |||
@@ -0,0 +1,19 @@ | |||
1 | #!/bin/bash | ||
2 | # ssh wrapper; requires "--" before host argument | ||
3 | options=() | ||
4 | while [ $# -gt 0 ] | ||
5 | do | ||
6 | case $1 in | ||
7 | -- ) break ;; | ||
8 | esac | ||
9 | options+=("$1") | ||
10 | shift | ||
11 | done | ||
12 | set -e | ||
13 | [ "$1" = '--' ] | ||
14 | shift | ||
15 | [ $# -gt 0 ] | ||
16 | host=$1 | ||
17 | shift | ||
18 | ssh "${options[@]}" -- "$host" ${*@Q} | ||
19 | |||