|
@@ -0,0 +1,145 @@
|
|
|
+#!/bin/zsh -f
|
|
|
+
|
|
|
+LIBRARYFILE=~/.library/library.rec
|
|
|
+LIBRARYDIRECTORY=~/.library
|
|
|
+GIT=true
|
|
|
+
|
|
|
+if [[ $# -eq 0 ]] ; then
|
|
|
+ echo "library [ help | query query-expressions | add | emacs | git [ other-args ] | bulk-add number | report [ name | list | new name ] ]"
|
|
|
+ exit
|
|
|
+fi
|
|
|
+
|
|
|
+function run-query {
|
|
|
+ recsel -t Book $@ ${LIBRARYFILE}
|
|
|
+}
|
|
|
+
|
|
|
+function add-single {
|
|
|
+ echo -n "Title: "
|
|
|
+ read TITLE
|
|
|
+ echo -n "Author: "
|
|
|
+ read AUTHOR
|
|
|
+ echo -n "LCCN: "
|
|
|
+ read LCCN
|
|
|
+ echo -n "Copyright: "
|
|
|
+ read COPYRIGHT
|
|
|
+ echo -n "Publisher: "
|
|
|
+ read PUBLISHER
|
|
|
+ echo -n "ISBN: "
|
|
|
+ read ISBN
|
|
|
+ echo -n "Location: "
|
|
|
+ read LOCATION
|
|
|
+ recins -t Book \
|
|
|
+ -f Title -v "${TITLE}" \
|
|
|
+ -f Author -v "${AUTHOR}" \
|
|
|
+ -f LCCN -v "${LCCN}" \
|
|
|
+ -f Copyright -v "${COPYRIGHT}" \
|
|
|
+ -f Publisher -v "${PUBLISHER}" \
|
|
|
+ -f ISBN -v "${ISBN}" \
|
|
|
+ -f Location -v "${LOCATION}" \
|
|
|
+ ${LIBRARYFILE}
|
|
|
+ if [[ $GIT == "true" ]] ; then
|
|
|
+ OLD=`pwd`
|
|
|
+ cd ${LIBRARYDIRECTORY}
|
|
|
+ git add `basename ${LIBRARYFILE}`
|
|
|
+ git commit -m "Added record for \"${TITLE}\""
|
|
|
+ cd ${OLD}
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+function bulk-add {
|
|
|
+ GITOLD=${GIT}
|
|
|
+ GIT=FALSE
|
|
|
+ for i in {1..$1} ; do
|
|
|
+ echo "Adding book number ${i}"
|
|
|
+ add-single
|
|
|
+ done
|
|
|
+ GIT=${GITOLD}
|
|
|
+ if [[ $GIT == "true" ]] ; then
|
|
|
+ OLD=`pwd`
|
|
|
+ cd ${LIBRARYDIRECTORY}
|
|
|
+ git add `basename ${LIBRARYFILE}`
|
|
|
+ git commit -m "Added ${1} records"
|
|
|
+ cd ${OLD}
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+function do-report {
|
|
|
+ NAME=$1
|
|
|
+ shift
|
|
|
+ case ${NAME} in
|
|
|
+ list)
|
|
|
+ for report in ${LIBRARYDIRECTORY}/*.report ;
|
|
|
+ do
|
|
|
+ echo " - $(basename -- ${report} .report)"
|
|
|
+ done
|
|
|
+ ;;
|
|
|
+ new)
|
|
|
+ REPORT=$1
|
|
|
+ shift
|
|
|
+ echo "# -*- mode: shell-script -*-" > ${LIBRARYDIRECTORY}/${REPORT}.report
|
|
|
+ emacsclient --alternate-editor="" -n ${LIBRARYDIRECTORY}/${REPORT}.report
|
|
|
+ ;;
|
|
|
+ *)
|
|
|
+ if [[ -e ${LIBRARYDIRECTORY}/${NAME}.report ]] ; then
|
|
|
+ sh ${LIBRARYDIRECTORY}/${NAME}.report $@
|
|
|
+ fi
|
|
|
+ esac
|
|
|
+}
|
|
|
+
|
|
|
+function do-git {
|
|
|
+ OLD=`pwd`
|
|
|
+ cd ${LIBRARYDIRECTORY}
|
|
|
+ git $@
|
|
|
+ cd ${OLD}
|
|
|
+}
|
|
|
+
|
|
|
+function display-help {
|
|
|
+ cat <<EOF
|
|
|
+library [ help | query query-expressions | add | emacs | git [ other-args ] | bulk-add number | report [ name | list | new name ] ]
|
|
|
+
|
|
|
+help: Display this help message.
|
|
|
+query: Query Library Database.
|
|
|
+add: Add a singular book record.
|
|
|
+emacs: View records in emacs.
|
|
|
+git: Run a git command.
|
|
|
+report: Run a report.
|
|
|
+bulk-add: Add a specified number of records.
|
|
|
+EOF
|
|
|
+}
|
|
|
+
|
|
|
+COMMAND=$1
|
|
|
+shift
|
|
|
+
|
|
|
+case ${COMMAND} in
|
|
|
+ help)
|
|
|
+ display-help
|
|
|
+ exit
|
|
|
+ ;;
|
|
|
+ query)
|
|
|
+ run-query $@
|
|
|
+ exit
|
|
|
+ ;;
|
|
|
+ add)
|
|
|
+ add-single
|
|
|
+ exit
|
|
|
+ ;;
|
|
|
+ git)
|
|
|
+ do-git $@
|
|
|
+ exit
|
|
|
+ ;;
|
|
|
+ bulk-add)
|
|
|
+ bulk-add $@
|
|
|
+ exit
|
|
|
+ ;;
|
|
|
+ report)
|
|
|
+ do-report $@
|
|
|
+ exit
|
|
|
+ ;;
|
|
|
+ emacs)
|
|
|
+ emacsclient --alternate-editor="" -n ${LIBRARYFILE}
|
|
|
+ exit
|
|
|
+ ;;
|
|
|
+ *)
|
|
|
+ display-help
|
|
|
+ exit
|
|
|
+esac
|