Skip to content

Instantly share code, notes, and snippets.

@sciguy16
Last active June 16, 2017 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sciguy16/41feaad91ee4c2b7cd8b53a9733ffcf8 to your computer and use it in GitHub Desktop.
Save sciguy16/41feaad91ee4c2b7cd8b53a9733ffcf8 to your computer and use it in GitHub Desktop.
Bash script for opening latex source files from a directory
#!/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