Browse code

Start re-write-- mainly lib/stic progress

Jade Levesque authored on 2017-06-18 07:14:10
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,52 @@
1
+OK, I'm re-writing shelltube.
2
+It worked, but it was inflexible and total shit.
3
+Yes, the dream is still POSIX. :)
4
+Here is a general plan:
5
+
6
+./shelltube	Wrapper script for everything else. Slim and simple
7
+./lib/yts	Searches YT, outputs a comp-friendly list of results
8
+./lib/ytc	Lists videos on a YT channel/user-page
9
+./lib/ytd	Downloads/streams a YT video
10
+./lib/stc	Helps configure shelltube
11
+./lib/stic	Helps with cli arguments
12
+./lib/sti	Helps with trapped user input
13
+
14
+Planned inputs & details:
15
+./shelltube
16
+	shelltube [command(s) to run after startup]
17
+./lib/yts
18
+	$ yts query [-o $outfile]
19
+	* Prints the results in the following format:
20
+		artist \t name \t length (?) \t ID
21
+./lib/ytc
22
+	$ ytc query [-o $outfile]
23
+	* Prints the results in the following format:
24
+		name \t length (?) \t ID
25
+./lib/ytd
26
+	$ ytd URL||ID [-o $outfile||-s]
27
+./lib/stc
28
+	$ stc [-h||--home $homedir]
29
+	* Just creates/edits $HOME/.config/shelltube
30
+./lib/stic
31
+	$ stic "$@" "[[syntax]] shortargf longargf argf
32
+	* Outputs commandline args to the specified files
33
+	  for easier parsing
34
+	* dargf contains args like -c, -o, --config, etc.
35
+	* argf contains everything else, like 'filename' etc.
36
+	* [[syntax]] consists of something like this:
37
+	  "[[(1|1|c|config)(1|0|v|verbose)(0|1|infile)(0|2|outfile)]]"
38
+	* Does it look terrible painful? Let me show you the anatomy of
39
+	  one of those listed potential arugments:
40
+	* In a dashed arg (--config or -c), the syntax is this:
41
+	  (1|0=no subsequent arg 1=subs. arg|short form|long form)
42
+	  The "subsequent arg" means like 'file' in "--config file"
43
+	* In a non-dashed arg (infile or outfile), the syntax is this:
44
+	  (0|position in input|name)
45
+	  "Position in input" refers to the position it has in relation
46
+	  to other non-dashed args.
47
+	  The "name"
48
+	
49
+
50
+I'm working on stic riggt now. I think it'll really make shelltube (and
51
+probably any other shell script I'll ever write!) a lot better and more
52
+usable.
0 53
new file mode 100644
... ...
@@ -0,0 +1,73 @@
1
+#!/bin/sh -e
2
+
3
+#####################################################################################
4
+# Name: stic
5
+# Lisc: GPLv3
6
+# Main: jadedctrl | jadedml@openmailbox.org
7
+# Usage: $ stic "$@" "SYNTAX" argfile longargfile
8
+# Desc: Makes handling cli arguments easier-- no more shitty case or if statements
9
+#       for us! ... or I'll throw myself against the nearest sharp object
10
+#####################################################################################
11
+
12
+
13
+ALL="$1"
14
+SYNTAX="$2"
15
+ARGFILE="$3"
16
+LONGARGFILE="$4"
17
+
18
+RANDID=$(mktemp -u XXXXXX)
19
+LONGARGPROCFILE="/tmp/stic-long-${RANDID}.proc"
20
+SHORTARGPROCFILE="/tmp/stic-short-${RANDID}.proc"
21
+
22
+
23
+# Go through every () syntax statement; output in awk+grep-friendly format
24
+syntaxproc="$(echo $SYNTAX | sed 's^ ^^g' | sed 's^)(^) (^g')"
25
+for synarg in $(echo "$syntaxproc")
26
+do
27
+	synargproc="$(echo "$synarg" | sed 's/(//' | sed 's/)//')"
28
+	argtype=$(echo "$synargproc" | awk -F "|" '{ print $1 }')
29
+
30
+	# Longargs go first
31
+	if [ $argtype -eq 0 ]
32
+	then
33
+		position=$(echo "$synargproc" | awk -F "|" '{ print $2 }')
34
+		name=$(echo "$synargproc" | awk -F "|" '{ print $3 }')
35
+		printf "%s\t%s\n" $position $name >> $LONGARGPROCFILE
36
+	
37
+	# Now for the shortargs
38
+	elif [ $argtype -eq 1 ]
39
+	then
40
+		subsarg=$(echo "$synargproc" | awk -F "|" '{ print $2 }')
41
+		shortname=$(echo "$synargproc" | awk -F "|" '{ print $3 }')
42
+		longname=$(echo "$synargproc" | awk -F "|" '{ print $4 }')
43
+		printf "%s\t%s\t%s" $subsarg $shortname $longname >> $SHORTARGPROCFILE
44
+		if [ $subsarg -eq 1 ]
45
+		then
46
+			subsname=$(echo "$synargproc" | awk -F "|" '{ print $5 }')
47
+			printf "\t%s" $subsname >> $SHORTARGPROCFILE
48
+		fi
49
+		printf "\n" >> $SHORTARGPROCFILE
50
+	else
51
+		exit 1
52
+	fi
53
+done
54
+
55
+printf "Session ID: %s\n" $RANDID
56
+cat $SHORTARGPROCFILE
57
+cat $LONGARGPROCFILE
58
+
59
+# At this point, the syntax is easy awk-parseable stored in the $*ARGPROCFILE files
60
+
61
+position=0
62
+for argument in "$(echo "$ALL")"
63
+do
64
+	if echo "$argument" | grep "^\--"
65
+	then
66
+		argtype=1
67
+		if 
68
+	else
69
+		if [ $insubsarg -eq 1 ]
70
+		then
71
+			printf "\t%s\n" $argument >> $SHORTARGFILE
72
+		argtype=0
73
+		position=$((position+1))