diff options
| author | Timmy Keller <tjk@tjkeller.xyz> | 2021-11-11 22:23:17 -0600 | 
|---|---|---|
| committer | Timmy Keller <tjk@tjkeller.xyz> | 2021-11-11 22:23:17 -0600 | 
| commit | ab1bc3837a0236f4f07614e1c77b73640e12fdec (patch) | |
| tree | daf5b52e8dcb1e097f55703ee98a33fbceed8474 | |
| parent | a92bcfe91bc274970840cbd65e1389d0c4371e02 (diff) | |
| parent | 559e75d16bc039207461683c7120bb9ab03fd4b7 (diff) | |
| download | scripts-ab1bc3837a0236f4f07614e1c77b73640e12fdec.tar.xz scripts-ab1bc3837a0236f4f07614e1c77b73640e12fdec.zip  | |
Merge branch 'master' of git.tjkeller.xyz:/var/www/git/scripts
| -rwxr-xr-x | misc/pdfautocompile | 39 | 
1 files changed, 38 insertions, 1 deletions
diff --git a/misc/pdfautocompile b/misc/pdfautocompile index d44ec3f..3c0d8f4 100755 --- a/misc/pdfautocompile +++ b/misc/pdfautocompile @@ -1,2 +1,39 @@  #!/bin/sh -echo "$1" | entr pdflatex "$1" || echo "entr or LaTeX is not installed!" +interactiveopt() { +	# Usage: interactiveopt "options" "prompt" "maxopts (if unset than equal to inf)" "col" +	# Purpose: give the user a numbered list of options. User can specify multiple choices. User can specify either the number or the name of the option. +	# Output: saved in variable "opt" +	unset opt # This won't be set if using recursion, do it in a while loop instead +	while [ -z $opt ] 2>/dev/null; do +		# Column option +		[ -n "$4" ] && [ "$4" = "col" ] \ +			&& echo "$1" | nl -s': ' | column \ +			|| echo "$1" | nl -s': ' +		# Parse user input +		read -p "$2" choices \ +			&& choices="$(echo $choices | cut -d' ' -f1-$3)" +		for choice in $choices; do +			case "$choice" in +				[0-9]*)	opt="$(echo "$1" | head -"$(echo $choice | tr -cd '[:digit:]')" | tail -1) $opt"	;; +				*) 	opt="$(echo "$1" | grep "^$choice$" 2>/dev/null) $opt"					;; +			esac || ( echo "Invalid option \"$choice\"" && undet opt && break ) # Why wont this unset opt or break??????? +		done +	done +} + +listfiles() { +	pids=$(xdotool search --class "Vim") +	for pid in $pids; do +		names="$(xdotool getwindowname $pid | grep '\.tex')\n$names" +		#$openfiles="$(echo "$name" | cut -d' ' -f1)\n$openfiles" +		#$openfilepaths="$(echo "$name" | awk -F'[()]' '{ print $2 }')\n$openfiles" +	done +	#file="$(echo $openfiles | grep "^$1")" +	[ -z "$file" ] \ +		&& interactiveopt "$(echo $openfiles | sort -bu | tail +2)" "Which file to autocompile? " 1 \ +		&& file="$opt" +} + +[ -e "$1" ] && file="$1" || listfiles + +echo "$file" | entr pdflatex "$file" || echo "entr or LaTeX is not installed!"  | 
