From 03d827e2fbc409ef97829f25b8eeca5204f81a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 12 Jul 2021 13:24:49 +0200 Subject: Re-organize files --- Makefile | 13 +++-- P | 5 -- README | 20 +++++--- ce | 28 ----------- child | 27 ----------- colortest | 15 ------ cpy | 3 -- cpy.1 | 48 ------------------ cuthere | 2 - doc/cpy.1 | 48 ++++++++++++++++++ doc/ep.1 | 33 +++++++++++++ doc/f.1 | 27 +++++++++++ doc/mkmv.1 | 35 ++++++++++++++ doc/ord.1 | 51 ++++++++++++++++++++ doc/pst.1 | 1 + ep | 9 ---- ep.1 | 33 ------------- etc/P | 5 ++ etc/ce | 28 +++++++++++ etc/child | 27 +++++++++++ etc/colortest | 15 ++++++ etc/cpy | 3 ++ etc/cuthere | 2 + etc/ep | 9 ++++ etc/f | 10 ++++ etc/flip | 3 ++ etc/g | 30 ++++++++++++ etc/gspell | 18 +++++++ etc/imgur | 123 +++++++++++++++++++++++++++++++++++++++++++++++ etc/inc | 3 ++ etc/isort | 21 ++++++++ etc/lorem | 5 ++ etc/mkmv | 23 +++++++++ etc/ord | 56 +++++++++++++++++++++ etc/p | 7 +++ etc/pst | 17 +++++++ etc/re! | 48 ++++++++++++++++++ etc/wpdf | 76 +++++++++++++++++++++++++++++ etc/xtopen | 41 ++++++++++++++++ f | 10 ---- f.1 | 27 ----------- flip | 3 -- g | 30 ------------ git-bdiff | 51 -------------------- git-orig | 20 -------- git-s | 20 -------- git-st | 31 ------------ git/git-bdiff | 51 ++++++++++++++++++++ git/git-orig | 20 ++++++++ git/git-s | 20 ++++++++ git/git-st | 31 ++++++++++++ gspell | 18 ------- imgur | 123 ----------------------------------------------- inc | 3 -- isort | 21 -------- lorem | 5 -- mkmv | 23 --------- mkmv.1 | 35 -------------- ord | 56 --------------------- ord.1 | 51 -------------------- p | 7 --- pl | 8 --- pl/pl | 8 +++ pl/pla | 1 + pl/plf | 1 + pl/plh | 1 + pl/plm | 1 + pl/plq | 1 + pl/plv | 1 + pla | 1 - plf | 1 - plh | 1 - plm | 1 - plq | 1 - plv | 1 - pst | 17 ------- pst.1 | 1 - re! | 48 ------------------ with-git | 5 -- with-pager | 2 - with-shell | 3 -- with-shell-on-error | 2 - with/with-git | 5 ++ with/with-pager | 2 + with/with-shell | 3 ++ with/with-shell-on-error | 2 + wpdf | 76 ----------------------------- xtopen | 41 ---------------- 88 files changed, 933 insertions(+), 926 deletions(-) delete mode 100755 P delete mode 100755 ce delete mode 100755 child delete mode 100755 colortest delete mode 100755 cpy delete mode 100644 cpy.1 delete mode 100755 cuthere create mode 100644 doc/cpy.1 create mode 100644 doc/ep.1 create mode 100644 doc/f.1 create mode 100644 doc/mkmv.1 create mode 100644 doc/ord.1 create mode 120000 doc/pst.1 delete mode 100755 ep delete mode 100644 ep.1 create mode 100755 etc/P create mode 100755 etc/ce create mode 100755 etc/child create mode 100755 etc/colortest create mode 100755 etc/cpy create mode 100755 etc/cuthere create mode 100755 etc/ep create mode 100755 etc/f create mode 100755 etc/flip create mode 100755 etc/g create mode 100755 etc/gspell create mode 100644 etc/imgur create mode 100755 etc/inc create mode 100755 etc/isort create mode 100755 etc/lorem create mode 100755 etc/mkmv create mode 100755 etc/ord create mode 100755 etc/p create mode 100755 etc/pst create mode 100755 etc/re! create mode 100755 etc/wpdf create mode 100755 etc/xtopen delete mode 100755 f delete mode 100644 f.1 delete mode 100755 flip delete mode 100755 g delete mode 100755 git-bdiff delete mode 100755 git-orig delete mode 100755 git-s delete mode 100755 git-st create mode 100755 git/git-bdiff create mode 100755 git/git-orig create mode 100755 git/git-s create mode 100755 git/git-st delete mode 100755 gspell delete mode 100644 imgur delete mode 100755 inc delete mode 100755 isort delete mode 100755 lorem delete mode 100755 mkmv delete mode 100644 mkmv.1 delete mode 100755 ord delete mode 100644 ord.1 delete mode 100755 p delete mode 100755 pl create mode 100755 pl/pl create mode 120000 pl/pla create mode 120000 pl/plf create mode 120000 pl/plh create mode 120000 pl/plm create mode 120000 pl/plq create mode 120000 pl/plv delete mode 120000 pla delete mode 120000 plf delete mode 120000 plh delete mode 120000 plm delete mode 120000 plq delete mode 120000 plv delete mode 100755 pst delete mode 120000 pst.1 delete mode 100755 re! delete mode 100755 with-git delete mode 100755 with-pager delete mode 100755 with-shell delete mode 100755 with-shell-on-error create mode 100755 with/with-git create mode 100755 with/with-pager create mode 100755 with/with-shell create mode 100755 with/with-shell-on-error delete mode 100755 wpdf delete mode 100755 xtopen diff --git a/Makefile b/Makefile index 9b1b071..f8d23b4 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ -EXEC != find -H . -follow -type f -maxdepth 1 -perm -111 -IEXEC != echo " $(EXEC)" | sed -E 's, \./, /usr/local/bin/,g' +EXEC != find -H . -follow -type f -perm -111 ! -path '*/.git/*' +IEXEC != echo " $(EXEC)" | sed -E 's, \./([^ ]*/)?, /usr/local/bin/,g' install: - install -m 644 *.[1-9] /usr/local/man/man1 - install $(EXEC) /usr/local/bin - re! $(IEXEC) + @echo Installing man pages... + @install -m 644 doc/*.[1-9] /usr/local/man/man1 + @echo Installing executables... + @install $(EXEC) /usr/local/bin + @echo Rewriting shebangs... + @re! $(IEXEC) diff --git a/P b/P deleted file mode 100755 index 3c11b20..0000000 --- a/P +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -# P -- open file processed with p in PAGER - -"$PAGER" /var/tmp/pg diff --git a/README b/README index 47299fe..108287a 100644 --- a/README +++ b/README @@ -3,14 +3,18 @@ idiosyncratic extra UNIX tools. In my opinion, the most generally useful ones are - ce center text - ep edit pipe - g poor man's ack - inc increment numbers in lines - p/P maybe view output in pager +etc/ + ce center text + ep edit pipe + g poor man's ack + inc increment numbers in lines + p/P maybe view output in pager + +git/ + git-orig checkout original file For similar programs, see - dwim http://git.ankarstrom.se/dwim - repl http://git.ankarstrom.se/repl - vp http://git.ankarstrom.se/vp + dwim http://git.ankarstrom.se/dwim + repl http://git.ankarstrom.se/repl + vp http://git.ankarstrom.se/vp diff --git a/ce b/ce deleted file mode 100755 index c00d1bf..0000000 --- a/ce +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -# ce -- center text - -usage() { echo usage: $0 [cols] 1>&2; exit 1; } - -[ $# -gt 1 ] && usage - -if [ $# -eq 1 ]; then - cols=${1#-} - [ "$cols" -gt 0 ] || usage - shift -else - cols=`tput cols` - [ "$cols" -le 80 ] || cols=80 -fi - -while read line; do - line=${line## } - line=${line%% } - len=`echo "$line" | wc -c` - max=$(((cols - len) / 2)) - i=0 - while [ $((i++)) -lt $max ]; do - printf ' ' - done - echo "$line" -done diff --git a/child b/child deleted file mode 100755 index 32dab60..0000000 --- a/child +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# child -- print pid of youngest grandchild - -opt= -for x in "$@"; do - case "$x" in - -*) opt="$opt $x"; shift ;; - *) ;; - esac -done - -[ $# -ne 1 ] && { echo usage: $0 [-?] pid 1>&2; exit 1; } - -ps -do pid,etime,comm -k etime $opt | -pid=$1 perl -lane ' - if (/^ *$ENV{pid} / .. 1) { - next if /^ *$ENV{pid} /; - last if not /[|`-]/; - $t = 0; $i = 0; - $t += $_*(60**$i++) for reverse split /:/, $F[1]; - print "$t $_" if $t > 2; - } -' | -sort -n | -head -1 | -cut -d\ -f2 diff --git a/colortest b/colortest deleted file mode 100755 index 24aa95c..0000000 --- a/colortest +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -printf " " -for b in 0 1 2 3 4 5 6 7; do printf " 4${b}m "; done -echo -for f in "" 30 31 32 33 34 35 36 37; do - for s in "" "1;"; do - printf "%4sm" "${s}${f}" - printf " \033[%sm%s\033[0m" "$s$f" "gYw " - for b in 0 1 2 3 4 5 6 7; do - printf " \033[4%s;%sm%s\033[0m" "$b" "$s$f" " gYw " - done - echo - done -done diff --git a/cpy b/cpy deleted file mode 100755 index 827d21c..0000000 --- a/cpy +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -tee /tmp/cpy"$1" diff --git a/cpy.1 b/cpy.1 deleted file mode 100644 index 3b23b8b..0000000 --- a/cpy.1 +++ /dev/null @@ -1,48 +0,0 @@ -.Dd $Mdocdate$ -.Dt cpy 1 -.Os -. -.Sh NAME -.Nm cpy -.Nd copy text -. -.Sh SYNOPSIS -.Nm cpy -.Op Ar suffix -.Nm pst -.Op Fl d -.Op Ar suffix -. -.Sh DESCIPTION -.Pp -.Nm cpy -copies text on standard input to /tmp/cpy using -.Nm tee . -.Nm pst -writes the contents of /tmp/cpy on standard output. -If -.Fl d -is present, -.Nm pst -deletes /tmp/cpy after reading it. -.Pp -If -.Ar suffix -is present, -.Nm cpy -and -.Nm pst -append that suffix to the file name. -For example, setting -.Ar suffix -to -.Ql 1 -will copy to and paste from the file /tmp/cpy1. -. -.Sh AUTHORS -.Pp -.Nm cpy -and -.Nm pst -are written by John Ankarström -.Aq Mt john (at) ankarstrom.se . diff --git a/cuthere b/cuthere deleted file mode 100755 index 01c1606..0000000 --- a/cuthere +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -echo '--------------------8<------------------------------------' diff --git a/doc/cpy.1 b/doc/cpy.1 new file mode 100644 index 0000000..3b23b8b --- /dev/null +++ b/doc/cpy.1 @@ -0,0 +1,48 @@ +.Dd $Mdocdate$ +.Dt cpy 1 +.Os +. +.Sh NAME +.Nm cpy +.Nd copy text +. +.Sh SYNOPSIS +.Nm cpy +.Op Ar suffix +.Nm pst +.Op Fl d +.Op Ar suffix +. +.Sh DESCIPTION +.Pp +.Nm cpy +copies text on standard input to /tmp/cpy using +.Nm tee . +.Nm pst +writes the contents of /tmp/cpy on standard output. +If +.Fl d +is present, +.Nm pst +deletes /tmp/cpy after reading it. +.Pp +If +.Ar suffix +is present, +.Nm cpy +and +.Nm pst +append that suffix to the file name. +For example, setting +.Ar suffix +to +.Ql 1 +will copy to and paste from the file /tmp/cpy1. +. +.Sh AUTHORS +.Pp +.Nm cpy +and +.Nm pst +are written by John Ankarström +.Aq Mt john (at) ankarstrom.se . diff --git a/doc/ep.1 b/doc/ep.1 new file mode 100644 index 0000000..95e992d --- /dev/null +++ b/doc/ep.1 @@ -0,0 +1,33 @@ +.Dd $Mdocdate$ +.Dt ep 1 +.Os +. +.Sh NAME +.Nm ep +.Nd edit pipe +. +.Sh SYNOPSIS +.Nm +. +.Sh DESCIPTION +.Pp +.Nm +redirects standard input to a temporary file, +opens it in +.Ev EDITOR +(or +.Xr vi 1 , +if none is set) +and prints the contents of the (edited) file on standard output. +.Pp +.Nm +can be used as a versatile option selector. +The following sequence is a quick way to delete all lines but the current in +.Xr vi 1 : +.Dl :.w! +. +.Sh AUTHORS +.Pp +.Nm +is written by John Ankarström +.Aq Mt "john (at) ankarstrom.se" . diff --git a/doc/f.1 b/doc/f.1 new file mode 100644 index 0000000..104ebae --- /dev/null +++ b/doc/f.1 @@ -0,0 +1,27 @@ +.Dd $Mdocdate$ +.Dt f 1 +.Os +. +.Sh NAME +.Nm f +.Nd fmt but with new sentence on new line +. +.Sh SYNOPSIS +.Nm f +.Op Ar arg ... +. +.Sh DESCIPTION +.Pp +.Nm +runs +.Xr fmt 1 +with any given +.Ar arg +in a way such that each new sentence begins on a new line. +Sentence breaks are recognized if the period in the original text +is followed by two spaces or a newline. +.Sh AUTHORS +.Pp +.Nm +is written by John Ankarström +.Aq Mt john (at) ankarstrom.se . diff --git a/doc/mkmv.1 b/doc/mkmv.1 new file mode 100644 index 0000000..7087769 --- /dev/null +++ b/doc/mkmv.1 @@ -0,0 +1,35 @@ +.Dd $Mdocdate$ +.Dt mkmv 1 +.Os +. +.Sh NAME +.Nm mkmv +.Nd move files to new directory +. +.Sh SYNOPSIS +.Nm +.Fl t Ar target +.Ar file ... +. +.Sh DESCIPTION +.Pp +.Nm +moves the specified files into a new directory named +.Ar target . +It correctly handles the (not uncommon) case +where one of the moved files has the same name +as the target directory. + +Note that +.Nm +does not support the argument syntax of +.Xr mv 1 . +The explicit +.Fl t +flag is obligatory. +. +.Sh AUTHORS +.Pp +.Nm +is written by John Ankarström +.Aq Mt john (at) ankarstrom.se . diff --git a/doc/ord.1 b/doc/ord.1 new file mode 100644 index 0000000..9ab54a5 --- /dev/null +++ b/doc/ord.1 @@ -0,0 +1,51 @@ +.Dd $Mdocdate$ +.Dt ord 1 +.Os +. +.Sh NAME +.Nm ord +.Nd re-order files with numeric indices +. +.Sh SYNOPSIS +.Nm +.Op Fl n Ar "number width" +.Op Fl s Ar separator +.Ar file ... +. +.Sh DESCIPTION +.Pp +.Nm +is a convenient utility for re-ordering numerically indexed files, i.e. files with names beginning with +.Ql 01.\ , +.Ql 02.\ +and so forth. +Among other things, it is useful for managing disk-based playlists. + +Given any number of files as arguments, +.Nm +will open a temporary text file in your +.Ev EDITOR , +in which you can re-order the files by re-ordering lines. +Save the file and exit the text editor to change the names of the files to reflect the new order. + +The +.Fl n +and +.Fl s +control the format of the numeric indices expected and created by +.Nm . +Their respective default values are 2 and +.Ql .\ . + +Note that +.Fl n +and +.Fl s +cannot be used to change the format of existing numeric indices. +Such functionality is not provided by +.Nm . +.Sh AUTHORS +.Pp +.Nm +is written by John Ankarström +.Aq Mt john (at) ankarstrom.se . diff --git a/doc/pst.1 b/doc/pst.1 new file mode 120000 index 0000000..0ececb2 --- /dev/null +++ b/doc/pst.1 @@ -0,0 +1 @@ +cpy.1 \ No newline at end of file diff --git a/ep b/ep deleted file mode 100755 index 4be6317..0000000 --- a/ep +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -# ep -- edit pipe - -tmp=`mktemp /tmp/ep.XXXXXX` -cat > $tmp -${EDITOR:-vi} $tmp < /dev/tty > /dev/tty -cat $tmp -rm $tmp diff --git a/ep.1 b/ep.1 deleted file mode 100644 index 95e992d..0000000 --- a/ep.1 +++ /dev/null @@ -1,33 +0,0 @@ -.Dd $Mdocdate$ -.Dt ep 1 -.Os -. -.Sh NAME -.Nm ep -.Nd edit pipe -. -.Sh SYNOPSIS -.Nm -. -.Sh DESCIPTION -.Pp -.Nm -redirects standard input to a temporary file, -opens it in -.Ev EDITOR -(or -.Xr vi 1 , -if none is set) -and prints the contents of the (edited) file on standard output. -.Pp -.Nm -can be used as a versatile option selector. -The following sequence is a quick way to delete all lines but the current in -.Xr vi 1 : -.Dl :.w! -. -.Sh AUTHORS -.Pp -.Nm -is written by John Ankarström -.Aq Mt "john (at) ankarstrom.se" . diff --git a/etc/P b/etc/P new file mode 100755 index 0000000..3c11b20 --- /dev/null +++ b/etc/P @@ -0,0 +1,5 @@ +#!/bin/sh + +# P -- open file processed with p in PAGER + +"$PAGER" /var/tmp/pg diff --git a/etc/ce b/etc/ce new file mode 100755 index 0000000..c00d1bf --- /dev/null +++ b/etc/ce @@ -0,0 +1,28 @@ +#!/bin/sh + +# ce -- center text + +usage() { echo usage: $0 [cols] 1>&2; exit 1; } + +[ $# -gt 1 ] && usage + +if [ $# -eq 1 ]; then + cols=${1#-} + [ "$cols" -gt 0 ] || usage + shift +else + cols=`tput cols` + [ "$cols" -le 80 ] || cols=80 +fi + +while read line; do + line=${line## } + line=${line%% } + len=`echo "$line" | wc -c` + max=$(((cols - len) / 2)) + i=0 + while [ $((i++)) -lt $max ]; do + printf ' ' + done + echo "$line" +done diff --git a/etc/child b/etc/child new file mode 100755 index 0000000..32dab60 --- /dev/null +++ b/etc/child @@ -0,0 +1,27 @@ +#!/bin/sh + +# child -- print pid of youngest grandchild + +opt= +for x in "$@"; do + case "$x" in + -*) opt="$opt $x"; shift ;; + *) ;; + esac +done + +[ $# -ne 1 ] && { echo usage: $0 [-?] pid 1>&2; exit 1; } + +ps -do pid,etime,comm -k etime $opt | +pid=$1 perl -lane ' + if (/^ *$ENV{pid} / .. 1) { + next if /^ *$ENV{pid} /; + last if not /[|`-]/; + $t = 0; $i = 0; + $t += $_*(60**$i++) for reverse split /:/, $F[1]; + print "$t $_" if $t > 2; + } +' | +sort -n | +head -1 | +cut -d\ -f2 diff --git a/etc/colortest b/etc/colortest new file mode 100755 index 0000000..24aa95c --- /dev/null +++ b/etc/colortest @@ -0,0 +1,15 @@ +#!/bin/sh + +printf " " +for b in 0 1 2 3 4 5 6 7; do printf " 4${b}m "; done +echo +for f in "" 30 31 32 33 34 35 36 37; do + for s in "" "1;"; do + printf "%4sm" "${s}${f}" + printf " \033[%sm%s\033[0m" "$s$f" "gYw " + for b in 0 1 2 3 4 5 6 7; do + printf " \033[4%s;%sm%s\033[0m" "$b" "$s$f" " gYw " + done + echo + done +done diff --git a/etc/cpy b/etc/cpy new file mode 100755 index 0000000..827d21c --- /dev/null +++ b/etc/cpy @@ -0,0 +1,3 @@ +#!/bin/sh + +tee /tmp/cpy"$1" diff --git a/etc/cuthere b/etc/cuthere new file mode 100755 index 0000000..01c1606 --- /dev/null +++ b/etc/cuthere @@ -0,0 +1,2 @@ +#!/bin/sh +echo '--------------------8<------------------------------------' diff --git a/etc/ep b/etc/ep new file mode 100755 index 0000000..4be6317 --- /dev/null +++ b/etc/ep @@ -0,0 +1,9 @@ +#!/bin/sh + +# ep -- edit pipe + +tmp=`mktemp /tmp/ep.XXXXXX` +cat > $tmp +${EDITOR:-vi} $tmp < /dev/tty > /dev/tty +cat $tmp +rm $tmp diff --git a/etc/f b/etc/f new file mode 100755 index 0000000..7f541d8 --- /dev/null +++ b/etc/f @@ -0,0 +1,10 @@ +#!/bin/sh + +# f -- fmt with new line for each sentence + +fmt "$@" | +sed 's/\([^ ]\)\. \([^ ]\)/\1.\ +\.temporary line for fmt\ +\2/g' | +fmt "$@" | +sed '/^\.temporary line for fmt$/d' diff --git a/etc/flip b/etc/flip new file mode 100755 index 0000000..614bc67 --- /dev/null +++ b/etc/flip @@ -0,0 +1,3 @@ +#!/usr/bin/perl + +exec (shift @ARGV, pop @ARGV, @ARGV); diff --git a/etc/g b/etc/g new file mode 100755 index 0000000..7c55707 --- /dev/null +++ b/etc/g @@ -0,0 +1,30 @@ +#!/bin/sh + +# g -- poor man's ack + +IFS=' +' + +pat= +opt= +i=0 + +while [ $((i++)) -lt $# ]; do + case "$1" in + -*) opt=`printf '%s%s\n' "$opt" $1` + shift ;; + *) break ;; + esac +done + +[ $# -eq 0 ] && { echo usage: $0 [-...] pattern [file ...] 1>&2; exit 1; } + +pat=$1 +shift + +files=`find . -name '*.c' -or -name '*.h' -or -name '*.cc' | sed s,./,,` +[ -z "$files" ] && [ -z "$*" ] && { echo no matching files found 1>&2; exit 1; } + +# todo (?): treat argument \*.x like -or -name \*.x + +p grep $opt -n "$pat" $files "$@" diff --git a/etc/gspell b/etc/gspell new file mode 100755 index 0000000..e931f3c --- /dev/null +++ b/etc/gspell @@ -0,0 +1,18 @@ +#!/bin/sh + +# gspell -- print locations of spelling errors in file + +f=`mktemp` +if [ $# -eq 0 ]; then + g=`mktemp` + cat > $g + set -- $g +fi + +spell "$@" > $f +fgrep -Hnof $f "$@" | +awk -F: 'NF > 2 { print $0; prefix = $1 ":" $2 ":"; next } { print prefix $0 }' +s=$? +rm $f +rm $g 2>/dev/null +exit $s diff --git a/etc/imgur b/etc/imgur new file mode 100644 index 0000000..f459fc3 --- /dev/null +++ b/etc/imgur @@ -0,0 +1,123 @@ +#!/bin/sh + +# Imgur script by Bart Nagel +# Improvements by Tino Sino +# Made POSIX-compliant by John Ankarström +# Version 6 or more +# I release this into the public domain. Do with it what you will. +# The latest version can be found at https://github.com/tremby/imgur.sh + +# API Key provided by Bart; +# replace with your own or specify yours as IMGUR_CLIENT_ID envionment variable +# to avoid limits +default_client_id=c9a6efb3d7932fd +client_id="${IMGUR_CLIENT_ID:=$default_client_id}" + +# Function to output usage instructions +usage() { + echo "Usage: $(basename $0) [ [...]]" >&2 + echo + echo "Upload images to imgur and output their new URLs to stdout. Each one's" >&2 + echo "delete page is output to stderr between the view URLs." >&2 + echo + echo "A filename can be - to read from stdin. If no filename is given, stdin is read." >&2 + echo + echo "If xsel, xclip, pbcopy, or clip is available," >&2 + echo "the URLs are put on the X selection or clipboard for easy pasting." >&2 +} + +# Function to upload a path +# First argument should be a content spec understood by curl's -F option +upload() { + curl -s -H "Authorization: Client-ID $client_id" -H "Expect: " -F "image=$1" https://api.imgur.com/3/image.xml + # The "Expect: " header is to get around a problem when using this through + # the Squid proxy. Not sure if it's a Squid bug or what. +} + +# Check arguments +if [ x"$1" = x"-h" -o x"$1" = x"--help" ]; then + usage + exit 0 +elif [ $# -eq 0 ]; then + echo "No file specified; reading from stdin" >&2 + exec "$0" - +fi + +# Check curl is available +type curl 2>&1 >/dev/null || { + echo "Couldn't find curl, which is required." >&2 + exit 17 +} + +clip="" +errors=false + +# Loop through arguments +while [ $# -gt 0 ]; do + file="$1" + shift + + # Upload the image + case "$file" + http://*|https://*) + # URL -> imgur + response=$(upload "$file") 2>/dev/null + ;; + *) + # File -> imgur + # Check file exists + if [ x"$file" != x"-" -a ! -f "$file" ]; then + echo "File '$file' doesn't exist; skipping" >&2 + errors=true + continue + fi + response=$(upload "@$file") 2>/dev/null + esac + + if [ $? -ne 0 ]; then + echo "Upload failed" >&2 + errors=true + continue + elif echo "$response" | grep -q 'success="0"'; then + echo "Error message from imgur:" >&2 + msg="${response##*}" + echo "${msg%%*}" >&2 + errors=true + continue + fi + + # Parse the response and output our stuff + url="${response##*}" + url="${url%%*}" + delete_hash="${response##*}" + delete_hash="${delete_hash%%*}" + echo $url | sed 's/^http:/https:/' + echo "Delete page: https://imgur.com/delete/$delete_hash" >&2 + + # Append the URL to a string so we can put them all on the clipboard later + clip+="$url" + if [ $# -gt 0 ]; then + clip+=$'\n' + fi +done + +# Put the URLs on the clipboard if we can +if type pbcopy 2>&1 >/dev/null; then + echo -n "$clip" | pbcopy +elif type clip 2>&1 >/dev/null; then + echo -n "$clip" | clip +elif [ $DISPLAY ]; then + if type xsel 2>&1 >/dev/null; then + echo -n "$clip" | xsel -i + elif type xclip 2>&1 >/dev/null; then + echo -n "$clip" | xclip + else + echo "Haven't copied to the clipboard: no xsel or xclip" >&2 + fi +else + echo "Haven't copied to the clipboard: no \$DISPLAY or pbcopy or clip" >&2 +fi + +if $errors; then + exit 1 +fi diff --git a/etc/inc b/etc/inc new file mode 100755 index 0000000..51345a5 --- /dev/null +++ b/etc/inc @@ -0,0 +1,3 @@ +#!/usr/bin/perl -p +# inc -- increment numbers in lines +s/\d+/$n=$& if!$n;$n+$i++/e diff --git a/etc/isort b/etc/isort new file mode 100755 index 0000000..eecde11 --- /dev/null +++ b/etc/isort @@ -0,0 +1,21 @@ +#!/usr/bin/perl -p + +# isort -- sort C variable declarations separated by commas + +# Extract words, save prefix. +s/([^,]*?)(\S+[,;])/$2/; +$prefix = $1; + +# Ensure all words end with comma. +$semicolon = s/;$/,/; + +# Sort words. +@words = sort { + ($x = $a) =~ s/^\*+//; + ($y = $b) =~ s/^\*+//; + $x cmp $y +} split /\s+/; + +# Join words, add prefix and semicolon. +$_ = $prefix . (join ' ', @words) . "\n"; +s/,$/;/ if $semicolon; diff --git a/etc/lorem b/etc/lorem new file mode 100755 index 0000000..3dc7042 --- /dev/null +++ b/etc/lorem @@ -0,0 +1,5 @@ +#!/bin/sh + +cat <&2; exit 1; } + +# Default values +n=2 +s='. ' + +# Parse options +while getopts n:s: o +do + case $o in + n) n=$OPTARG ;; + s) s=$OPTARG ;; + ?) usage ;; + esac +done +shift $((OPTIND-1)) + +# Validate options +case "$n" in +[1-9]) ;; +*) echo $0: n must be a number from 1 to 9 1>&2 + exit 1 ;; +esac +test -z "$1" && usage + +# Construct glob and regex substitution from -s and -n +i=0; while test $((i++)) -lt "$n"; do sub=$sub'[0-9]'; done +glob=$sub +sub="s/^$sub$(printf '%s\n' "$s" | sed 's/\([.*[\\]\|\]\)/\\&/g')//" + +totext() { + for f in "$@"; do printf '%s\n' "$f"; done | + sort | + sed "$sub" +} + +fromtext() { + nl -s.\ -w2 -nrz | { + i=1 + while read new + do + name=`printf '%s\n' "$new" | sed "$sub"` + if test -e "$name" + then mv "$name" "$new" + else mv $glob"$s$name" "$new" 2>&- + fi + done + } +} + +# Edit order +totext "$@" | ep | fromtext diff --git a/etc/p b/etc/p new file mode 100755 index 0000000..b145031 --- /dev/null +++ b/etc/p @@ -0,0 +1,7 @@ +#!/bin/sh + +# p -- maybe view command output in pager + +[ -t 0 ] && exec /bin/sh -c '"$@" 2>&1 | "$0"' "$0" "$@" + +cat | tee /var/tmp/pg diff --git a/etc/pst b/etc/pst new file mode 100755 index 0000000..dd6bd64 --- /dev/null +++ b/etc/pst @@ -0,0 +1,17 @@ +#!/bin/sh + +d= +while getopts d o +do + case $o in + d) d=1 ;; + ?) echo usage: $0 [-d] [suffix] 1>&2; exit 1 ;; + esac +done +shift $((OPTIND-1)) +s=$1 + +test ! -e /tmp/cpy"$s" && { echo clipboard not present 1>&2; exit 1; } +cat /tmp/cpy"$s" +test ! -z "$d" && rm /tmp/cpy"$s" +return 0 diff --git a/etc/re! b/etc/re! new file mode 100755 index 0000000..1314ae9 --- /dev/null +++ b/etc/re! @@ -0,0 +1,48 @@ +#!/usr/bin/env perl + +# re! -- rewrite shebangs + +use strict; + +my $test = 0; +sub usage { die "usage: $0 [-n] file ...\n" } + +if (@ARGV and $ARGV[0] eq '-n') { + $test = 1; + shift @ARGV; +} +usage if not @ARGV; + +for my $file (@ARGV) { + open my $o, '<', $file or die "could not open $file: $!\n"; + + # parse shebang + my $shebang = <$o>; + $shebang =~ /^#!/ or die "no shebang: $file\n"; + $shebang =~ /^#!\s*(\S+)\s*(.*)/; + my ($old, $args) = ($1, $2); + + # validate path + next if -x $old; + + # get new path + (my $basename = $old) =~ s,.*/,,; + chomp(my $new = `which $basename`); + $new or die "could not find $basename\n"; + next if $old eq $new; + + # print results if test + if ($test) { + print "$file: $old -> $new\n"; + next; + } + + # write new shebang + open my $n, '>', "$file.tmp" or die "could not open $file.tmp: $!\n"; + print $n "#!$new $args\n"; + print $n $_ while <$o>; + + close for ($o, $n); + system('mv', "$file.tmp", $file) == 0 + or die "could not overwrite $file\n"; +} diff --git a/etc/wpdf b/etc/wpdf new file mode 100755 index 0000000..94e5029 --- /dev/null +++ b/etc/wpdf @@ -0,0 +1,76 @@ +#!/usr/bin/perl + +# wpdf -- view, watch and remake pdf based on Makefile + +use strict; +use warnings; + +my $alive; # number of children alive +my %deptarget; # dependency => target +my $parent = $$; # pid of parent + +$SIG{USR1} = sub { kill 'HUP', 0 if not --$alive }; +$SIG{HUP} = sub { exit 0 }; + +# collect dependencies for given files +for my $target (@ARGV) { + # if pdf, collect from Makefile + if ($target =~ /\.pdf$/) { + (my $basename = $target) =~ s/\.pdf$//; + open my $f, '<', 'Makefile' + or die "could not open Makefile: $!\n"; + while (<$f>) { + # explicit + if (/^\Q$target\E:\s*(.*)/) { + $deptarget{$_} = $target for split /\s/, $1; + last; + } + # implicit + if (/^\.([^ .]+)\.pdf\s*:\s*(.*)/) { + $deptarget{"$basename.$1"} = $target; + $deptarget{$_} = $target for split /\s/, $2; + last; + } + } + close $f; + } + + # if not pdf, assume target is actually source file and collect from it + # (with build(1) syntax) + else { + my $i = 0; + my $source = $target; + $target =~ s,\.[^./]*$,,; $target .= '.pdf'; + $deptarget{$source} = $target; + + open my $f, '<', $source; + while (<$f>) { + last if ++$i > 20; + if (/\s% (.*)/) { + $deptarget{$_} = $target for split /\s/, $1; + last; + } + } + close $f; + } + + if (fork == 0) { + system 'xpdf', '-remote', "wpdf-$target", $target; + kill 'USR1', $parent; + exit; + } + $alive++; +} + +die "no dependencies found\n" if not keys %deptarget; + +# make pdf on demand +open my $p, '-|', 'watch', keys %deptarget + or die "could not start watch: $!\n"; +while (<$p>) { + chomp; + system('make', "$deptarget{$_}") == 0 + && system('xpdf', '-remote', "wpdf-$deptarget{$_}", '-reload'); +} +close $p; +exit($? != 0); diff --git a/etc/xtopen b/etc/xtopen new file mode 100755 index 0000000..ccda2e5 --- /dev/null +++ b/etc/xtopen @@ -0,0 +1,41 @@ +#!/bin/sh + +# xtopen -- run command in xterm + +abbr() { + case "$1" in + /home/$USER/*) a='~'${1#/home/$USER} ;; + /home/$USER) a='~' ;; + /home/*) a='~'${1#/home/} ;; + *) a=$1 ;; + esac + printf '%s\n' "$a" +} + +if [ $# -eq 0 ]; then + xmessage -buttons sorry:0 -default sorry -nearmouse \ + "usage: $0 [-o xterm-opt] [-p prefix] cmd ..." + exit 1 +fi + +o= +p= +while getopts o:p: opt; do + case $opt in + o) o=$OPTARG ;; + p) p=$OPTARG ;; + ?) xmessage -buttons sorry:0 -default sorry -nearmouse \ + error: "unknown flag $1" + exit 1 ;; + esac +done +shift $((OPTIND-1)) + +if ! which "$1" >/dev/null; then + xmessage -default okay -nearmouse \ + error: "program $1 not found" + exit 1 +fi + +export LC_ALL=en_US.ISO8859-1 # speed up xterm start +exec xterm -title "$* (`abbr "$PWD"`)" $o -e u $p "$@" diff --git a/f b/f deleted file mode 100755 index 7f541d8..0000000 --- a/f +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -# f -- fmt with new line for each sentence - -fmt "$@" | -sed 's/\([^ ]\)\. \([^ ]\)/\1.\ -\.temporary line for fmt\ -\2/g' | -fmt "$@" | -sed '/^\.temporary line for fmt$/d' diff --git a/f.1 b/f.1 deleted file mode 100644 index 104ebae..0000000 --- a/f.1 +++ /dev/null @@ -1,27 +0,0 @@ -.Dd $Mdocdate$ -.Dt f 1 -.Os -. -.Sh NAME -.Nm f -.Nd fmt but with new sentence on new line -. -.Sh SYNOPSIS -.Nm f -.Op Ar arg ... -. -.Sh DESCIPTION -.Pp -.Nm -runs -.Xr fmt 1 -with any given -.Ar arg -in a way such that each new sentence begins on a new line. -Sentence breaks are recognized if the period in the original text -is followed by two spaces or a newline. -.Sh AUTHORS -.Pp -.Nm -is written by John Ankarström -.Aq Mt john (at) ankarstrom.se . diff --git a/flip b/flip deleted file mode 100755 index 614bc67..0000000 --- a/flip +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/perl - -exec (shift @ARGV, pop @ARGV, @ARGV); diff --git a/g b/g deleted file mode 100755 index 7c55707..0000000 --- a/g +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -# g -- poor man's ack - -IFS=' -' - -pat= -opt= -i=0 - -while [ $((i++)) -lt $# ]; do - case "$1" in - -*) opt=`printf '%s%s\n' "$opt" $1` - shift ;; - *) break ;; - esac -done - -[ $# -eq 0 ] && { echo usage: $0 [-...] pattern [file ...] 1>&2; exit 1; } - -pat=$1 -shift - -files=`find . -name '*.c' -or -name '*.h' -or -name '*.cc' | sed s,./,,` -[ -z "$files" ] && [ -z "$*" ] && { echo no matching files found 1>&2; exit 1; } - -# todo (?): treat argument \*.x like -or -name \*.x - -p grep $opt -n "$pat" $files "$@" diff --git a/git-bdiff b/git-bdiff deleted file mode 100755 index 9b39ad4..0000000 --- a/git-bdiff +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/perl - -# git-bdiff -- fake compare binary files - -use strict; -use warnings; - -my $i; - -if (@ARGV == 1) { - $i = 0; -} elsif (@ARGV == 7) { - $i = 4; -} else { - die <) { - # explicit - if (/^\Q$target\E:\s*(.*)/) { - push @deps, "$repo/$path$_" for split /\s/, $1; - last; - } - # implicit - if (/^\.([^ .]+)\.\Q$ext\E\s*:\s*(.*)/) { - push @deps, "$repo/$path$basename.$1"; - push @deps, "$repo/$path$_" for split /\s/, $2; - last; - } -} -close $f; -die "no dependencies found, cannot compare\n" if not @deps; - -$i = 0; -for (`git diff HEAD -- @deps`) { - print if @ARGV == 7; - $i = 1; -} -exit $i if @ARGV == 1; diff --git a/git-orig b/git-orig deleted file mode 100755 index a792390..0000000 --- a/git-orig +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# git-orig -- checkout original file - -[ $# -lt 2 ] && { echo "usage: $0 head file [...]" 1>&2; exit 1; } - -h=$1 -shift -set -e - -for f in "$@"; do - mv -i "$f" "$f".new -done - -git checkout "$h" -- "$@" - -for f in "$@"; do - mv -i "$f" "$f".orig - mv "$f".new "$f" -done diff --git a/git-s b/git-s deleted file mode 100755 index faf55ff..0000000 --- a/git-s +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# git-s -- selection-friendly git-status - -git status -s | perl -ne ' - push @{$x{$1}}, $2 if /^(.). (.*)/; - push @{$y{$1}}, $2 if /^.(.) (.*)/; - END { - delete $x{"?"}; delete $x{" "}; delete $y{" "}; - for (["index" => \%x], ["tree" => \%y]) { - ($n, $h) = @$_; - print "$n:" if values %$h; - for (sort keys %$h) { - print " $_ "; - print " $_" for @{$h->{$_}}; - print "\n"; - } - } - } -' diff --git a/git-st b/git-st deleted file mode 100755 index 8edae3f..0000000 --- a/git-st +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/perl - -# git-st -- show git status (but handle binary files correctly) - -open $p, '-|', 'git', '-c', 'color.status=always', 'status', @ARGV - or die "$!\n"; -chomp($g = `git rev-parse --show-toplevel`); - -while (<$p>) { - if (/^Changes not staged for commit:$/ .. /^$/) { - if (/modified:\s+(.*\.pdf)/) { - $f = "$ENV{PWD}/$1"; - $f =~ s,^\Q$g\E/?,,; - $f =~ s/'/'"'"'/g; - `git-bdiff '$f'`; - if ($?) { - $mbuf .= $_; - $mod = 1; - } - } else { - $mod = 1 if not $mod and /[^t]:\s+/; - $mbuf .= $_; - } - $buf .= $mbuf if /^$/ and $mod; - } else { - $buf .= $_; - } -} - -close $p; -print $buf; diff --git a/git/git-bdiff b/git/git-bdiff new file mode 100755 index 0000000..9b39ad4 --- /dev/null +++ b/git/git-bdiff @@ -0,0 +1,51 @@ +#!/usr/bin/perl + +# git-bdiff -- fake compare binary files + +use strict; +use warnings; + +my $i; + +if (@ARGV == 1) { + $i = 0; +} elsif (@ARGV == 7) { + $i = 4; +} else { + die <) { + # explicit + if (/^\Q$target\E:\s*(.*)/) { + push @deps, "$repo/$path$_" for split /\s/, $1; + last; + } + # implicit + if (/^\.([^ .]+)\.\Q$ext\E\s*:\s*(.*)/) { + push @deps, "$repo/$path$basename.$1"; + push @deps, "$repo/$path$_" for split /\s/, $2; + last; + } +} +close $f; +die "no dependencies found, cannot compare\n" if not @deps; + +$i = 0; +for (`git diff HEAD -- @deps`) { + print if @ARGV == 7; + $i = 1; +} +exit $i if @ARGV == 1; diff --git a/git/git-orig b/git/git-orig new file mode 100755 index 0000000..a792390 --- /dev/null +++ b/git/git-orig @@ -0,0 +1,20 @@ +#!/bin/sh + +# git-orig -- checkout original file + +[ $# -lt 2 ] && { echo "usage: $0 head file [...]" 1>&2; exit 1; } + +h=$1 +shift +set -e + +for f in "$@"; do + mv -i "$f" "$f".new +done + +git checkout "$h" -- "$@" + +for f in "$@"; do + mv -i "$f" "$f".orig + mv "$f".new "$f" +done diff --git a/git/git-s b/git/git-s new file mode 100755 index 0000000..faf55ff --- /dev/null +++ b/git/git-s @@ -0,0 +1,20 @@ +#!/bin/sh + +# git-s -- selection-friendly git-status + +git status -s | perl -ne ' + push @{$x{$1}}, $2 if /^(.). (.*)/; + push @{$y{$1}}, $2 if /^.(.) (.*)/; + END { + delete $x{"?"}; delete $x{" "}; delete $y{" "}; + for (["index" => \%x], ["tree" => \%y]) { + ($n, $h) = @$_; + print "$n:" if values %$h; + for (sort keys %$h) { + print " $_ "; + print " $_" for @{$h->{$_}}; + print "\n"; + } + } + } +' diff --git a/git/git-st b/git/git-st new file mode 100755 index 0000000..8edae3f --- /dev/null +++ b/git/git-st @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +# git-st -- show git status (but handle binary files correctly) + +open $p, '-|', 'git', '-c', 'color.status=always', 'status', @ARGV + or die "$!\n"; +chomp($g = `git rev-parse --show-toplevel`); + +while (<$p>) { + if (/^Changes not staged for commit:$/ .. /^$/) { + if (/modified:\s+(.*\.pdf)/) { + $f = "$ENV{PWD}/$1"; + $f =~ s,^\Q$g\E/?,,; + $f =~ s/'/'"'"'/g; + `git-bdiff '$f'`; + if ($?) { + $mbuf .= $_; + $mod = 1; + } + } else { + $mod = 1 if not $mod and /[^t]:\s+/; + $mbuf .= $_; + } + $buf .= $mbuf if /^$/ and $mod; + } else { + $buf .= $_; + } +} + +close $p; +print $buf; diff --git a/gspell b/gspell deleted file mode 100755 index e931f3c..0000000 --- a/gspell +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -# gspell -- print locations of spelling errors in file - -f=`mktemp` -if [ $# -eq 0 ]; then - g=`mktemp` - cat > $g - set -- $g -fi - -spell "$@" > $f -fgrep -Hnof $f "$@" | -awk -F: 'NF > 2 { print $0; prefix = $1 ":" $2 ":"; next } { print prefix $0 }' -s=$? -rm $f -rm $g 2>/dev/null -exit $s diff --git a/imgur b/imgur deleted file mode 100644 index f459fc3..0000000 --- a/imgur +++ /dev/null @@ -1,123 +0,0 @@ -#!/bin/sh - -# Imgur script by Bart Nagel -# Improvements by Tino Sino -# Made POSIX-compliant by John Ankarström -# Version 6 or more -# I release this into the public domain. Do with it what you will. -# The latest version can be found at https://github.com/tremby/imgur.sh - -# API Key provided by Bart; -# replace with your own or specify yours as IMGUR_CLIENT_ID envionment variable -# to avoid limits -default_client_id=c9a6efb3d7932fd -client_id="${IMGUR_CLIENT_ID:=$default_client_id}" - -# Function to output usage instructions -usage() { - echo "Usage: $(basename $0) [ [...]]" >&2 - echo - echo "Upload images to imgur and output their new URLs to stdout. Each one's" >&2 - echo "delete page is output to stderr between the view URLs." >&2 - echo - echo "A filename can be - to read from stdin. If no filename is given, stdin is read." >&2 - echo - echo "If xsel, xclip, pbcopy, or clip is available," >&2 - echo "the URLs are put on the X selection or clipboard for easy pasting." >&2 -} - -# Function to upload a path -# First argument should be a content spec understood by curl's -F option -upload() { - curl -s -H "Authorization: Client-ID $client_id" -H "Expect: " -F "image=$1" https://api.imgur.com/3/image.xml - # The "Expect: " header is to get around a problem when using this through - # the Squid proxy. Not sure if it's a Squid bug or what. -} - -# Check arguments -if [ x"$1" = x"-h" -o x"$1" = x"--help" ]; then - usage - exit 0 -elif [ $# -eq 0 ]; then - echo "No file specified; reading from stdin" >&2 - exec "$0" - -fi - -# Check curl is available -type curl 2>&1 >/dev/null || { - echo "Couldn't find curl, which is required." >&2 - exit 17 -} - -clip="" -errors=false - -# Loop through arguments -while [ $# -gt 0 ]; do - file="$1" - shift - - # Upload the image - case "$file" - http://*|https://*) - # URL -> imgur - response=$(upload "$file") 2>/dev/null - ;; - *) - # File -> imgur - # Check file exists - if [ x"$file" != x"-" -a ! -f "$file" ]; then - echo "File '$file' doesn't exist; skipping" >&2 - errors=true - continue - fi - response=$(upload "@$file") 2>/dev/null - esac - - if [ $? -ne 0 ]; then - echo "Upload failed" >&2 - errors=true - continue - elif echo "$response" | grep -q 'success="0"'; then - echo "Error message from imgur:" >&2 - msg="${response##*}" - echo "${msg%%*}" >&2 - errors=true - continue - fi - - # Parse the response and output our stuff - url="${response##*}" - url="${url%%*}" - delete_hash="${response##*}" - delete_hash="${delete_hash%%*}" - echo $url | sed 's/^http:/https:/' - echo "Delete page: https://imgur.com/delete/$delete_hash" >&2 - - # Append the URL to a string so we can put them all on the clipboard later - clip+="$url" - if [ $# -gt 0 ]; then - clip+=$'\n' - fi -done - -# Put the URLs on the clipboard if we can -if type pbcopy 2>&1 >/dev/null; then - echo -n "$clip" | pbcopy -elif type clip 2>&1 >/dev/null; then - echo -n "$clip" | clip -elif [ $DISPLAY ]; then - if type xsel 2>&1 >/dev/null; then - echo -n "$clip" | xsel -i - elif type xclip 2>&1 >/dev/null; then - echo -n "$clip" | xclip - else - echo "Haven't copied to the clipboard: no xsel or xclip" >&2 - fi -else - echo "Haven't copied to the clipboard: no \$DISPLAY or pbcopy or clip" >&2 -fi - -if $errors; then - exit 1 -fi diff --git a/inc b/inc deleted file mode 100755 index 51345a5..0000000 --- a/inc +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/perl -p -# inc -- increment numbers in lines -s/\d+/$n=$& if!$n;$n+$i++/e diff --git a/isort b/isort deleted file mode 100755 index eecde11..0000000 --- a/isort +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/perl -p - -# isort -- sort C variable declarations separated by commas - -# Extract words, save prefix. -s/([^,]*?)(\S+[,;])/$2/; -$prefix = $1; - -# Ensure all words end with comma. -$semicolon = s/;$/,/; - -# Sort words. -@words = sort { - ($x = $a) =~ s/^\*+//; - ($y = $b) =~ s/^\*+//; - $x cmp $y -} split /\s+/; - -# Join words, add prefix and semicolon. -$_ = $prefix . (join ' ', @words) . "\n"; -s/,$/;/ if $semicolon; diff --git a/lorem b/lorem deleted file mode 100755 index 3dc7042..0000000 --- a/lorem +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -cat <&2; exit 1; } - -# Default values -n=2 -s='. ' - -# Parse options -while getopts n:s: o -do - case $o in - n) n=$OPTARG ;; - s) s=$OPTARG ;; - ?) usage ;; - esac -done -shift $((OPTIND-1)) - -# Validate options -case "$n" in -[1-9]) ;; -*) echo $0: n must be a number from 1 to 9 1>&2 - exit 1 ;; -esac -test -z "$1" && usage - -# Construct glob and regex substitution from -s and -n -i=0; while test $((i++)) -lt "$n"; do sub=$sub'[0-9]'; done -glob=$sub -sub="s/^$sub$(printf '%s\n' "$s" | sed 's/\([.*[\\]\|\]\)/\\&/g')//" - -totext() { - for f in "$@"; do printf '%s\n' "$f"; done | - sort | - sed "$sub" -} - -fromtext() { - nl -s.\ -w2 -nrz | { - i=1 - while read new - do - name=`printf '%s\n' "$new" | sed "$sub"` - if test -e "$name" - then mv "$name" "$new" - else mv $glob"$s$name" "$new" 2>&- - fi - done - } -} - -# Edit order -totext "$@" | ep | fromtext diff --git a/ord.1 b/ord.1 deleted file mode 100644 index 9ab54a5..0000000 --- a/ord.1 +++ /dev/null @@ -1,51 +0,0 @@ -.Dd $Mdocdate$ -.Dt ord 1 -.Os -. -.Sh NAME -.Nm ord -.Nd re-order files with numeric indices -. -.Sh SYNOPSIS -.Nm -.Op Fl n Ar "number width" -.Op Fl s Ar separator -.Ar file ... -. -.Sh DESCIPTION -.Pp -.Nm -is a convenient utility for re-ordering numerically indexed files, i.e. files with names beginning with -.Ql 01.\ , -.Ql 02.\ -and so forth. -Among other things, it is useful for managing disk-based playlists. - -Given any number of files as arguments, -.Nm -will open a temporary text file in your -.Ev EDITOR , -in which you can re-order the files by re-ordering lines. -Save the file and exit the text editor to change the names of the files to reflect the new order. - -The -.Fl n -and -.Fl s -control the format of the numeric indices expected and created by -.Nm . -Their respective default values are 2 and -.Ql .\ . - -Note that -.Fl n -and -.Fl s -cannot be used to change the format of existing numeric indices. -Such functionality is not provided by -.Nm . -.Sh AUTHORS -.Pp -.Nm -is written by John Ankarström -.Aq Mt john (at) ankarstrom.se . diff --git a/p b/p deleted file mode 100755 index b145031..0000000 --- a/p +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -# p -- maybe view command output in pager - -[ -t 0 ] && exec /bin/sh -c '"$@" 2>&1 | "$0"' "$0" "$@" - -cat | tee /var/tmp/pg diff --git a/pl b/pl deleted file mode 100755 index a331623..0000000 --- a/pl +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -a=${0##*/} -a=${a#pl} -case $a in -[A-z]) exec perldoc -$a "$@" ;; -*) exec perldoc "$@" ;; -esac diff --git a/pl/pl b/pl/pl new file mode 100755 index 0000000..a331623 --- /dev/null +++ b/pl/pl @@ -0,0 +1,8 @@ +#!/bin/sh + +a=${0##*/} +a=${a#pl} +case $a in +[A-z]) exec perldoc -$a "$@" ;; +*) exec perldoc "$@" ;; +esac diff --git a/pl/pla b/pl/pla new file mode 120000 index 0000000..55239f3 --- /dev/null +++ b/pl/pla @@ -0,0 +1 @@ +pl \ No newline at end of file diff --git a/pl/plf b/pl/plf new file mode 120000 index 0000000..55239f3 --- /dev/null +++ b/pl/plf @@ -0,0 +1 @@ +pl \ No newline at end of file diff --git a/pl/plh b/pl/plh new file mode 120000 index 0000000..55239f3 --- /dev/null +++ b/pl/plh @@ -0,0 +1 @@ +pl \ No newline at end of file diff --git a/pl/plm b/pl/plm new file mode 120000 index 0000000..55239f3 --- /dev/null +++ b/pl/plm @@ -0,0 +1 @@ +pl \ No newline at end of file diff --git a/pl/plq b/pl/plq new file mode 120000 index 0000000..55239f3 --- /dev/null +++ b/pl/plq @@ -0,0 +1 @@ +pl \ No newline at end of file diff --git a/pl/plv b/pl/plv new file mode 120000 index 0000000..55239f3 --- /dev/null +++ b/pl/plv @@ -0,0 +1 @@ +pl \ No newline at end of file diff --git a/pla b/pla deleted file mode 120000 index 55239f3..0000000 --- a/pla +++ /dev/null @@ -1 +0,0 @@ -pl \ No newline at end of file diff --git a/plf b/plf deleted file mode 120000 index 55239f3..0000000 --- a/plf +++ /dev/null @@ -1 +0,0 @@ -pl \ No newline at end of file diff --git a/plh b/plh deleted file mode 120000 index 55239f3..0000000 --- a/plh +++ /dev/null @@ -1 +0,0 @@ -pl \ No newline at end of file diff --git a/plm b/plm deleted file mode 120000 index 55239f3..0000000 --- a/plm +++ /dev/null @@ -1 +0,0 @@ -pl \ No newline at end of file diff --git a/plq b/plq deleted file mode 120000 index 55239f3..0000000 --- a/plq +++ /dev/null @@ -1 +0,0 @@ -pl \ No newline at end of file diff --git a/plv b/plv deleted file mode 120000 index 55239f3..0000000 --- a/plv +++ /dev/null @@ -1 +0,0 @@ -pl \ No newline at end of file diff --git a/pst b/pst deleted file mode 100755 index dd6bd64..0000000 --- a/pst +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -d= -while getopts d o -do - case $o in - d) d=1 ;; - ?) echo usage: $0 [-d] [suffix] 1>&2; exit 1 ;; - esac -done -shift $((OPTIND-1)) -s=$1 - -test ! -e /tmp/cpy"$s" && { echo clipboard not present 1>&2; exit 1; } -cat /tmp/cpy"$s" -test ! -z "$d" && rm /tmp/cpy"$s" -return 0 diff --git a/pst.1 b/pst.1 deleted file mode 120000 index 0ececb2..0000000 --- a/pst.1 +++ /dev/null @@ -1 +0,0 @@ -cpy.1 \ No newline at end of file diff --git a/re! b/re! deleted file mode 100755 index 1314ae9..0000000 --- a/re! +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env perl - -# re! -- rewrite shebangs - -use strict; - -my $test = 0; -sub usage { die "usage: $0 [-n] file ...\n" } - -if (@ARGV and $ARGV[0] eq '-n') { - $test = 1; - shift @ARGV; -} -usage if not @ARGV; - -for my $file (@ARGV) { - open my $o, '<', $file or die "could not open $file: $!\n"; - - # parse shebang - my $shebang = <$o>; - $shebang =~ /^#!/ or die "no shebang: $file\n"; - $shebang =~ /^#!\s*(\S+)\s*(.*)/; - my ($old, $args) = ($1, $2); - - # validate path - next if -x $old; - - # get new path - (my $basename = $old) =~ s,.*/,,; - chomp(my $new = `which $basename`); - $new or die "could not find $basename\n"; - next if $old eq $new; - - # print results if test - if ($test) { - print "$file: $old -> $new\n"; - next; - } - - # write new shebang - open my $n, '>', "$file.tmp" or die "could not open $file.tmp: $!\n"; - print $n "#!$new $args\n"; - print $n $_ while <$o>; - - close for ($o, $n); - system('mv', "$file.tmp", $file) == 0 - or die "could not overwrite $file\n"; -} diff --git a/with-git b/with-git deleted file mode 100755 index 8952a82..0000000 --- a/with-git +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -[ x"$1" = x"-s" ] && { s=$1; shift; } || s= -"$@" -[ -z "$s" ] || git status -exec repl "${GIT:-git}" diff --git a/with-pager b/with-pager deleted file mode 100755 index 10f8717..0000000 --- a/with-pager +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -"$@" | ${PAGER:-less} diff --git a/with-shell b/with-shell deleted file mode 100755 index 364d2ac..0000000 --- a/with-shell +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -"$@" -exec "${SHELL:-sh}" diff --git a/with-shell-on-error b/with-shell-on-error deleted file mode 100755 index d29a1d6..0000000 --- a/with-shell-on-error +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -"$@" || exec "${SHELL:-sh}" diff --git a/with/with-git b/with/with-git new file mode 100755 index 0000000..8952a82 --- /dev/null +++ b/with/with-git @@ -0,0 +1,5 @@ +#!/bin/sh +[ x"$1" = x"-s" ] && { s=$1; shift; } || s= +"$@" +[ -z "$s" ] || git status +exec repl "${GIT:-git}" diff --git a/with/with-pager b/with/with-pager new file mode 100755 index 0000000..10f8717 --- /dev/null +++ b/with/with-pager @@ -0,0 +1,2 @@ +#!/bin/sh +"$@" | ${PAGER:-less} diff --git a/with/with-shell b/with/with-shell new file mode 100755 index 0000000..364d2ac --- /dev/null +++ b/with/with-shell @@ -0,0 +1,3 @@ +#!/bin/sh +"$@" +exec "${SHELL:-sh}" diff --git a/with/with-shell-on-error b/with/with-shell-on-error new file mode 100755 index 0000000..d29a1d6 --- /dev/null +++ b/with/with-shell-on-error @@ -0,0 +1,2 @@ +#!/bin/sh +"$@" || exec "${SHELL:-sh}" diff --git a/wpdf b/wpdf deleted file mode 100755 index 94e5029..0000000 --- a/wpdf +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/perl - -# wpdf -- view, watch and remake pdf based on Makefile - -use strict; -use warnings; - -my $alive; # number of children alive -my %deptarget; # dependency => target -my $parent = $$; # pid of parent - -$SIG{USR1} = sub { kill 'HUP', 0 if not --$alive }; -$SIG{HUP} = sub { exit 0 }; - -# collect dependencies for given files -for my $target (@ARGV) { - # if pdf, collect from Makefile - if ($target =~ /\.pdf$/) { - (my $basename = $target) =~ s/\.pdf$//; - open my $f, '<', 'Makefile' - or die "could not open Makefile: $!\n"; - while (<$f>) { - # explicit - if (/^\Q$target\E:\s*(.*)/) { - $deptarget{$_} = $target for split /\s/, $1; - last; - } - # implicit - if (/^\.([^ .]+)\.pdf\s*:\s*(.*)/) { - $deptarget{"$basename.$1"} = $target; - $deptarget{$_} = $target for split /\s/, $2; - last; - } - } - close $f; - } - - # if not pdf, assume target is actually source file and collect from it - # (with build(1) syntax) - else { - my $i = 0; - my $source = $target; - $target =~ s,\.[^./]*$,,; $target .= '.pdf'; - $deptarget{$source} = $target; - - open my $f, '<', $source; - while (<$f>) { - last if ++$i > 20; - if (/\s% (.*)/) { - $deptarget{$_} = $target for split /\s/, $1; - last; - } - } - close $f; - } - - if (fork == 0) { - system 'xpdf', '-remote', "wpdf-$target", $target; - kill 'USR1', $parent; - exit; - } - $alive++; -} - -die "no dependencies found\n" if not keys %deptarget; - -# make pdf on demand -open my $p, '-|', 'watch', keys %deptarget - or die "could not start watch: $!\n"; -while (<$p>) { - chomp; - system('make', "$deptarget{$_}") == 0 - && system('xpdf', '-remote', "wpdf-$deptarget{$_}", '-reload'); -} -close $p; -exit($? != 0); diff --git a/xtopen b/xtopen deleted file mode 100755 index ccda2e5..0000000 --- a/xtopen +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh - -# xtopen -- run command in xterm - -abbr() { - case "$1" in - /home/$USER/*) a='~'${1#/home/$USER} ;; - /home/$USER) a='~' ;; - /home/*) a='~'${1#/home/} ;; - *) a=$1 ;; - esac - printf '%s\n' "$a" -} - -if [ $# -eq 0 ]; then - xmessage -buttons sorry:0 -default sorry -nearmouse \ - "usage: $0 [-o xterm-opt] [-p prefix] cmd ..." - exit 1 -fi - -o= -p= -while getopts o:p: opt; do - case $opt in - o) o=$OPTARG ;; - p) p=$OPTARG ;; - ?) xmessage -buttons sorry:0 -default sorry -nearmouse \ - error: "unknown flag $1" - exit 1 ;; - esac -done -shift $((OPTIND-1)) - -if ! which "$1" >/dev/null; then - xmessage -default okay -nearmouse \ - error: "program $1 not found" - exit 1 -fi - -export LC_ALL=en_US.ISO8859-1 # speed up xterm start -exec xterm -title "$* (`abbr "$PWD"`)" $o -e u $p "$@" -- cgit v1.2.3