Browse Source

Update library script

Samuel W. Flint 4 years ago
parent
commit
9810eed2a1
1 changed files with 41 additions and 38 deletions
  1. 41 38
      library

+ 41 - 38
library

@@ -1,8 +1,11 @@
 #!/bin/sh
 # packaging, library.org
-LIBRARYFILE=~/.library/library.rec
-LIBRARYDIRECTORY=~/.library
-GIT=detect
+# configuration, /home/swflint/Projects/library/library.org
+export LIBRARY_FILE=${LIBRARY_FILE:-~/.library/library.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}
+# configuration ends here
 
 # help-message, /home/swflint/Projects/library/library.org
 if [[ $# -eq 0 ]] ; then
@@ -37,11 +40,11 @@ function do_report {
     fi
     NAME=$1
     shift
-    case ${NAME} in
+    case "${NAME}" in
         list)
-            for report in ${LIBRARYDIRECTORY}/reports/*.report ;
+            for report in ${LIBRARY_DIRECTORY}/reports/*.report ;
             do
-                echo " - $(basename -- ${report} .report)"
+                echo " - $(basename -- "${report}" .report)"
             done
         ;;
         new)
@@ -51,12 +54,12 @@ function do_report {
             fi
             REPORT=$1
             shift
-            echo "# -*- mode: shell-script -*-" > ${LIBRARYDIRECTORY}/reports/${REPORT}.report
-            emacsclient --alternate-editor="" -n ${LIBRARYDIRECTORY}/reports/${REPORT}.report
+            echo "# -*- mode: shell-script -*-" > "${LIBRARY_DIRECTORY}/reports/${REPORT}.report"
+            emacsclient --alternate-editor="" -n "${LIBRARY_DIRECTORY}/reports/${REPORT}.report"
         ;;
         *)
-            if [[ -e ${LIBRARYDIRECTORY}/reports/${NAME}.report ]] ; then
-               sh ${LIBRARYDIRECTORY}/reports/${NAME}.report $@
+            if [[ -e "${LIBRARY_DIRECTORY}/reports/${NAME}.report" ]] ; then
+               sh "${LIBRARY_DIRECTORY}/reports/${NAME}.report" "$@"
             fi
     esac
 }
@@ -71,13 +74,13 @@ function do_git {
     FIRST=$1
     if [[ $FIRST == "init" ]] ; then
         OLD=`pwd`
-        cd ${LIBRARYDIRECTORY}
-        git $@
+        cd "${LIBRARY_DIRECTORY}"
+        git "$@"
         cd ${OLD}
     else
-        if [[ $GIT == "detect" ]] ; then
+        if [[ $LIBRARY_GIT == "detect" ]] ; then
             OLD=`pwd`
-            cd ${LIBRARYDIRECTORY}
+            cd "${LIBRARY_DIRECTORY}"
             git "$@"
             cd ${OLD}
         fi
@@ -87,7 +90,7 @@ function do_git {
 
 # handle-query, /home/swflint/Projects/library/library.org
 function run_query {
-    recsel -t Book $@ ${LIBRARYFILE}
+    recsel -t Book "$@" "${LIBRARY_FILE}"
 }
 # handle-query ends here
 
@@ -133,8 +136,8 @@ function add_single {
            -f ISBN -v "${ISBN}" \
            -f Location -v "${LOCATION}" \
            -f Card -v UNPRINTED \
-           ${LIBRARYFILE}
-    do_git add `basename ${LIBRARYFILE}`
+           "${LIBRARY_FILE}"
+    do_git add `basename "${LIBRARY_FILE}"`
     do_git commit -m "Added record for \"${TITLE}\""
 }
 # add-book ends here
@@ -145,14 +148,14 @@ function bulk_add {
         echo "library bulk-add number"
         exit 1
     fi
-    GITOLD=${GIT}
-    GIT=FALSE
+    GITOLD="${LIBRARY_GIT}"
+    LIBRARY_GIT=FALSE
     for i in {1..$1} ; do
         echo "Adding book number ${i}"
         add_single
     done
-    GIT=${GITOLD}
-    do_git add `basename ${LIBRARYFILE}`
+    LIBRARY_GIT="${GITOLD}"
+    do_git add `basename "${LIBRARY_FILE}"`
     do_git commit -m "Added ${1} records"
 }
 # add-in-bulk ends here
@@ -171,18 +174,18 @@ function do_edit {
     if [[ $FIELD = "Withdrawn" ]] ; then
         TMPDIR=. recset -e "ID = ${ID}" \
                -f "Withdrawn" -S "`date +"%a, %d %b %Y %H:%M:%S %z"`" \
-               ${LIBRARYFILE}
+               "${LIBRARY_FILE}"
         TMPDIR=. recset -e "ID = ${ID}" \
               -f "Location" -S "WITHDRAWN" \
-              ${LIBRARYFILE}
+              "${LIBRARY_FILE}"
     else
         VALUE=$1
         shift
         TMPDIR=. recset -e "ID = ${ID}" \
                -f "${FIELD}" -s "${VALUE}" \
-               ${LIBRARYFILE}
+               "${LIBRARY_FILE}"
     fi
-    do_git add `basename ${LIBRARYFILE}`
+    do_git add `basename "${LIBRARY_FILE}"`
     do_git commit -m "Edited record id ${ID}"
 }
 
@@ -199,8 +202,8 @@ function do_edit_exp {
     shift
     TMPDIR=. recset -e "${MATCHEXPRESSION}" \
            -f "${FIELDNAME}" -S "${VALUE}" \
-           ${LIBRARYFILE}
-    do_git add $(basename ${LIBRARYFILE})
+           "${LIBRARY_FILE}"
+    do_git add $(basename "${LIBRARY_FILE}")
     if [[ $1 != "" ]] ; then
         do_git commit -m "${1}"
     else
@@ -212,10 +215,10 @@ function do_edit_exp {
 # initialize-database, /home/swflint/Projects/library/library.org
 function initialize {
     OLD=`pwd`
-    mkdir -p ${LIBRARYDIRECTORY}
-    cd ${LIBRARYDIRECTORY}
-    [[ ! -e `basename ${LIBRARYFILE}` ]] && \
-        cat <<EOF > `basename ${LIBRARYFILE}`
+    mkdir -p "${LIBRARY_DIRECTORY}"
+    cd "${LIBRARY_DIRECTORY}"
+    [[ ! -e `basename "${LIBRARY_FILE}"` ]] && \
+        cat <<EOF > `basename "${LIBRARY_FILE}"`
 # file-format, /home/swflint/Projects/library/library.org
 # -*- mode: rec -*-
 
@@ -260,11 +263,11 @@ function do_loan {
 
     TMPDIR=. recset -e "ID = ${ID}" \
            -f "LoanTo" -S "${NAME}" \
-           ${LIBRARYFILE}
+           "${LIBRARY_FILE}"
     TMPDIR=. recset -e "ID = ${ID}" \
            -f "LoanOn" -S "`date +"%a, %d %b %Y %H:%M:%S %z"`" \
-           ${LIBRARYFILE}
-    do_git add `basename ${LIBRARYFILE}`
+           "${LIBRARY_FILE}"
+    do_git add `basename "${LIBRARY_FILE}"`
     do_git commit -m "Loaned Book ${ID} to ${NAME}"
 }
 
@@ -279,12 +282,12 @@ function do_return {
 
     TMPDIR=. recset -e "ID = ${ID}" \
            -f "LoanTo" -d \
-           ${LIBRARYFILE}
+           "${LIBRARY_FILE}"
     TMPDIR=. recset -e "ID = ${ID}" \
            -f "LoanOn" -d \
-           ${LIBRARYFILE}
+           "${LIBRARY_FILE}"
 
-    do_git add `basename ${LIBRARYFILE}`
+    do_git add `basename "${LIBRARY_FILE}"`
     do_git commit -m "Returned Book ${ID}"
 }
 # loan ends here
@@ -293,7 +296,7 @@ function do_return {
 COMMAND=$1
 shift
 
-case ${COMMAND} in
+case "${COMMAND}" in
     help)
         display_help
         exit