Updated all scripts to have usage strings. Adjusted a couple scripts while I was there.

This commit is contained in:
Olivier Poirier 2023-09-28 23:23:26 -07:00
parent 4717ca39e4
commit 1f776e9acf
31 changed files with 140 additions and 38 deletions

View File

@ -1,11 +1,14 @@
#!/bin/sh
# If the first argument is a valid command, executes it with the supplied arguments. If not, executes cat.
NAME="$(filename $0)"
USAGE="Usage: $NAME [command] [args ...]"
if usage "$1" "$USAGE" ; then exit ; fi
if [ "$1" != "" ] ; then
type "$1" 2>/dev/null 1>/dev/null
if [ "$?" = "0" ] ; then
$@
else
echo "$(readpipe)" | cat
exit
fi
else
echo "$(readpipe)" | cat
fi
echo "$(readpipe)" | cat

View File

@ -1,3 +1,8 @@
#!/bin/sh
# echoes the parent PID, then runs cat.
NAME="$(filename $0)"
USAGE="Usage: $NAME"
if usage "$1" "$USAGE" ; then exit ; fi
echo $$
cat

View File

@ -3,8 +3,9 @@
# Requires: <program> <package (Devuan)>
# echo coreutils
USAGE='Usage: <command, args...> | linedo'
#if usage "$1" "$USAGE" ; then exit ; fi
NAME="$(filename $0)"
USAGE="Usage: <command, args...> | $NAME"
if usage "$1" "$USAGE" ; then exit ; fi
IFS='
'

View File

@ -1,4 +1,10 @@
#!/bin/sh
# If the first argument is a valid command, executes it with the supplied arguments. If not, executes cat.
NAME="$(filename $0)"
USAGE="Usage: $NAME [command, args...]"
if usage "$1" "$USAGE" ; then exit ; fi
if [ "$1" != "" ] ; then
type "$1" 2>/dev/null 1>/dev/null
if [ "$?" = "0" ] ; then

View File

