aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-10-14 17:28:28 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-10-14 17:28:28 +1300
commitdd2171f0491e8e723b9f3e658d484ec9eece1d2d (patch)
tree9986013a5e2b4884167111f0ed74669ba73b5c28
parentRemove unneeded quotes from br(1df) man page (diff)
downloaddotfiles-dd2171f0491e8e723b9f3e658d484ec9eece1d2d.tar.gz
dotfiles-dd2171f0491e8e723b9f3e658d484ec9eece1d2d.zip
Add ap(1df) and bp(1df)
-rw-r--r--README.markdown3
-rwxr-xr-xbin/ap34
-rwxr-xr-xbin/bp3
-rw-r--r--man/man1/ap.1df14
-rw-r--r--man/man1/bp.1df17
-rw-r--r--man/man1/br.1df2
6 files changed, 72 insertions, 1 deletions
diff --git a/README.markdown b/README.markdown
index 66864981..182269a5 100644
--- a/README.markdown
+++ b/README.markdown
@@ -399,12 +399,15 @@ Installed by the `install-bin` target:
* `med(1df)` prints the median.
* `mode(1df)` prints the first encountered mode.
* `tot(1df)` totals the set.
+* `ap(1df)` reads arguments for a given command from the standard input,
+ prompting if appropriate
* `apf(1df)` prepends arguments to a command with ones read from a file,
intended as a framework for shell wrappers or functions.
* `ax(1df)` evaluates an awk expression given on the command line; this is
intended as a quick way to test how Awk would interpret a given expression.
* `bel(1df)` prints a terminal bell character.
* `bl(1df)` generates a given number of blank lines.
+* `bp(1df)` runs `br(1df)` after prompting for an URL
* `br(1df)` launches `$BROWSER`, or a more suitable application for an URL if
it knows of one.
* `ca(1df)` prints a count of its given arguments.
diff --git a/bin/ap b/bin/ap
new file mode 100755
index 00000000..b6ee36d4
--- /dev/null
+++ b/bin/ap
@@ -0,0 +1,34 @@
+#!/bin/sh
+# Run a program with args read from standard input, prompted if from term
+if [ "$#" -eq 0 ] ; then
+ printf >&2 'ap: Need at least one argument (command name)\n'
+ exit 2
+fi
+
+# Get the command name and shift it off
+cmd=$1
+shift
+
+# Iterate through the remaining args; it's legal for there to be none, but in
+# that case the user may as well just have invoked the command directly
+for arg ; do
+
+ # If this is the first iteration, clear the params away (we grabbed them in
+ # the for statement)
+ if [ -z "$reset" ] ; then
+ set --
+ reset=1
+ fi
+
+ # If stdin is a terminal, prompt with the name of the argument
+ if [ -t 0 ] ; then
+ printf '%s: ' "$arg"
+ fi
+
+ # Note that a whitespace or even empty argument is allowed
+ IFS= read -r val
+ set -- "$@" "$val"
+done
+
+# Execute the command with the given parameters
+exec "$cmd" "$@"
diff --git a/bin/bp b/bin/bp
new file mode 100755
index 00000000..6b78fbbc
--- /dev/null
+++ b/bin/bp
@@ -0,0 +1,3 @@
+#!/bin/sh
+# Read an URL and then browse to it, saving the annoyance of quoting URLs
+ap br URL
diff --git a/man/man1/ap.1df b/man/man1/ap.1df
new file mode 100644
index 00000000..bcbc4ce0
--- /dev/null
+++ b/man/man1/ap.1df
@@ -0,0 +1,14 @@
+.TH AP 1df "October 2016" "Manual page for ap"
+.SH NAME
+.B ap
+\- read named arguments from stdin with prompts
+.SH SYNOPSIS
+.B ap PROGRAM ARGNAME1 [ARGNAME2...]
+.SH DESCRIPTION
+.B ap
+runs a program with arguments read from stdin, with an appropriate prompt if
+stdin is a terminal.
+.SH SEE ALSO
+bp(1df), xargs(1)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/bp.1df b/man/man1/bp.1df
new file mode 100644
index 00000000..49f9de0c
--- /dev/null
+++ b/man/man1/bp.1df
@@ -0,0 +1,17 @@
+.TH BP 1df "October 2016" "Manual page for bp"
+.SH NAME
+.B bp
+\- launch $BROWSER with an URL read from stdin
+.SH SYNOPSIS
+.B bp
+BROWSER=firefox
+.B bp
+.SH DESCRIPTION
+.B bp
+reads an URL from stdin, with an "URL:" prompt if stdin is a terminal, and runs
+br(1df) against it. It was written because the author hates quoting URLs on the
+command line.
+.SH SEE ALSO
+br(1df), ap(1df)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/br.1df b/man/man1/br.1df
index f007e278..af9645fb 100644
--- a/man/man1/br.1df
+++ b/man/man1/br.1df
@@ -18,6 +18,6 @@ arguments. That's it.
It was written to have a clean way to launch $BROWSER from ~/.xbindkeysrc. It
has no other reason to exist.
.SH SEE ALSO
-xgo(1df), xgoc(1df)
+bp(1df), xgo(1df), xgoc(1df)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>