Ĉi tiu deponejo arĥiviĝis je 2024-01-29. Vi povas vidi kaj elŝuti dosierojn, sed ne povas puŝi nek raporti problemojn nek tirpeti.
shellTube/lib/stic

74 lines
2.0 KiB
Bash

#!/bin/sh -e
#####################################################################################
# Name: stic
# Lisc: GPLv3
# Main: jadedctrl | jadedml@openmailbox.org
# Usage: $ stic "$@" "SYNTAX" argfile longargfile
# Desc: Makes handling cli arguments easier-- no more shitty case or if statements
# for us! ... or I'll throw myself against the nearest sharp object
#####################################################################################
ALL="$1"
SYNTAX="$2"
ARGFILE="$3"
LONGARGFILE="$4"
RANDID=$(mktemp -u XXXXXX)
LONGARGPROCFILE="/tmp/stic-long-${RANDID}.proc"
SHORTARGPROCFILE="/tmp/stic-short-${RANDID}.proc"
# Go through every () syntax statement; output in awk+grep-friendly format
syntaxproc="$(echo $SYNTAX | sed 's^ ^^g' | sed 's^)(^) (^g')"
for synarg in $(echo "$syntaxproc")
do
synargproc="$(echo "$synarg" | sed 's/(//' | sed 's/)//')"
argtype=$(echo "$synargproc" | awk -F "|" '{ print $1 }')
# Longargs go first
if [ $argtype -eq 0 ]
then
position=$(echo "$synargproc" | awk -F "|" '{ print $2 }')
name=$(echo "$synargproc" | awk -F "|" '{ print $3 }')
printf "%s\t%s\n" $position $name >> $LONGARGPROCFILE
# Now for the shortargs
elif [ $argtype -eq 1 ]
then
subsarg=$(echo "$synargproc" | awk -F "|" '{ print $2 }')
shortname=$(echo "$synargproc" | awk -F "|" '{ print $3 }')
longname=$(echo "$synargproc" | awk -F "|" '{ print $4 }')
printf "%s\t%s\t%s" $subsarg $shortname $longname >> $SHORTARGPROCFILE
if [ $subsarg -eq 1 ]
then
subsname=$(echo "$synargproc" | awk -F "|" '{ print $5 }')
printf "\t%s" $subsname >> $SHORTARGPROCFILE
fi
printf "\n" >> $SHORTARGPROCFILE
else
exit 1
fi
done
printf "Session ID: %s\n" $RANDID
cat $SHORTARGPROCFILE
cat $LONGARGPROCFILE
# At this point, the syntax is easy awk-parseable stored in the $*ARGPROCFILE files
position=0
for argument in "$(echo "$ALL")"
do
if echo "$argument" | grep "^\--"
then
argtype=1
if
else
if [ $insubsarg -eq 1 ]
then
printf "\t%s\n" $argument >> $SHORTARGFILE
argtype=0
position=$((position+1))