@ -5,6 +5,9 @@
# It uses the script 'tmpfifo' to create FIFOs.
# Modify tmpfifo or replace it to change default location and naming convention.
NAME="$(filename $0)"
USAGE="Usage: $NAME [command, args...]"
if usage "$1" "$USAGE" ; then exit ; fi
Fifork () {
TMPFIFO="$1"

View File

@ -1,4 +1,12 @@
#!/bin/sh
# Cuts the name of a single file or list of files out from its path and echoes it.
# Otherwise, does nothing.
IFS='/'
NAME="$(lastarg $0)"
USAGE="Usage: $NAME [filenames...]"
if usage "$1" "$USAGE" ; then exit ; fi
for item in "$@" ; do
echo "$(lastarg $item)"
done

View File

@ -1,7 +1,9 @@
#!/bin/sh
# Takes the first argument, injects it in the nth position and runs the result. If the argument or position is not available, returns 1.
USAGE="Usage: nthargdo [arg] [position] <command> [args ...]"
NAME="$(filename $0)"
USAGE="Usage: $NAME [arg] [position] <command> [args ...]"
if usage "$1" "$USAGE" ; then exit ; fi
IFS='
'

View File

@ -1,11 +1,12 @@
#!/bin/sh
# Takes the first argument and pipes it into a command.
# Takes the first n arguments and pipes it into a command.
# Requires: <program> <package (Devuan)>
# cat coreutils
# echo coreutils
NAME="$(filename $0)"
USAGE="Usage: $NAME <number of args to pipe> <args...> [command, args...]"
if usage "$1" "$USAGE" ; then exit ; fi
if isnum "$1" ; then
POSITION="$1"

View File

@ -4,7 +4,9 @@
# cat coreutils
# echo coreutils
USAGE='Usage: <argument to pipe> [command, args...]'
NAME="$(filename $0)"
USAGE="Usage: $NAME <argument to pipe> [command, args...]"
if usage "$1" "$USAGE" ; then exit ; fi
IFS='
'

View File

@ -1,4 +1,9 @@
#!/bin/sh
# Echoes the exit code for an arbitrary command.
# Echoes the exit code for an arbitrary command, otherwise returns 0.
NAME="$(filename $0)"
USAGE="Usage: $NAME [command]"
if usage "$1" "$USAGE" ; then exit ; fi
$@
echo "$?"

View File

@ -1,5 +1,10 @@
#!/bin/sh
# Inverts the return status of whatever just ran.
# Inverts the return status of whatever just ran, or echoes the string and returns 1. Pure eeeevillll.
NAME="$(filename $0)"
USAGE="Usage: $NAME [command, args]"
if usage "$1" "$USAGE" ; then exit ; fi
echoordo "$@"
if [ "$?" = "0" ] ; then
exit 1

View File

@ -5,7 +5,9 @@
# See: https://unix.stackexchange.com/questions/598036/
# Why doesn't test have a check like this..?
#if usage "$1" 'Usage: isnum <number>' ; then exit ; fi
NAME="$(filename $0)"
USAGE="Usage: $NAME [number]"
if usage "$1" "$USAGE" ; then exit ; fi
case "${1#[+-]}" in
(*[!0123456789]*) return 1 ;;

View File

@ -1,8 +1,11 @@
#!/bin/sh
# Kills something and executes a command.
# Attempts to kill the PID in the first argument and execute a command, otherwise does nothing.
NAME="$(filename $0)"
USAGE="Usage: $NAME [pid] [command, args...]"
if usage "$1" "$USAGE" ; then exit ; fi
if [ "$1" != "" ] ; then
if isnum $1 ; then
kill "$1"
if [ "$2" != "" ] ; then
shift

View File

@ -1,3 +1,9 @@
#!/bin/sh
# Returns the last argument.
NAME="$(filename $0)"
USAGE="Usage: $NAME [args...]"
if usage "$1" "$USAGE" ; then exit ; fi
for last in "$@" ; do :; done
echo "$last"

View File

@ -1,10 +1,12 @@
#!/bin/sh
# Takes the first argument and pipes it into a command.
# Takes the last argument and pipes it into a command.
# Requires: <program> <package (Devuan)>
# cat coreutils
# echo coreutils
USAGE='Usage: [command, args...] <argument to pipe>'
NAME="$(filename $0)"
USAGE="Usage: $NAME [command, args...] <argument to pipe>"
if usage "$1" "$USAGE" ; then exit ; fi
PIPEARG="$(lastarg $@)"
if [ ! "$PIPEARG" = "" ] ; then

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Runs multiple instances of a program with single arguments passed in.
# Runs multiple instances of a program with single arguments passed in as the first argument.
# Requires: <program> <package (Devuan)>
# seq coreutils
# echo coreutils

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Runs multiple instances of a program with single arguments passed in.
# Runs multiple instances of a program with single arguments passed in as the last argument.
# Requires: <program> <package (Devuan)>
# seq coreutils
# echo coreutils

View File

@ -6,7 +6,6 @@
NAME="$(filename $0)"
USAGE="Usage: <check strings> | $NAME [match string] [command] [args...]"
if usage "$1" "$USAGE" ; then exit ; fi
if [ "$1" != "" ] ; then

View File

@ -4,7 +4,9 @@
# notify-send libnotify-bin
# sed sed
if usage "$1" 'Usage: [command] | lnotify [notify-send arguments]' ; then exit ; fi
NAME="$(filename $0)"
USAGE="Usage: [command] | $NAME [notify-send arguments]"
if usage "$1" "$USAGE" ; then exit ; fi
if [ "$LNOTIFY_PLAYER" = "" ] ; then
LNOTIFY_PLAYER="openmpt123"

View File

@ -5,7 +5,9 @@
# echo coreutils
# cat coreutils
if usage "$1" 'Usage: lparg [command]' ; then exit ; fi
NAME="$(filename $0)"
USAGE="Usage: $NAME [command, args...]"
if usage "$1" "$USAGE" ; then exit ; fi
ARGS="$@"

View File

@ -1,7 +1,10 @@
#!/bin/sh
# This lets you rotate items in the argument list by n, and also summons the Antichrist.
# This lets you rotate items in the argument list left by n, and also summons the Antichrist.
NAME="$(filename $0)"
USAGE="Usage: $NAME <number> <args ...>"
if usage "$1" "$USAGE" ; then exit ; fi
USAGE="Usage: lrotate <number> <args ...>"
if isnum "$1" ; then
if [ $# -gt 2 ] ; then
TIMES="$1"

View File

@ -1,7 +1,9 @@
#!/bin/sh
# This lets you shift items in the argument list to the right by n.
USAGE="Usage: lshift <number> <args ...>"
NAME="$(filename $0)"
USAGE="Usage: $NAME <number> <args ...>"
if usage "$1" "$USAGE" ; then exit ; fi
if isnum "$1" ; then
if [ $# -gt 2 ] ; then

View File

@ -1,4 +1,11 @@
#!/bin/sh
# Spawns a process over and over, each listening to a single FIFO until the process sending data to the FIFO dies.
# Only spawns a certain amount of these processes at a time, determined by the set limit.
# This thing is a monstrosity and I desperately need to simplify it if I can.
NAME="$(filename $0)"
USAGE="Usage: $NAME [max threads] <command> [args...]"
if usage "$1" "$USAGE" ; then exit ; fi
THREAD_LIMIT="$1"
@ -6,7 +13,7 @@ if ! isnum "$DEFAULT_THREAD_LIMIT" ; then
DEFAULT_THREAD_LIMIT="$(nproc)"
fi
if ! isnum "$LIMIT" ; then
if ! isnum "$THREAD_LIMIT" ; then
THREAD_LIMIT="$DEFAULT_THREAD_LIMIT"
else
shift

View File

@ -1,10 +1,18 @@
#!/bin/sh
ARGS="$@"
COUNT="$#"
set --
for arg in $ARGS ; do
if [ "$#" -lt "$(( COUNT - 1 ))" ] ; then
set -- $@ $arg
fi
done
echo "$@"
# Returns everything except the last argument, otherwise does nothing.
NAME="$(filename $0)"
USAGE="Usage: $NAME [args...]"
if usage "$1" "$USAGE" ; then exit ; fi
if [ "#$" != "0" ] ; then
ARGS="$@"
COUNT="$#"
set --
for arg in $ARGS ; do
if [ "$#" -lt "$(( COUNT - 1 ))" ] ; then
set -- $@ $arg
fi
done
echo "$@"
fi

View File

@ -7,6 +7,10 @@
# grep grep
# sed sed
NAME="$(filename $0)"
USAGE="Usage: $NAME"
if usage "$1" "$USAGE" ; then exit ; fi
IFS='
'
if [ "$LNOTIFY_ICON" = "" ] ; then LNOTIFY_ICON="/usr/share/icons/ouro/attention.png" ; fi

View File

@ -1,9 +1,13 @@
#!/bin/sh
# Reads with no timeout in a POSIX-friendly way.
# Reads with no timeout in a POSIX-friendly way, but only once.
# Good for getting data from a pipe without user intervention.
# Requires: <program> <package (Devuan)>
# echo coreutils
NAME="$(filename $0)"
USAGE="Usage: $NAME"
if usage "$1" "$USAGE" ; then exit ; fi
if [ ! -t 0 ] ; then
read LINE
while [ "$?" = "0" ] ; do

View File

@ -4,6 +4,10 @@
# Requires: <program> <package (Devuan)>
# echo coreutils
NAME="$(filename $0)"
USAGE="Usage: $NAME"
if usage "$1" "$USAGE" ; then exit ; fi
if [ ! -t 0 ] ; then
read LINE
if [ "$?" = "0" ] ; then

View File

@ -2,7 +2,8 @@
# This lets you rotate items in the argument list right by n, and also summons the Antichrist.
NAME="$(filename $0)"
USAGE="Usage: rrotate <number> <args ...>"
USAGE="Usage: $NAME <number> <args ...>"
if usage "$1" "$USAGE" ; then exit ; fi
if isnum "$1" ; then
if [ $# -gt 2 ] ; then

View File

@ -1,7 +1,9 @@
#!/bin/sh
# This lets you shift items in the argument list to the right by n.
USAGE="Usage: rshift <number> <args ...>"
NAME="$(filename $0)"
USAGE="Usage: $NAME <number> <args ...>"
if usage "$1" "$USAGE" ; then exit ; fi
if isnum "$1" ; then
if [ $# -gt 2 ] ; then

View File

@ -1,5 +1,10 @@
#!/bin/sh
# Sets the exit code to the first argument if the first argument is a number.
# Sets the exit code to the first argument if the first argument is a number, otherwise, does nothing.
NAME="$(filename $0)"
USAGE="Usage: $NAME <number>"
if usage "$1" "$USAGE" ; then exit ; fi
if isnum "$1" ; then
exit $1
fi

View File

@ -1,10 +1,15 @@
#!/bin/sh
# Creates a fifo named after the first argument.
NAME="$(filename $0)"
USAGE="Usage: $NAME [name]"
if usage "$1" "$USAGE" ; then exit ; fi
FIFODIR="/tmp/fifo"
mkdir -p "$FIFODIR"
if [ $? != "0" ] ; then
echo "Couldn't make FIFO directory: $FIFODIR" >&2
echo "$USAGE"
else
if [ "$1" = "" ] ; then
NAME="fifo"