diff options
| -rwxr-xr-x | bsgrep | 77 | ||||
| -rwxr-xr-x | termbin | 44 | ||||
| -rwxr-xr-x | tolatin | 8 |
3 files changed, 106 insertions, 23 deletions
@@ -22,7 +22,7 @@ $SIG{__WARN__} = sub { # from the 'while(<>)' or File::Find. if($m !~ /^$self:/) { $m = "$self: $m"; - $ret = 2 unless $opt{s}; + $ret = 2 unless $opt{q}; } print STDERR $m unless $opt{s}; @@ -315,22 +315,29 @@ select lines that match all of the patterns; the default is to select lines that match any of the patterns. This option doesn't exist in B<grep>. +=item -q + +Quiet: don't write to standard output. Exit status will be zero if +a match was found, even if there were errors. This doesn't prevent +warnings/errors being printed to standard error; use B<-s> to silence +those. Same as B<grep>. + =item -r Recursively read all files under each directory, following symlinks only if they're on the command line. If no files or directories are given, reads the current directory. Same as B<grep>. -=item -v - -Print only lines that do I<not> match (same as B<grep>). - =item -s Silence warnings (same as B<grep>). This includes error messages about unreadable files as well as warnings about the input (see B<DIAGNOSTICS>, below). +=item -v + +Print only lines that do I<not> match (same as B<grep>). + =back =head1 EXAMPLE @@ -409,7 +416,7 @@ to be Unicode, it will be assumed ISO-8859-1, and converted to Unicode. =head1 EXIT STATUS 0 if there were any matches, 1 if there were none, or 2 if there -were errors (e.g. nonexistent file). However, with B<-s>, the exit +were errors (e.g. nonexistent file). However, with B<-q>, the exit status will be 0 or 1 even if there were errors. This is the same as B<grep>'s exit status. @@ -445,3 +452,61 @@ under the WTFPL: Do WTF you want with this. B<grep>(1), B<perl>(1) =cut + +__END__ + +implemented: + --help + -V, --version + -F, --fixed-strings + -e PATTERNS, --regexp=PATTERNS + -i, --ignore-case + -v, --invert-match + -q, --quiet, --silent + -s, --no-messages + -n, --line-number + -z, --null-data + -r, --recursive + -l, --files-with-matches + +todo: + -f FILE, --file=FILE + -y Obsolete synonym for -i. + -c, --count + -R, --dereference-recursive + -L, --files-without-match + -Z, --null + -A NUM, --after-context=NUM + -B NUM, --before-context=NUM + -C NUM, -NUM, --context=NUM + -H, --with-filename + -h, --no-filename + -w, --word-regexp + -x, --line-regexp + +do not implement: + -E, --extended-regexp + -G, --basic-regexp + -P, --perl-regexp + --no-ignore-case + +undecided: + --color[=WHEN], --colour[=WHEN] + -m NUM, --max-count=NUM + -o, --only-matching + -b, --byte-offset + --label=LABEL + -T, --initial-tab + --group-separator=SEP + --no-group-separator + -a, --text + --binary-files=TYPE + -D ACTION, --devices=ACTION + -d ACTION, --directories=ACTION + --exclude=GLOB + --exclude-from=FILE + --exclude-dir=GLOB + -I + --include=GLOB + --line-buffered + -U, --binary @@ -1,16 +1,25 @@ -#!/bin/sh +#!/bin/bash + +VERSION="0.1.0" +SELF="$( basename $0 )" # 20200424 bkw: This used to be a one-line script: # cat "${1:--}" | nc termbin.com 9999 # ...but I really wanted the "copy link to X clipboard" feature. -if [ "$1" = "--help" ]; then +if [ "$1" = "--help" -o "$1" = "-h" ]; then cat <<EOF -Usage: $( basename $0 ) <filename> +termbin v$VERSION + +Usage: $SELF <filename> [<filename> ...] + +Uses nc (netcat) to paste stdin to termbin.com, or pastes one or more +files if <filename(s)> are given. Spits out paste URL on stdout. Also +copies URL to the X clipboard if X is running and either xsel or xclip +is installed. -Uses nc (NetCat) to paste stdin to termbin.com, or pastes a file if -<filename> is given. Spits out paste URL on stdout. Also copies URL to -the X clipboard if X is running and either xsel or xclip is installed. +Only one paste is created. If you give multiple filenames, they are +concatenated together. Written by B. Watson <urchlay@slackware.uk>, released under the WTFPL: do WTF you want with this. @@ -18,20 +27,21 @@ EOF exit 0 fi -if ! which nc &>/dev/null; then - echo "$( basename $0 ): can't find nc on path, install nc or netcat package" - exit 1 -fi +# 20251226 bkw: the sed is because termbin.com sends us e.g. +# https://termbin.com/XXXX\n\0 +# and we get "warning: ignoring null byte" from bash. +url="$( cat "${1:--}" | nc termbin.com 9999 | sed 's,\x00,,' )" -url="$( cat "${1:--}" | nc termbin.com 9999 )" -[ -z "$url" ] && exit "$?" +# 20251227 bkw: don't print an error message if nc fails (nc will print +# its own, or the shell will if it's "command not found"). +err="$?" +[ -z "$url" ] && exit "$err" echo "$url" if [ -n "$DISPLAY" ]; then - if which xsel &>/dev/null; then - echo -n "$url" | xsel -i - elif which xclip &>/dev/null; then - echo -n "$url" | xclip - fi + echo -n "$url" | xsel -i >/dev/null 2>&1 || \ + echo -n "$url" | xclip >/dev/null 2>&1 fi + +exit 0 @@ -0,0 +1,8 @@ +#!/bin/sh + +case "$@" in + -u) PIPE="| unaccent utf8" ;; + *) ;; +esac + +eval exec uconv -x Any-Latin $PIPE |
