Last active
June 16, 2017 14:58
-
-
Save sciguy16/41feaad91ee4c2b7cd8b53a9733ffcf8 to your computer and use it in GitHub Desktop.
Bash script for opening latex source files from a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Sections should each have a ${section}.tex in . and a ${section} directory | |
# containing their subsections and other content. | |
function openall { | |
if [[ -f "$1.tex" ]] ; then | |
OPT="$1.tex" | |
else | |
OPT="" | |
fi | |
if [[ -f "$1/refs.bib" ]] ; then | |
OPT="${OPT} $1/refs.bib" | |
fi | |
xed --new-window ${OPT} "$1"/*.tex & | |
} | |
if [[ -d "$1" ]] # it is a valid directory | |
then | |
openall "$1" | |
exit | |
fi | |
echo "Here is a list of valid options:" | |
# see https://stackoverflow.com/questions/23356779/how-can-i-store-find-command-result-as-arrays-in-bash | |
options=() | |
while IFS= read -r -d $'\0'; do | |
options+=("$REPLY") | |
done < <(find . -maxdepth 1 -mindepth 0 -type d -print0 | sed 's/\.\///g') | |
let len=${#options[*]}-1 | |
for i in `seq 0 $len` | |
do | |
echo "$i: ${options[$i]}" | |
done | |
REPLY="" | |
while [[ ! $REPLY ]] ; do | |
read -r -p "Enter a number (0 to ${len}): " | |
done | |
if [[ -d ${options[$REPLY]} ]] | |
then | |
echo ${options[$REPLY]} | |
openall ${options[$REPLY]} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment