123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #!/bin/sh
- export JOURNAL_FILE=${JOURNAL_FILE:-~/.library/journals.rec}
- export LIBRARY_DIRECTORY=${LIBRARY_DIRECTOR:-~/.library}
- export LIBRARY_GIT=${LIBRARY_GIT:-detect}
- export LIBRARY_DEFAULT_FIELDS=${LIBRARY_DEFAULT_FIELDS:-ID,Title,Author,LCCN,Location,Course}
- PROGNAME=$(basename $0)
- if [[ $# -eq 0 ]] ; then
- echo "$PROGNAME [ help | add_journal | add_issue | many_issues | git ]"
- exit
- fi
- function display_help {
- cat <<EOF
- $PROGNAME [help | add-journal | add-issue | many-issues | git ]
- help: show this help
- add-journal: add entry for a journal
- add-issue: add entry for an issue
- many-issues: add many issues
- git: perform git command
- EOF
- }
- function do_git {
- if [[ $# -lt 1 ]] ; then
- echo "$PROGNAME git args*"
- exit 1
- fi
- FIRST=$1
- if [[ $FIRST == "init" ]] ; then
- OLD=`pwd`
- cd "${LIBRARY_DIRECTORY}"
- git "$@"
- cd ${OLD}
- else
- if [[ $LIBRARY_GIT == "detect" ]] ; then
- OLD=`pwd`
- cd "${LIBRARY_DIRECTORY}"
- git "$@"
- cd ${OLD}
- fi
- fi
- }
- function add_journal {
- if [[ $# -lt 2 ]] ; then
- echo -n "Title: "
- read TITLE
- echo -n "ISSN: "
- read ISSN
- echo -n "Publisher: "
- read PUBLISHER
- else
- TITLE=$1
- shift
- ISSN=$1
- shift
- PUBLISHER=$1
- shift
- fi
- TMPDIR=. recins -t Journal \
- -f Title -v "${TITLE}" \
- -f ISSN -v "${ISSN}" \
- -f Publisher -v "${PUBLISHER}" \
- "${JOURNAL_FILE}"
- do_git add `basename "${JOURNAL_FILE}"`
- do_git commit -m "Added entry for journal ${TITLE}."
- }
- function guess_journal {
- echo -n "Journal Name: "
- read NAME
- recsel -t Journal \
- -i -q "${NAME}" \
- -R ID,Title \
- "${JOURNAL_FILE}" |\
- awk -F' ' -e 'NF' |\
- awk -F' ' -e '{sub(/ /,"\t")}1'
- echo -n "Journal Number: "
- read JOURNAL
- }
- function add_issue {
- if [[ $# -lt 3 ]] ; then
- guess_journal
- echo -n "Volume: "
- read VOLUME
- echo -n "Issue: "
- read ISSUE
- echo -n "Location: "
- read LOCATION
- else
- JOURNAL=$1
- shift
- VOLUME=$1
- shift
- ISSUE=$1
- shift
- LOCATION=$1
- shift
- fi
- TMPDIR=. recins -t Issue \
- -f Journal -v "${JOURNAL}" \
- -f Volume -v "${VOLUME}" \
- -f Issue -v "${ISSUE}" \
- -f Location -v "${Location}" \
- "${JOURNAL_FILE}"
- do_git add `basename "${JOURNAL_FILE}"`
- do_git commit -m "Added entry for Journal Issue"
- }
- function many_issues {
- if [[ $@ -lt 1 ]] ; then
- echo "$PROGNAME many_issues number"
- exit 1
- fi
- echo $1
- GITOLD="${LIBRARY_GIT}"
- LIBRARY_GIT=FALSE
- for i in {1..$1} ; do
- add_issue
- done
- LIBRARY_GIT="${GITOLD}"
- do_git add `basename "${JOURNAL_FILE}"`
- do_git commit -m "Added ${1} Issues"
- }
- COMMAND=$1
- shift
- case "${COMMAND}" in
- help)
- display_help
- exit
- ;;
- add-journal)
- add_journal "$@"
- exit
- ;;
- add-issue)
- add_issue "$@"
- exit
- ;;
- git)
- do_git "$@"
- exit
- ;;
- many-issues)
- many_issues "$@"
- exit
- ;;
- *)
- display_help
- exit
- esac
- journal
|