Commit 13dc60ea authored by User expired's avatar User expired Committed by User expired
Browse files

newbib: Use abbreviated (default) or full journal name

Since journal abbreviation has become quick, it is useful to
always ensure either the abbreviated or full (option -f) form.
parent 024b6ba1
......@@ -9,6 +9,7 @@ function usage() {
echo "Options:"
echo " -h print this help"
echo " -n show changes only (basic formatting is applied)"
echo " -f full instead of abbreviated journal names"
echo " -u do not change field contents"
echo " (.bibtex file is renamed to .bib)"
exit $1
......@@ -19,10 +20,11 @@ if [ $# -lt 1 ]; then usage 1; fi
targetdir=.
# Default options.
DRYFORMAT="" # Optional option for basic formatting.
DRYRUN="" # No dry run option for bib-* tools.
ACTION="eval" # Execute commands (no dry run).
FULLNAME="" # Use long journal names.
KEEPVALUES="" # Edit selected field values.
SKIPJABBR="" # Journal may not be abbreviated.
# Parse command line options.
for arg; do
......@@ -30,19 +32,29 @@ for arg; do
if [[ "$arg" == "-h" ]]; then usage 0; fi
# With option '-n' only print changes/actions.
if [[ "$arg" == "-n" ]]; then
DRYFORMAT="-u"
DRYRUN="-n"
ACTION="echo"
fi
# With option '-f' use full journal names.
if [[ "$arg" == "-f" ]]; then FULLNAME="-u"; fi
# With option '-u' keep field values unchanged.
if [[ "$arg" == "-u" ]]; then KEEPVALUES="-u"; fi
done
if [ -z "${FULLNAME}" ] && [ -z "${DRYRUN}" ]
then
# Journal will certainly be abbreviated, don't do again.
SKIPJABBR="-s"
echo $SKIPJABBR
fi
# Iterate bib files.
for bibfile in "$@"
do
# Skip options.
test "$bibfile" != "-n" || continue
test "$bibfile" != "-f" || continue
test "$bibfile" != "-u" || continue
# Optionally select target directory by argument.
......@@ -60,13 +72,22 @@ do
}
# Format bibtex file.
bib-format ${KEEPVALUES} ${DRYFORMAT} "${bibfile}"
if [ -n "$DRYRUN" ]
then
# Apply basic formatting for dry run.
bib-format -u "${bibfile}"
fi
bib-format ${KEEPVALUES} ${DRYRUN} "${bibfile}"
# (Un)abbreviate journal name.
bib-jabbr ${DRYRUN} ${FULLNAME} "${bibfile}"
# Update citation key.
bib-keyinsert -q ${DRYRUN} "${bibfile}"
bib-keyinsert -q ${SKIPJABBR} ${DRYRUN} "${bibfile}"
# Future bibtex file name.
newbibfile="$(bib-name "${bibfile}" | grep -o '[^ "]*\.pdf\.bib' | tail -n1)"
newbibfile="$(bib-name ${SKIPJABBR} "${bibfile}" \
| grep -o '[^ "]*\.pdf\.bib' | tail -n1)"
# Rename bib and pdf file.
test "${bibfile}" == "${targetdir}/${newbibfile}" \
......
......@@ -10,6 +10,7 @@ function usage() {
echo "Options:"
echo " -h print this help"
echo " -n show changes only"
echo " -f full instead of abbreviated journal names"
echo " -u do not change field contents"
echo " -l select newest files in directory"
echo " (.bibtex file is renamed to .bib)"
......@@ -21,11 +22,12 @@ function usage() {
TARGETDIR=new_lit
# Default options.
DRYFORMAT="" # Optional option for basic formatting.
DRYRUN="" # No dry run option for bib-* tools.
ACTION="eval" # Execute commands (no dry run).
FULLNAME="" # Use long journal names.
KEEPVALUES="" # Edit selected field values.
NEWEST=0 # Do not select newest pdf/bib file.
SKIPJABBR="" # Journal may not be abbreviated.
# Parse command line options.
for arg; do
......@@ -33,21 +35,31 @@ for arg; do
if [[ "$arg" == "-h" ]]; then usage 0; fi
# With option '-n' only print changes/actions.
if [[ "$arg" == "-n" ]]; then
DRYFORMAT="-u"
DRYRUN="-n"
ACTION="echo"
fi
# With option '-f' use full journal names.
if [[ "$arg" == "-f" ]]; then FULLNAME="-u"; fi
# With option '-u' keep field values unchanged.
if [[ "$arg" == "-u" ]]; then KEEPVALUES="-u"; fi
# With option '-l' select newest pdf/bib file.
if [[ "$arg" == "-l" ]]; then NEWEST=1; fi
done
if [ -z "${FULLNAME}" ] && [ -z "${DRYRUN}" ]
then
# Journal will certainly be abbreviated, don't do again.
SKIPJABBR="-s"
echo $SKIPJABBR
fi
# Iterate filenames.
for arg
do
# Skip options.
test "$arg" != "-n" || continue
test "$arg" != "-f" || continue
test "$arg" != "-u" || continue
test "$arg" != "-l" || continue
......@@ -159,16 +171,25 @@ then
fi >/dev/stderr
# Format bibtex file.
bib-format ${KEEPVALUES} ${DRYFORMAT} "${BIBFILE}"
if [ -n "$DRYRUN" ]
then
# Apply basic formatting for dry run.
bib-format -u "${BIBFILE}"
fi
bib-format ${KEEPVALUES} ${DRYRUN} "${BIBFILE}"
# (Un)abbreviate journal name.
bib-jabbr ${DRYRUN} ${FULLNAME} "${BIBFILE}"
# Update citation key.
bib-keyinsert -q ${DRYRUN} "${BIBFILE}"
bib-keyinsert -q ${SKIPJABBR} ${DRYRUN} "${BIBFILE}"
# Create default target directory if required.
test -d "${TARGETDIR}" || $ACTION "mkdir -p \"${TARGETDIR}\"" || exit 1
# Future bibtex file name.
NEWBIBFILE="$(bib-name "${BIBFILE}" | grep -o '[^ "]*\.pdf\.bib' | tail -n1)"
NEWBIBFILE="$(bib-name ${SKIPJABBR} "${BIBFILE}" \
| grep -o '[^ "]*\.pdf\.bib' | tail -n1)"
NEWPDFFILE="${NEWBIBFILE%.bib}"
# Rename bib and pdf file.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment