diff options
-rw-r--r-- | Makefile | 6 | ||||
-rwxr-xr-x | cpy | 3 | ||||
-rw-r--r-- | cpy.1 | 48 | ||||
-rw-r--r-- | ep | 9 | ||||
-rwxr-xr-x | ord | 60 | ||||
-rw-r--r-- | ord.1 | 51 | ||||
-rwxr-xr-x | pst | 17 | ||||
l--------- | pst.1 | 1 |
8 files changed, 195 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..72160f1 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +install: bin man + +man: + install -m 644 *.1 /usr/share/man/man1/ +bin: + ls * | grep -v '\.1$$' | xargs -I{} install {} /usr/local/bin/ @@ -0,0 +1,3 @@ +#!/bin/sh + +tee /tmp/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 . @@ -0,0 +1,9 @@ +#!/bin/sh + +# ep -- edit pipe + +tmp=/tmp/ep.$RANDOM +cat > $tmp +${EDITOR:-vi} $tmp < /dev/tty > /dev/tty +cat $tmp +rm $tmp @@ -0,0 +1,60 @@ +#!/bin/sh + +# Order files by adding/changing numbers (like "01. ") in front of their names + +usage() { echo usage: $0 [-n number width] [-s separator] 1>&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 +tmp=/tmp/ord.$RANDOM +totext "$@" > $tmp +${EDITOR:-vi} $tmp +fromtext < $tmp +rm $tmp @@ -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 . @@ -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 @@ -0,0 +1 @@ +cpy.1
\ No newline at end of file |