Added vim swapfiles to gitignore. Made usage work. Renamed lots of scripts to a standard format and added a whole bunch of new ones. Need to switch from status codes to signals soon(tm), laid the framework for that.
This commit is contained in:
parent
27b6d27703
commit
809fa91a8b
|
@ -1 +1,2 @@
|
|||
.wip/
|
||||
*.sw*
|
||||
|
|
2
install
2
install
|
@ -10,7 +10,7 @@ if type sed && type find ; then
|
|||
fi
|
||||
|
||||
for file in $(find ./ -not -path '*/.*' -path './*/*' -type f -perm 755) ; do
|
||||
cp "$file" "$DESTDIR$PREFIX/bin/$(echo $file | sed 's/.*\///')"
|
||||
cp -v "$file" "$DESTDIR$PREFIX/bin/$(echo $file | sed 's/.*\///')"
|
||||
done
|
||||
else
|
||||
echo "Please install find and sed." >&2
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# If the first argument is a valid command, executes it with the supplied arguments. If not, executes cat.
|
||||
if [ "$1" != "" ] ; then
|
||||
type "$1" 2>/dev/null 1>/dev/null
|
||||
if [ "$?" = "0" ] ; then
|
||||
$@
|
||||
else
|
||||
echo "$(readpipe)" | cat
|
||||
fi
|
||||
else
|
||||
echo "$(readpipe)" | cat
|
||||
fi
|
|
@ -0,0 +1,24 @@
|
|||
#!/bin/sh
|
||||
# Runs each piped line as a command.
|
||||
# Requires: <program> <package (Devuan)>
|
||||
# echo coreutils
|
||||
|
||||
USAGE='Usage: <command, args...> | linedo'
|
||||
#if usage "$1" "$USAGE" ; then exit ; fi
|
||||
|
||||
IFS='
|
||||
'
|
||||
ARGS="$(readpipe)"
|
||||
|
||||
if [ "$?" = "0" ] ; then
|
||||
for item in $ARGS ; do
|
||||
if [ "$item" != "" ] ; then
|
||||
catordo "$item"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "Nothing piped in." >&2
|
||||
echo $USAGE
|
||||
fi
|
||||
exit 1
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# If the first argument is a valid command, executes it with the supplied arguments. If not, executes cat.
|
||||
if [ "$1" != "" ] ; then
|
||||
type "$1" 2>/dev/null 1>/dev/null
|
||||
if [ "$?" = "0" ] ; then
|
||||
$@
|
||||
else
|
||||
echo "$@"
|
||||
fi
|
||||
fi
|
|
@ -0,0 +1,4 @@
|
|||
IFS='/'
|
||||
for item in "$@" ; do
|
||||
echo "$(lastarg $item)"
|
||||
done
|
|
@ -0,0 +1,34 @@
|
|||
#!/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 ...]"
|
||||
|
||||
IFS='
|
||||
'
|
||||
|
||||
if [ "$1" != "" ] && [ "$#" -gt 2 ] ; then
|
||||
if [ "$2" -le $(( $# - 1 )) ] ; then
|
||||
ARGUMENT="$1"
|
||||
shift
|
||||
POSITION="$1"
|
||||
shift
|
||||
if [ "$POSITION" -gt "$#" ] ; then
|
||||
set -- $@ $ARGUMENT
|
||||
else
|
||||
for position in $(seq "$#") ; do
|
||||
if [ "$position" = "$POSITION" ] ; then
|
||||
set -- $@ $ARGUMENT
|
||||
fi
|
||||
set -- $@ $1
|
||||
shift
|
||||
done
|
||||
fi
|
||||
"$@"
|
||||
else
|
||||
echo "Invalid argument position." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
||||
else
|
||||
echo "Not enough arguments." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/sh
|
||||
# Takes the first argument 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 isnum "$1" ; then
|
||||
POSITION="$1"
|
||||
shift
|
||||
if [ "$POSITION" -le "$#" ] ; then
|
||||
COMMAND="$(lshift $POSITION $@)"
|
||||
ARGS="$(rshift $(( $# - $POSITION )) $@)"
|
||||
echo "$ARGS" | $COMMAND
|
||||
else
|
||||
echo "Invalid position specified." >&2
|
||||
echo "$USAGE"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "First argument is not a number." >&2
|
||||
echo "$USAGE"
|
||||
exit 1
|
||||
fi
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
# Takes the first argument and pipes it into a command.
|
||||
# Requires: <program> <package (Devuan)>
|
||||
# cat coreutils
|
||||
# echo coreutils
|
||||
|
||||
USAGE='Usage: <argument to pipe> [command, args...]'
|
||||
|
||||
IFS='
|
||||
'
|
||||
echo "fp $# $@"
|
||||
|
||||
if [ ! "$1" = "" ] ; then
|
||||
PIPEARG="$1"
|
||||
shift
|
||||
echo "$PIPEARG" | catordo "$@"
|
||||
else
|
||||
echo "Nothing to pipe." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
# Echoes the exit code for an arbitrary command.
|
||||
$@
|
||||
echo "$?"
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
# Inverts the return status of whatever just ran.
|
||||
echoordo "$@"
|
||||
if [ "$?" = "0" ] ; then
|
||||
exit 1
|
||||
else
|
||||
exit 0
|
||||
fi
|
|
@ -5,7 +5,7 @@
|
|||
# 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
|
||||
#if usage "$1" 'Usage: isnum <number>' ; then exit ; fi
|
||||
|
||||
case "${1#[+-]}" in
|
||||
(*[!0123456789]*) return 1 ;;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/sh
|
||||
# Kills something and returns 1.
|
||||
|
||||
|
||||
if [ "$1" != "" ] ; then
|
||||
kill "$1"
|
||||
if [ "$2" != "" ] ; then
|
||||
shift
|
||||
if type "$1" 1>/dev/null 2>/dev/null ; then
|
||||
"$@"
|
||||
else
|
||||
echo "$@"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
exit 1
|
|
@ -1,26 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Runs a command if it receives a specific string, otherwise returns 1.
|
||||
# Command run defaults to cat.
|
||||
# Requires: <program> <package (Devuan)>
|
||||
# echo coreutils
|
||||
|
||||
if usage "$1" 'Usage: <command> | largcmd [match string] [command] [args...]' ; then exit ; fi
|
||||
|
||||
ARGS="$@"
|
||||
|
||||
if [ "$ARGS" = "" ] ; then
|
||||
set -- "cat"
|
||||
fi
|
||||
|
||||
ARG="$1"
|
||||
shift
|
||||
CMD="$1"
|
||||
shift
|
||||
|
||||
for item in "$@" ; do
|
||||
if [ "$item" = "$ARG" ] ; then
|
||||
read STRING ; echo "$STRING" | "$CMD"
|
||||
exit
|
||||
fi
|
||||
done
|
||||
exit 1
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/sh
|
||||
# Takes the first argument and pipes it into a command.
|
||||
# Requires: <program> <package (Devuan)>
|
||||
# cat coreutils
|
||||
# echo coreutils
|
||||
|
||||
USAGE='Usage: [command, args...] <argument to pipe>'
|
||||
|
||||
PIPEARG="$(lastarg $@)"
|
||||
if [ ! "$PIPEARG" = "" ] ; then
|
||||
set -- $(nolastarg $@)
|
||||
echo "$PIPEARG" | catordo "$@"
|
||||
else
|
||||
echo "Nothing to pipe." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
# Runs multiple instances of a program with single arguments passed in.
|
||||
# Requires: <program> <package (Devuan)>
|
||||
# seq coreutils
|
||||
# echo coreutils
|
||||
|
||||
NAME="$(filename $0)"
|
||||
USAGE="Usage: <singular args...> | $NAME <command> [args...]"
|
||||
if usage "$1" "$USAGE" ; then exit ; fi
|
||||
|
||||
#IFS='
|
||||
#'
|
||||
|
||||
|
||||
CMD="$1"
|
||||
if [ "$1" = "" ] ; then
|
||||
CMD="echo"
|
||||
set --
|
||||
else
|
||||
if [ "$2" != "" ] ; then shift ; else set -- ; fi
|
||||
fi
|
||||
|
||||
|
||||
ARGS="$(readpipeonce)"
|
||||
while [ "$?" = "0" ] ; do
|
||||
echoordo "$CMD" "$ARGS" "$@"
|
||||
if [ "$?" != "0" ] ; then exit ; fi
|
||||
ARGS="$(readpipeonce)"
|
||||
done
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh
|
||||
# Runs multiple instances of a program with single arguments passed in.
|
||||
# Requires: <program> <package (Devuan)>
|
||||
# seq coreutils
|
||||
# echo coreutils
|
||||
|
||||
NAME="$(filename $0)"
|
||||
USAGE="Usage: <singular args...> | $NAME <command> [args...]"
|
||||
if usage "$1" "$USAGE" ; then exit ; fi
|
||||
|
||||
#IFS='
|
||||
#'
|
||||
|
||||
|
||||
ARGS="$(readpipeonce)"
|
||||
while [ "$?" = "0" ] ; do
|
||||
if [ "$ARGS" != "" ] ; then
|
||||
echoordo "$@" "$ARGS"
|
||||
fi
|
||||
ARGS="$(readpipeonce)"
|
||||
done
|
|
@ -0,0 +1,25 @@
|
|||
#!/bin/sh
|
||||
# Runs a command if it receives a specific string, otherwise returns 1.
|
||||
# Command run defaults to cat.
|
||||
# Requires: <program> <package (Devuan)>
|
||||
# echo coreutils
|
||||
|
||||
NAME="$(filename $0)"
|
||||
USAGE="Usage: <check strings> | $NAME [match string] [command] [args...]"
|
||||
|
||||
if usage "$1" "$USAGE" ; then exit ; fi
|
||||
|
||||
if [ "$1" != "" ] ; then
|
||||
ARG="$1"
|
||||
if [ "$2" != "" ] ; then shift ; fi
|
||||
for item in $(readpipe) ; do
|
||||
if [ "$item" = "$ARG" ] ; then
|
||||
catordo "$@"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "No match string supplied." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
||||
exit 1
|
|
@ -0,0 +1,23 @@
|
|||
#!/bin/sh
|
||||
# This lets you rotate items in the argument list by n, and also summons the Antichrist.
|
||||
|
||||
USAGE="Usage: lrotate <number> <args ...>"
|
||||
if isnum "$1" ; then
|
||||
if [ $# -gt 2 ] ; then
|
||||
TIMES="$1"
|
||||
shift
|
||||
for time in $(seq $TIMES) ; do
|
||||
set -- "$@" "$1"
|
||||
shift
|
||||
done
|
||||
echo "$@"
|
||||
exit 0
|
||||
else
|
||||
echo "No arguments to rotate." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
||||
else
|
||||
echo "Missing or invalid rotation number." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
||||
exit 1
|
|
@ -1,30 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Runs multiple instances of a program with single arguments passed in.
|
||||
# Requires: <program> <package (Devuan)>
|
||||
# seq coreutils
|
||||
# echo coreutils
|
||||
|
||||
USAGE='Usage: lseqcmd <number of singular args> <singular args...> <command> [args...]'
|
||||
if usage "$1" "$USAGE" ; then exit ; fi
|
||||
|
||||
|
||||
FLAGS="$1"
|
||||
ARGS="$@"
|
||||
if isnum $FLAGS ; then
|
||||
for item in $(seq $FLAGS) ; do
|
||||
shift $item
|
||||
ITEM=$1
|
||||
shift $(($FLAGS-$item+1))
|
||||
CMD=$1
|
||||
shift
|
||||
if "$CMD" "$ITEM" "$@" ; then
|
||||
exit
|
||||
fi
|
||||
set -- $ARGS
|
||||
done
|
||||
else
|
||||
echo "Invalid number of options." >&2
|
||||
echo $USAGE
|
||||
fi
|
||||
exit 1
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh
|
||||
# This lets you shift items in the argument list to the right by n.
|
||||
|
||||
USAGE="Usage: lshift <number> <args ...>"
|
||||
|
||||
if isnum "$1" ; then
|
||||
if [ $# -gt 2 ] ; then
|
||||
TIMES="$1"
|
||||
shift
|
||||
shift $TIMES
|
||||
echo "$@"
|
||||
exit 0
|
||||
else
|
||||
echo "No arguments to shift." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
||||
else
|
||||
echo "Missing or invalid shift number." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
||||
exit 1
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
# Reads with no timeout in a POSIX-friendly way.
|
||||
# Good for getting data from a pipe without user intervention.
|
||||
# Requires: <program> <package (Devuan)>
|
||||
# echo coreutils
|
||||
|
||||
if [ ! -t 0 ] ; then
|
||||
read LINE
|
||||
while [ "$?" = "0" ] ; do
|
||||
echo $LINE
|
||||
read LINE
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/sh
|
||||
# Reads with no timeout in a POSIX-friendly way.
|
||||
# Good for getting data from a pipe without user intervention.
|
||||
# Requires: <program> <package (Devuan)>
|
||||
# echo coreutils
|
||||
|
||||
if [ ! -t 0 ] ; then
|
||||
read LINE
|
||||
if [ "$?" = "0" ] ; then
|
||||
echo $LINE
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
exit 1
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh
|
||||
# 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 ...>"
|
||||
|
||||
if isnum "$1" ; then
|
||||
if [ $# -gt 2 ] ; then
|
||||
TIMES="$1"
|
||||
shift
|
||||
lrotate "$(( (($#-1) * $TIMES) % $# ))" "$@"
|
||||
exit 0
|
||||
else
|
||||
echo "No arguments to rotate." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
||||
else
|
||||
echo "Missing or invalid rotation number." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
||||
exit 1
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
# This lets you shift items in the argument list to the right by n.
|
||||
|
||||
USAGE="Usage: rshift <number> <args ...>"
|
||||
|
||||
if isnum "$1" ; then
|
||||
if [ $# -gt 2 ] ; then
|
||||
TIMES="$1"
|
||||
shift
|
||||
set -- $(lrotate $(( $# - $TIMES )) "$@")
|
||||
shift $TIMES
|
||||
echo "$@"
|
||||
exit 0
|
||||
else
|
||||
echo "No arguments to shift." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
||||
else
|
||||
echo "Missing or invalid rotation number." >&2
|
||||
echo "$USAGE"
|
||||
fi
|
||||
exit 1
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
# Sets the exit code to the first argument if the first argument is a number.
|
||||
if isnum "$1" ; then
|
||||
exit $1
|
||||
fi
|
|
@ -0,0 +1,45 @@
|
|||
#!/bin/sh
|
||||
# Generates a signal if a command returns exit code 0.
|
||||
# Defaults are parent process, SIGUSR1, and 'setcode 1'.
|
||||
|
||||
NAME="$(filename $0)"
|
||||
USAGE="Usage: $NAME [PID] [signal number] <command> [args...]"
|
||||
if usage "$1" "$USAGE" ; then exit ; fi
|
||||
|
||||
DEFAULT_PID="$$"
|
||||
DEFAULT_SIGNAL="10"
|
||||
|
||||
if which $1 >/dev/null ; then
|
||||
PID="$DEFAULT_PID"
|
||||
SIGNAL="$DEFAULT_SIGNAL"
|
||||
elif which $2 >/dev/null ; then
|
||||
if isnum "$1" ; then
|
||||
PID="$1"
|
||||
else
|
||||
PID="$DEFAULT_PID"
|
||||
fi
|
||||
SIGNAL="$DEFAULT_SIGNAL"
|
||||
set -- $(lshift 1 "$@")
|
||||
elif which $3 >/dev/null ; then
|
||||
if isnum "$1" ; then
|
||||
PID="$1"
|
||||
else
|
||||
PID="$DEFAULT_PID"
|
||||
fi
|
||||
if isnum "$2" ; then
|
||||
SIGNAL="$2"
|
||||
else
|
||||
SIGNAL="$DEFAULT_SIGNAL"
|
||||
fi
|
||||
set -- $(lshift 2 "$@")
|
||||
else
|
||||
echo "Can't find a valid command." >&2
|
||||
echo "$USAGE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if $@ ; then
|
||||
kill -s "$SIGNAL" "$PID"
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/sh
|
||||
# Generates a signal depending on the status of the previous command.
|
||||
# Default status to signal on is 0.
|
||||
# Ignores everything after the 2nd argument, and ignores the 3rd argument if it's not a number.
|
||||
|
||||
NAME="$(filename $0)"
|
||||
USAGE="Usage: $NAME [PID] [signal number] [exit code] <command> [args...]"
|
||||
if usage "$1" "$USAGE" ; then exit ; fi
|
||||
|
||||
DEFAULT_PID="$$"
|
||||
DEFAULT_SIGNAL="10"
|
||||
DEFAULT_CODE="0"
|
||||
|
||||
if which $1 >/dev/null ; then
|
||||
CODE="$DEFAULT_CODE"
|
||||
set -- "$DEFAULT_PID" "$DEFAULT_SIGNAL" "$@"
|
||||
elif which $2 >/dev/null ; then
|
||||
CODE="$DEFAULT_CODE"
|
||||
set -- "$1" "$DEFAULT_SIGNAL" $(lshift 1 "$@")
|
||||
elif which $3 >/dev/null ; then
|
||||
CODE="$DEFAULT_CODE"
|
||||
set -- "$1" "$2" "$@"
|
||||
elif which $4 >/dev/null ; then
|
||||
if isnum "%3" ; then
|
||||
CODE="$3"
|
||||
else
|
||||
CODE="$DEFAULT_CODE"
|
||||
fi
|
||||
set -- "$1" "$2" $(lshift 3 "$@")
|
||||
else
|
||||
echo "Can't find a valid command." >&2
|
||||
echo "$USAGE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$(lshift 2 "$@")
|
||||
sigcondition "$1" "$2" test "$?" -eq "$CODE"
|
|
@ -4,7 +4,8 @@
|
|||
# Requires: <program> <package (Devuan)>
|
||||
# tail coreutils
|
||||
|
||||
USAGE='Usage: [notify-send args...] | track <filename> [command] [args...]'
|
||||
NAME="$(filename $0)"
|
||||
USAGE="Usage: [notify-send args...] | $NAME <filename> [command] [args...]"
|
||||
if usage "$1" "$USAGE" ; then exit ; fi
|
||||
|
||||
if [ "$1" != "" ] ; then
|
||||
|
@ -12,11 +13,12 @@ if [ "$1" != "" ] ; then
|
|||
shift
|
||||
ARGS="${@}"
|
||||
if [ "$ARGS" = "" ] ; then
|
||||
set -- "cat"
|
||||
set -- "echo"
|
||||
fi
|
||||
FILENAME="$(echo $FILE | sed 's/.*\///')"
|
||||
LNOTIFY_ARGS="$(lparg)"
|
||||
tail -Fn 0 "$FILE" 2>/dev/null | lparg "${@}" | lnotify $LNOTIFY_ARGS "$FILENAME"
|
||||
LNOTIFY_ARGS="$(readpipe)"
|
||||
echo tail -Fn 0 "$FILE" '2>/dev/null' '|' linefirstargdo "${@}" '|' linenotify $LNOTIFY_ARGS "$FILENAME"
|
||||
tail -Fn 0 "$FILE" 2>/dev/null | linefirstargdo "$@" #| cat #linenotify $LNOTIFY_ARGS "$FILENAME"
|
||||
else
|
||||
echo "No filename supplied." >&2
|
||||
echo "$USAGE"
|
||||
|
|
|
@ -3,15 +3,22 @@
|
|||
# Requires: <program> <package (Devuan)>
|
||||
# echo coreutils
|
||||
|
||||
NAME="$(filename $0)"
|
||||
IFS='
|
||||
'
|
||||
MESSAGE="$(lastarg $@)"
|
||||
AGAINST="$(nolastarg $@)"
|
||||
IFS=' '
|
||||
|
||||
if ( [ "$1" = "-h" ] || [ "$1" = "--help" ] ) && [ "$2" = "" ] ; then
|
||||
echo "Usage: usage [args to check] <usage string> "
|
||||
echo "Usage: $NAME [args to check] <usage string> "
|
||||
else
|
||||
CHECK='-h
|
||||
--help'
|
||||
if [ "$1" != "" ] ; then
|
||||
if [ -z $USAGE_LOCK ] ; then
|
||||
export USAGE_LOCK=1
|
||||
echo $CHECK | lseqcmd spipe largcmd cat "$@"
|
||||
echo $CHECK | linefirstargdo firstargnthargdo $(( 4 + $# )) firstnthpipedo $(( $# - 1 )) "$AGAINST" invertstatus linematchfirstargdo echo "$MESSAGE"
|
||||
CODE="$?"
|
||||
unset USAGE_LOCK
|
||||
exit $CODE
|
||||
|
|
Loading…
Reference in New Issue