From 6b06055eb8e9d390f32b65772dc4153834b8403f Mon Sep 17 00:00:00 2001 From: Jade Levesque Date: Sun, 18 Jun 2017 02:14:10 -0500 Subject: [PATCH] Start re-write-- mainly lib/stic progress --- README.md | 52 +++++++++++++++++++++++++++++++++++++++ lib/stic | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 README.md create mode 100644 lib/stic diff --git a/README.md b/README.md new file mode 100644 index 0000000..1e05f1d --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +OK, I'm re-writing shelltube. +It worked, but it was inflexible and total shit. +Yes, the dream is still POSIX. :) +Here is a general plan: + +./shelltube Wrapper script for everything else. Slim and simple +./lib/yts Searches YT, outputs a comp-friendly list of results +./lib/ytc Lists videos on a YT channel/user-page +./lib/ytd Downloads/streams a YT video +./lib/stc Helps configure shelltube +./lib/stic Helps with cli arguments +./lib/sti Helps with trapped user input + +Planned inputs & details: +./shelltube + shelltube [command(s) to run after startup] +./lib/yts + $ yts query [-o $outfile] + * Prints the results in the following format: + artist \t name \t length (?) \t ID +./lib/ytc + $ ytc query [-o $outfile] + * Prints the results in the following format: + name \t length (?) \t ID +./lib/ytd + $ ytd URL||ID [-o $outfile||-s] +./lib/stc + $ stc [-h||--home $homedir] + * Just creates/edits $HOME/.config/shelltube +./lib/stic + $ stic "$@" "[[syntax]] shortargf longargf argf + * Outputs commandline args to the specified files + for easier parsing + * dargf contains args like -c, -o, --config, etc. + * argf contains everything else, like 'filename' etc. + * [[syntax]] consists of something like this: + "[[(1|1|c|config)(1|0|v|verbose)(0|1|infile)(0|2|outfile)]]" + * Does it look terrible painful? Let me show you the anatomy of + one of those listed potential arugments: + * In a dashed arg (--config or -c), the syntax is this: + (1|0=no subsequent arg 1=subs. arg|short form|long form) + The "subsequent arg" means like 'file' in "--config file" + * In a non-dashed arg (infile or outfile), the syntax is this: + (0|position in input|name) + "Position in input" refers to the position it has in relation + to other non-dashed args. + The "name" + + +I'm working on stic riggt now. I think it'll really make shelltube (and +probably any other shell script I'll ever write!) a lot better and more +usable. diff --git a/lib/stic b/lib/stic new file mode 100644 index 0000000..e76a5ef --- /dev/null +++ b/lib/stic @@ -0,0 +1,73 @@ +#!/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))