From 09366721b4a5405ccd24e21c9f0c4edd25d51196 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 10 Nov 2018 14:41:38 -0500 Subject: various script cleanups --- bin/cryptdir | 27 ++++++++++-------- bin/fm22avi | 7 ++++- bin/git/git-file-size | 2 ++ bin/history-stats | 51 ++++++++++++++++++++++++++++++++++ bin/history_stats | 51 ---------------------------------- bin/hostcert | 9 ++++-- bin/hush/kill-focused | 49 +++++++++++++++++++++++++++++++++ bin/hush/kill_focused | 49 --------------------------------- bin/hush/numkeys | 2 ++ bin/hush/setup-inputs | 4 ++- bin/hush/svdn | 8 ++++-- bin/hush/svget | 4 ++- bin/hush/svkill | 4 ++- bin/hush/svlog | 4 ++- bin/hush/svnuke | 4 ++- bin/hush/svre | 4 ++- bin/hush/svst | 4 ++- bin/hush/svstop | 4 ++- bin/hush/svup | 4 ++- bin/hush/update-mail | 8 ++++-- bin/hush/volume | 4 ++- bin/hush/webcam | 3 ++ bin/mem-usage | 5 ++++ bin/mem_usage | 3 -- bin/p | 76 --------------------------------------------------- bin/pdfcat | 8 ++++-- bin/pick-music | 6 ++++ bin/pick_music | 6 ---- bin/pt | 6 ++-- bin/rand-music | 13 +++++++++ bin/rand_line | 7 ----- bin/rand_music | 13 --------- bin/ringtone | 21 ++++++++------ bin/setfont | 4 ++- bin/show-colors | 29 ++++++++++++++++++++ bin/show_colors | 26 ------------------ bin/sum | 8 ++++-- bin/t | 6 ++-- bin/tozt/learn_spam | 18 ++++++------ bin/vimmanpager | 3 ++ xbindkeysrc | 4 +-- 41 files changed, 277 insertions(+), 291 deletions(-) create mode 100755 bin/history-stats delete mode 100755 bin/history_stats create mode 100755 bin/hush/kill-focused delete mode 100755 bin/hush/kill_focused create mode 100755 bin/mem-usage delete mode 100755 bin/mem_usage delete mode 100755 bin/p create mode 100755 bin/pick-music delete mode 100755 bin/pick_music create mode 100755 bin/rand-music delete mode 100755 bin/rand_line delete mode 100755 bin/rand_music create mode 100755 bin/show-colors delete mode 100755 bin/show_colors diff --git a/bin/cryptdir b/bin/cryptdir index 4434e6e..3fb858f 100755 --- a/bin/cryptdir +++ b/bin/cryptdir @@ -1,13 +1,15 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail -if [[ -e /dev/mapper/cryptdir ]]; then +if [ -e /dev/mapper/cryptdir ]; then echo "only one instance can run at a time" 1>&2 exit 1 fi sudo -v || exit 1 -if [[ -z $1 ]]; then +if [ -z "${1:-}" ]; then size='16M' else size=$1 @@ -18,20 +20,21 @@ cryptdir=$(mktemp -d) pass=$(dd if=/dev/urandom bs=1 count=80 | base64) cleanup () { + set +e cd - sudo umount $cryptdir + sudo umount "$cryptdir" sudo cryptsetup close cryptdir - rm -f $cryptfile - rmdir $cryptdir + rm -f "$cryptfile" + rmdir "$cryptdir" } trap cleanup EXIT -dd if=/dev/urandom of=$cryptfile bs=$size count=1 -echo $pass | sudo cryptsetup luksFormat $cryptfile - -echo $pass | sudo cryptsetup open $cryptfile cryptdir --key-file - +dd if=/dev/urandom of="$cryptfile" bs="$size" count=1 +echo "$pass" | sudo cryptsetup luksFormat "$cryptfile" - +echo "$pass" | sudo cryptsetup open "$cryptfile" cryptdir --key-file - sudo mkfs.ext2 /dev/mapper/cryptdir -sudo mount /dev/mapper/cryptdir $cryptdir -sudo chown $USER $cryptdir -cd $cryptdir +sudo mount /dev/mapper/cryptdir "$cryptdir" +sudo chown "$USER" "$cryptdir" +cd "$cryptdir" $SHELL diff --git a/bin/fm22avi b/bin/fm22avi index 5d11d58..eebfb4f 100755 --- a/bin/fm22avi +++ b/bin/fm22avi @@ -1,3 +1,8 @@ #!/bin/bash +set -eu +set -o pipefail -fceux --playmov $1.fm2 --sound 1 --soundq 1 --soundrate 48000 --nospritelim 1 --pal 0 --xscale 1 --yscale 1 --opengl 0 --special 0 $2 --videolog "mencoder - -o $1.avi -ovc x264 -x264encopts qp=0 -oac mp3lame -lameopts mode=3:preset=128 -noskip -nocache -mc 0 -aspect 4/3 NESVSETTINGS" +movie="$1" +rom="$2" + +fceux --playmov "$movie" --sound 1 --soundq 1 --soundrate 48000 --nospritelim 1 --pal 0 --xscale 1 --yscale 1 --opengl 0 --special 0 "$rom" --videolog "mencoder - -o ${movie/.fm2/.avi} -ovc x264 -x264encopts qp=0 -oac mp3lame -lameopts mode=3:preset=128 -noskip -nocache -mc 0 -aspect 4/3 NESVSETTINGS" diff --git a/bin/git/git-file-size b/bin/git/git-file-size index 2a90373..0e7d00d 100755 --- a/bin/git/git-file-size +++ b/bin/git/git-file-size @@ -1,3 +1,5 @@ #!/bin/sh +set -eu +set -o pipefail git ls-files -z | xargs -0 du -b | sum diff --git a/bin/history-stats b/bin/history-stats new file mode 100755 index 0000000..b289f97 --- /dev/null +++ b/bin/history-stats @@ -0,0 +1,51 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Getopt::Long; +use Path::Class; + +my $history_file = $ENV{SHELL} =~ m{/zsh} ? '.zsh_history' : '.bash_history'; + +my $fh = dir($ENV{HOME})->file($history_file)->openr; +my $n = 10; +my $subcommand; +GetOptions( + 'n=i' => \$n, + 'subcommand=s' => \$subcommand, +); + +my %cmds; +my %sudo_cmds; + +while (<$fh>) { + chomp; + + # strip zsh history timestamps + s/^[^;]*;// if /^:/; + + s/^\s*(.*?)\s*$/$1/; + my @words = split /\s+/; + next unless @words; + shift @words while @words && $words[0] =~ /^[A-Z][A-Z0-9_]*=/; + next unless @words; + my $sudo; + if ($words[0] eq 'sudo') { + $sudo = 1; + shift @words; + } + if ($subcommand) { + next unless $words[0] eq $subcommand; + shift @words; + shift @words while @words && $words[0] =~ /^-/; + } + $cmds{($words[0] || '')}++; + $sudo_cmds{$words[0]}++ if $sudo; +} + +for my $cmd (sort { $cmds{$b} <=> $cmds{$a} } keys %cmds) { + printf '%5d %s', $cmds{$cmd}, $subcommand ? "$subcommand $cmd" : $cmd; + printf ' (%d under sudo)', $sudo_cmds{$cmd} if $sudo_cmds{$cmd}; + print "\n"; + last unless --$n; +} diff --git a/bin/history_stats b/bin/history_stats deleted file mode 100755 index b289f97..0000000 --- a/bin/history_stats +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use Getopt::Long; -use Path::Class; - -my $history_file = $ENV{SHELL} =~ m{/zsh} ? '.zsh_history' : '.bash_history'; - -my $fh = dir($ENV{HOME})->file($history_file)->openr; -my $n = 10; -my $subcommand; -GetOptions( - 'n=i' => \$n, - 'subcommand=s' => \$subcommand, -); - -my %cmds; -my %sudo_cmds; - -while (<$fh>) { - chomp; - - # strip zsh history timestamps - s/^[^;]*;// if /^:/; - - s/^\s*(.*?)\s*$/$1/; - my @words = split /\s+/; - next unless @words; - shift @words while @words && $words[0] =~ /^[A-Z][A-Z0-9_]*=/; - next unless @words; - my $sudo; - if ($words[0] eq 'sudo') { - $sudo = 1; - shift @words; - } - if ($subcommand) { - next unless $words[0] eq $subcommand; - shift @words; - shift @words while @words && $words[0] =~ /^-/; - } - $cmds{($words[0] || '')}++; - $sudo_cmds{$words[0]}++ if $sudo; -} - -for my $cmd (sort { $cmds{$b} <=> $cmds{$a} } keys %cmds) { - printf '%5d %s', $cmds{$cmd}, $subcommand ? "$subcommand $cmd" : $cmd; - printf ' (%d under sudo)', $sudo_cmds{$cmd} if $sudo_cmds{$cmd}; - print "\n"; - last unless --$n; -} diff --git a/bin/hostcert b/bin/hostcert index 561244c..545167a 100755 --- a/bin/hostcert +++ b/bin/hostcert @@ -1,3 +1,8 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail -openssl s_client -connect "$1" < /dev/null 2>/dev/null | perl -nle 'print if /BEGIN CERTIFICATE/../END CERTIFICATE/' | openssl x509 -text | perl -nle 'print unless /BEGIN CERTIFICATE/../END CERTIFICATE/' +host="$1" +port="${2:-443}" + +openssl s_client -connect "$host:$port" < /dev/null 2>/dev/null | perl -nle 'print if /BEGIN CERTIFICATE/../END CERTIFICATE/' | openssl x509 -text | perl -nle 'print unless /BEGIN CERTIFICATE/../END CERTIFICATE/' diff --git a/bin/hush/kill-focused b/bin/hush/kill-focused new file mode 100755 index 0000000..37271ac --- /dev/null +++ b/bin/hush/kill-focused @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.014; + +use JSON::PP; + +my ($sig) = @ARGV; +my $pid = get_pid(); +my $pgrp = get_pgrp($pid); +kill $sig, -$pgrp; + +sub get_pid { + my $window_id = get_window_id(); + die "couldn't find window" unless defined $window_id; + my $prop = `xprop -id $window_id _NET_WM_PID`; + die "couldn't get pid from focused window" + if $prop =~ /not found/; + chomp($prop); + $prop =~ s/^_NET_WM_PID\(CARDINAL\) = //; + return $prop; +} + +sub get_pgrp { + my ($pid) = @_; + open my $stat_fh, '<', "/proc/$pid/stat" + or die "couldn't open /proc/$pid/stat"; + my $stat = do { local $/; <$stat_fh> }; + my @f = ($stat =~ /\([^)]*\)|[^ ]+/g); + return $f[4]; +} + +sub get_window_id { + return find(decode_json(`i3-msg -t get_tree`))->{window}; +} + +sub find { + my ($t) = @_; + if ($t->{focused}) { + return $t; + } + + for my $subtree (@{ $t->{nodes} }, @{ $t->{floating_nodes} }) { + my $found = find($subtree); + return $found if $found; + } + + return; +} diff --git a/bin/hush/kill_focused b/bin/hush/kill_focused deleted file mode 100755 index 37271ac..0000000 --- a/bin/hush/kill_focused +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use 5.014; - -use JSON::PP; - -my ($sig) = @ARGV; -my $pid = get_pid(); -my $pgrp = get_pgrp($pid); -kill $sig, -$pgrp; - -sub get_pid { - my $window_id = get_window_id(); - die "couldn't find window" unless defined $window_id; - my $prop = `xprop -id $window_id _NET_WM_PID`; - die "couldn't get pid from focused window" - if $prop =~ /not found/; - chomp($prop); - $prop =~ s/^_NET_WM_PID\(CARDINAL\) = //; - return $prop; -} - -sub get_pgrp { - my ($pid) = @_; - open my $stat_fh, '<', "/proc/$pid/stat" - or die "couldn't open /proc/$pid/stat"; - my $stat = do { local $/; <$stat_fh> }; - my @f = ($stat =~ /\([^)]*\)|[^ ]+/g); - return $f[4]; -} - -sub get_window_id { - return find(decode_json(`i3-msg -t get_tree`))->{window}; -} - -sub find { - my ($t) = @_; - if ($t->{focused}) { - return $t; - } - - for my $subtree (@{ $t->{nodes} }, @{ $t->{floating_nodes} }) { - my $found = find($subtree); - return $found if $found; - } - - return; -} diff --git a/bin/hush/numkeys b/bin/hush/numkeys index ab9dc14..9d037f5 100755 --- a/bin/hush/numkeys +++ b/bin/hush/numkeys @@ -1,4 +1,6 @@ #!/bin/sh +set -eu +set -o pipefail on() { xmodmap -e 'keycode 10 = exclam 1' diff --git a/bin/hush/setup-inputs b/bin/hush/setup-inputs index 6aaa19f..94e8e7f 100755 --- a/bin/hush/setup-inputs +++ b/bin/hush/setup-inputs @@ -1,9 +1,11 @@ #!/bin/sh +set -eu +set -o pipefail # key bindings setxkbmap -option ctrl:nocaps setxkbmap -option compose:caps -xmodmap $HOME/.Xmodmap +xmodmap "$HOME"/.Xmodmap "$(dirname "$0")"/numkeys on # trackpad settings diff --git a/bin/hush/svdn b/bin/hush/svdn index ce6f4c4..9e0fa0b 100755 --- a/bin/hush/svdn +++ b/bin/hush/svdn @@ -1,13 +1,15 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail svst "$1" && svstop "$1" svst "$1" && sleep 1 svst "$1" && svstop "$1" -for i in 1..5; do +for _ in $(seq 1 5); do svst "$1" && sleep 1 done svst "$1" && svstop "$1" -for i in 1..10; do +for _ in $(seq 1 10); do svst "$1" && sleep 1 done svst "$1" && svkill "$1" diff --git a/bin/hush/svget b/bin/hush/svget index 77c18f4..0eab9bf 100755 --- a/bin/hush/svget +++ b/bin/hush/svget @@ -1,3 +1,5 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail svstat "$HOME/.services/enabled/$1" diff --git a/bin/hush/svkill b/bin/hush/svkill index 060d2c7..a84e1a2 100755 --- a/bin/hush/svkill +++ b/bin/hush/svkill @@ -1,4 +1,6 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail svc -k "$HOME/.services/enabled/$1" svget "$1" diff --git a/bin/hush/svlog b/bin/hush/svlog index 436b25a..201ce9b 100755 --- a/bin/hush/svlog +++ b/bin/hush/svlog @@ -1,3 +1,5 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail tail -F "$HOME/.log/$1/current" | tai64nlocal diff --git a/bin/hush/svnuke b/bin/hush/svnuke index 6a383ce..309a1d5 100755 --- a/bin/hush/svnuke +++ b/bin/hush/svnuke @@ -1,4 +1,6 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail svdn "$1" svdn "$1/log" diff --git a/bin/hush/svre b/bin/hush/svre index e57576e..159b017 100755 --- a/bin/hush/svre +++ b/bin/hush/svre @@ -1,4 +1,6 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail svdn "$1" svup "$1" diff --git a/bin/hush/svst b/bin/hush/svst index 92d20c1..4d0c6ce 100755 --- a/bin/hush/svst +++ b/bin/hush/svst @@ -1,3 +1,5 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail svget "$1" | grep -q ": up (" diff --git a/bin/hush/svstop b/bin/hush/svstop index 36c0132..649ec26 100755 --- a/bin/hush/svstop +++ b/bin/hush/svstop @@ -1,4 +1,6 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail svc -d "$HOME/.services/enabled/$1" svget "$1" diff --git a/bin/hush/svup b/bin/hush/svup index c49a99e..3772fdb 100755 --- a/bin/hush/svup +++ b/bin/hush/svup @@ -1,4 +1,6 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail svc -u "$HOME/.services/enabled/$1" svget "$1" diff --git a/bin/hush/update-mail b/bin/hush/update-mail index b909d9f..8149a8d 100755 --- a/bin/hush/update-mail +++ b/bin/hush/update-mail @@ -1,9 +1,11 @@ #!/bin/sh +set -eu +set -o pipefail stat=$(svstat "$HOME/.services/enabled/offlineimap") -if echo $stat | grep -q "offlineimap: down"; then +if echo "$stat" | grep -q "offlineimap: down"; then echo "no offlineimap process running" >&2 exit 1 fi -pid=$(echo $stat | sed 's/.*offlineimap: up (pid \([[:digit:]]\+\)).*/\1/') -kill -USR1 $pid +pid=$(echo "$stat" | sed 's/.*offlineimap: up (pid \([[:digit:]]\+\)).*/\1/') +kill -USR1 "$pid" diff --git a/bin/hush/volume b/bin/hush/volume index e4c81fb..a0df2d3 100755 --- a/bin/hush/volume +++ b/bin/hush/volume @@ -1,4 +1,6 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail case $1 in up) diff --git a/bin/hush/webcam b/bin/hush/webcam index 48ee3f3..fdac5f8 100755 --- a/bin/hush/webcam +++ b/bin/hush/webcam @@ -1,2 +1,5 @@ #!/bin/sh +set -eu +set -o pipefail + mpv av://v4l2:/dev/video0 diff --git a/bin/mem-usage b/bin/mem-usage new file mode 100755 index 0000000..19e8c32 --- /dev/null +++ b/bin/mem-usage @@ -0,0 +1,5 @@ +#!/bin/sh +set -eu +set -o pipefail + +ps -eo rss,ucmd | sort -rn | head -n"${1:-20}" diff --git a/bin/mem_usage b/bin/mem_usage deleted file mode 100755 index 038009e..0000000 --- a/bin/mem_usage +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -ps -eo rss,ucmd | sort -rn | head -n$([ -z "$1" ] && echo 20 || echo $1) diff --git a/bin/p b/bin/p deleted file mode 100755 index a52ba1e..0000000 --- a/bin/p +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -_clean () { - git clean -dfx - ctags *.c *.h -} - -_configure () { - # XXX breaks when building Compress::Raw::Zlib, nobody else can reproduce? - # ./Configure -des -Dusedevel -DDEBUGGING -Dusethreads -Uversiononly -Accflags="-Wall -Wextra" -Doptimize="-g -O0 -ggdb3" - # can't do this with -Werror, not everything (external modules, say) is - # -Werror clean - # ./Configure -des -Dusedevel -Accflags="-Wall -Wextra" - ./Configure -des -Dusedevel -DDEBUGGING -} - -_make () { - if [[ ! -e Makefile ]]; then - _configure - fi - # -Werror at configure time seems to confuse Configure, so do it here - make -j9 OPTIMIZE="-g -Werror" -} - -_test () { - if [[ ! -e perl ]]; then - _make - fi - export TEST_JOBS=9 - if [ -n "$*" ]; then - make test_harness TEST_FILES="$*" - else - make test_harness - fi -} - -_test_porting () { - if [[ ! -e perl ]]; then - _make - fi - export TEST_JOBS=9 - if [ -n "$*" ]; then - make test_porting TEST_FILES="$*" - else - make test_porting - fi -} - -cmd=$1 -shift - -case $cmd in - cl|clean) - _clean $@ - ;; - c|conf|configure) - _configure $@ - ;; - m|make) - _make $@ - ;; - t|test) - _test $@ - ;; - tp|test_porting) - _test_porting $@ - ;; - a|all) - _clean - _test - ;; - *) - echo "Usage: p [args...]" 1>&2 - exit 1 - ;; -esac diff --git a/bin/pdfcat b/bin/pdfcat index 663f0af..ff4edaa 100755 --- a/bin/pdfcat +++ b/bin/pdfcat @@ -1,5 +1,7 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail -local out=$1 +out="$1" shift -gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$out $* +gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$out" "$@" diff --git a/bin/pick-music b/bin/pick-music new file mode 100755 index 0000000..8c406f7 --- /dev/null +++ b/bin/pick-music @@ -0,0 +1,6 @@ +#!/bin/sh +set -eu +set -o pipefail + +lastfm-query sync doyster +lastfm-query recommend "${1:-20}" diff --git a/bin/pick_music b/bin/pick_music deleted file mode 100755 index fe65dbc..0000000 --- a/bin/pick_music +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -eu -set -o pipefail - -lastfm-query sync doyster -lastfm-query recommend "${1:-20}" diff --git a/bin/pt b/bin/pt index a69df1b..c5ca9b9 100755 --- a/bin/pt +++ b/bin/pt @@ -1,6 +1,8 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail -if [[ -d blib ]]; then +if [ -d blib ]; then prove -Mlib::require::all=blib/lib,blib/arch -b "$@" t else prove -Mlib::require::all=lib -l "$@" t diff --git a/bin/rand-music b/bin/rand-music new file mode 100755 index 0000000..6e9bccc --- /dev/null +++ b/bin/rand-music @@ -0,0 +1,13 @@ +#!/bin/sh +set -eu +set -o pipefail + +if [ "${1:-}" = '--old' ]; then + extra_args="--exclude yearly --include all" + shift +else + extra_args= +fi + +lastfm-query sync doyster +lastfm-query recommend --random --album $extra_args "${1:-20}" diff --git a/bin/rand_line b/bin/rand_line deleted file mode 100755 index 7eba7ab..0000000 --- a/bin/rand_line +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/perl - -my $save = ''; -while (<>) { - $save = $_ if !int rand $.; -} -print $save; diff --git a/bin/rand_music b/bin/rand_music deleted file mode 100755 index ecf6666..0000000 --- a/bin/rand_music +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -eu -set -o pipefail - -if [[ "${1:-}" == '--old' ]]; then - extra_args="--exclude yearly --include all" - shift -else - extra_args= -fi - -lastfm-query sync doyster -lastfm-query recommend --random --album $extra_args "${1:-20}" diff --git a/bin/ringtone b/bin/ringtone index 5c8cfe1..19dddb6 100755 --- a/bin/ringtone +++ b/bin/ringtone @@ -1,4 +1,6 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail if [ $# -lt 3 ]; then echo "usage: ringtone " @@ -7,11 +9,12 @@ if [ $# -lt 3 ]; then exit 1 fi -mencoder -ovc frameno \ - -oac mp3lame \ - -lameopts cbr:br=64 \ - -of rawaudio \ - -o $2 \ - -audiofile $1 \ - -endpos 256kb \ - $3 +mencoder \ + -ovc frameno \ + -oac mp3lame \ + -lameopts cbr:br=64 \ + -of rawaudio \ + -o "$2" \ + -audiofile "$1" \ + -endpos 256kb \ + "$3" diff --git a/bin/setfont b/bin/setfont index 50b4b78..d3e9f2a 100755 --- a/bin/setfont +++ b/bin/setfont @@ -1,3 +1,5 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail printf '\e]710;%s\007\e]711;%s\007' "$1" "$1" diff --git a/bin/show-colors b/bin/show-colors new file mode 100755 index 0000000..be1a489 --- /dev/null +++ b/bin/show-colors @@ -0,0 +1,29 @@ +#!/bin/sh +set -eu +set -o pipefail + +############################################################ +# Nico Golde Homepage: http://www.ngolde.de +# Last change: Mon Feb 16 16:24:41 CET 2004 +############################################################ + +for attr in 0 1 2 3 4 5 6 7 ; do + echo "----------------------------------------------------------------" + printf 'ESC[%s;Foreground;Background - \n' $attr + for fore in 30 31 32 33 34 35 36 37; do + for back in 40 41 42 43 44 45 46 47; do + printf '\033[%s;%s;%sm %02s;%02s ' $attr $fore $back $fore $back + done + printf '\033[0m\n' + done + printf '\033[0m' +done + +printf '\n' +for color in $(seq 0 255); do + printf '\033[%s;%s;%sm \033[m' 48 5 "$color" + if [ "$color" -eq 15 ] || [ "$(echo "scale = 0; ($color - 15) % 36" | bc)" -eq 0 ]; then + printf '\n' + fi +done +printf '\033[0m\n' diff --git a/bin/show_colors b/bin/show_colors deleted file mode 100755 index 35c5374..0000000 --- a/bin/show_colors +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -############################################################ -# Nico Golde Homepage: http://www.ngolde.de -# Last change: Mon Feb 16 16:24:41 CET 2004 -############################################################ - -for attr in 0 1 2 3 4 5 6 7 ; do - echo "----------------------------------------------------------------" - printf "ESC[%s;Foreground;Background - \n" $attr - for fore in 30 31 32 33 34 35 36 37; do - for back in 40 41 42 43 44 45 46 47; do - printf '\033[%s;%s;%sm %02s;%02s ' $attr $fore $back $fore $back - done - printf '\033[0m\n' - done - printf '\033[0m' -done - -printf '\n' -for color in $(seq 0 255); do - printf '\033[%s;%s;%sm \033[m' 48 5 $color - if [[ $color -eq 15 || $(echo "scale = 0; ($color - 15) % 36" | bc) -eq 0 ]]; then - printf '\n' - fi -done -printf '\033[0m\n' diff --git a/bin/sum b/bin/sum index df7cd81..cf21bfd 100755 --- a/bin/sum +++ b/bin/sum @@ -1,4 +1,8 @@ #!/usr/bin/env perl -use 5.010; +use strict; +use warnings; +use 5.014; + use List::Util 'sum'; -say sum map { s/^((?:\d|[-+\.])+).*/$1/; $_ } <>; + +say sum map { s/^([-+\.\d]+).*/$1/r } <>; diff --git a/bin/t b/bin/t index beffa0e..b6c065a 100755 --- a/bin/t +++ b/bin/t @@ -1,6 +1,8 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail -if [[ -d blib ]]; then +if [ -d blib ]; then perl -Mblib "$@" else perl -Ilib "$@" diff --git a/bin/tozt/learn_spam b/bin/tozt/learn_spam index ab5603a..128ca9a 100755 --- a/bin/tozt/learn_spam +++ b/bin/tozt/learn_spam @@ -1,10 +1,12 @@ -#!/bin/bash +#!/bin/sh +set -eu +set -o pipefail MAILDIR=~/Maildir OPTS="--no-sync" SALEARN=/usr/bin/vendor_perl/sa-learn -if [[ "$1" == "-q" ]]; then +if [ "$1" = "-q" ]; then OPTS="$OPTS" OUTFILE="/dev/null" else @@ -12,25 +14,25 @@ else OUTFILE="/dev/stdout" fi -if [[ ! "$1" == "-q" ]]; then +if [ ! "$1" = "-q" ]; then echo "$(date): Learning ham..." fi nice find $MAILDIR -type f | \ perl -nl0e'chomp; ($ts) = /(\d{10})/; $now = time; print if m{/(new|cur)/} && !m{/(\.old|\.spam)/} && $ts > $now - 60*60*24*30' | \ - xargs -n1000 -0 $SALEARN $OPTS --ham > $OUTFILE + xargs -n1000 -0 $SALEARN "$OPTS" --ham > $OUTFILE -if [[ ! "$1" == "-q" ]]; then +if [ ! "$1" = "-q" ]; then echo "$(date): Learning spam..." fi nice find $MAILDIR -type f | \ perl -nl0e'chomp; ($ts) = /(\d{10})/; $now = time; print if m{/(new|cur)/} && m{/\.spam/} && $ts > $now - 60*60*24*30' | \ - xargs -n1000 -0 $SALEARN $OPTS --spam > $OUTFILE + xargs -n1000 -0 $SALEARN "$OPTS" --spam > $OUTFILE -if [[ ! "$1" == "-q" ]]; then +if [ ! "$1" = "-q" ]; then echo "$(date): Syncing..." fi nice $SALEARN --sync > $OUTFILE -if [[ ! "$1" == "-q" ]]; then +if [ ! "$1" = "-q" ]; then echo "$(date): Done!" fi diff --git a/bin/vimmanpager b/bin/vimmanpager index 9df7f94..d33e4f9 100755 --- a/bin/vimmanpager +++ b/bin/vimmanpager @@ -1,4 +1,7 @@ #!/bin/sh +set -eu +set -o pipefail + sed -e 's/\x1B\[[[:digit:]]\+m//g' | col -b | \ vim \ -c 'let no_plugin_maps = 1' \ diff --git a/xbindkeysrc b/xbindkeysrc index a42e5c0..c47bdeb 100644 --- a/xbindkeysrc +++ b/xbindkeysrc @@ -52,10 +52,10 @@ "xset dpms force off" XF86Search -"kill_focused STOP" +"kill-focused STOP" XF86LaunchA -"kill_focused CONT" +"kill-focused CONT" XF86Explorer "xclip -selection CLIPBOARD -o | xargs -0 -n1 xdotool type --clearmodifiers --delay 0" -- cgit v1.2.3-54-g00ecf