aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rwxr-xr-xcpy3
-rw-r--r--cpy.148
-rw-r--r--ep9
-rwxr-xr-xord60
-rw-r--r--ord.151
-rwxr-xr-xpst17
l---------pst.11
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/
diff --git a/cpy b/cpy
new file mode 100755
index 0000000..827d21c
--- /dev/null
+++ b/cpy
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+tee /tmp/cpy"$1"
diff --git a/cpy.1 b/cpy.1
new file mode 100644
index 0000000..3b23b8b
--- /dev/null
+++ b/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/ep b/ep
new file mode 100644
index 0000000..3fb8a0d
--- /dev/null
+++ b/ep
@@ -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
diff --git a/ord b/ord
new file mode 100755
index 0000000..2d0687f
--- /dev/null
+++ b/ord
@@ -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
diff --git a/ord.1 b/ord.1
new file mode 100644
index 0000000..9ab54a5
--- /dev/null
+++ b/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/pst b/pst
new file mode 100755
index 0000000..dd6bd64
--- /dev/null
+++ b/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/pst.1 b/pst.1
new file mode 120000
index 0000000..0ececb2
--- /dev/null
+++ b/pst.1
@@ -0,0 +1 @@
+cpy.1 \ No newline at end of file