|
@@ -4,31 +4,37 @@ LIBRARYFILE=~/.library/library.rec
|
|
|
LIBRARYDIRECTORY=~/.library
|
|
|
GIT=detect
|
|
|
|
|
|
-# help-message, /home/swflint/.library/library.org
|
|
|
+# help-message, /home/swflint/org/library.org
|
|
|
if [[ $# -eq 0 ]] ; then
|
|
|
- echo "library [ help | query query-expressions | add | emacs | git [ other-args ] | bulk-add number | report [ name | list | new name ] | edit id field [ value ] | init ]"
|
|
|
+ echo "library [ help | query | add | emacs | git | bulk-add | report | edit | loan | do-return | init ]"
|
|
|
exit
|
|
|
fi
|
|
|
|
|
|
function display-help {
|
|
|
cat <<EOF
|
|
|
-library [ help | query query-expressions | add | emacs | git [ other-args ] | bulk-add number | report [ name | list | new name ] | edit id field [ value ] | init ]
|
|
|
-
|
|
|
-help: Display this help message.
|
|
|
-query: Query Library Database.
|
|
|
-add: Add a singular book record.
|
|
|
-emacs: View records in emacs.
|
|
|
-edit: Edit the value of a specified field in a specified record.
|
|
|
-git: Run a git command.
|
|
|
-report: Run a report.
|
|
|
-init: Initialize the database.
|
|
|
-bulk-add: Add a specified number of records.
|
|
|
+library [ help | query | add | emacs | git | bulk-add | report | edit | loan | do-return | init ]
|
|
|
+
|
|
|
+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.
|
|
|
+bulk-add: Add a specified number of records.
|
|
|
+report: Run a report.
|
|
|
+edit: Edit the value of a specified field in a specified record.
|
|
|
+loan: Loan a book out.
|
|
|
+do-return: Process a book return
|
|
|
+init: Initialize the database.
|
|
|
EOF
|
|
|
}
|
|
|
# help-message ends here
|
|
|
|
|
|
-# handle-reports, /home/swflint/.library/library.org
|
|
|
+# handle-reports, /home/swflint/org/library.org
|
|
|
function do-report {
|
|
|
+ if [[ $# -lt 1 ]] ; then
|
|
|
+ echo "library report name args*"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
NAME=$1
|
|
|
shift
|
|
|
case ${NAME} in
|
|
@@ -39,9 +45,13 @@ function do-report {
|
|
|
done
|
|
|
;;
|
|
|
new)
|
|
|
+ if [[ $# -lt 1 ]] ; then
|
|
|
+ echo "library report new name"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
REPORT=$1
|
|
|
shift
|
|
|
- echo "# -*- mode: sh-script -*-" > ${LIBRARYDIRECTORY}/${REPORT}.report
|
|
|
+ echo "# -*- mode: shell-script -*-" > ${LIBRARYDIRECTORY}/${REPORT}.report
|
|
|
emacsclient --alternate-editor="" -n ${LIBRARYDIRECTORY}/${REPORT}.report
|
|
|
;;
|
|
|
*)
|
|
@@ -52,8 +62,12 @@ function do-report {
|
|
|
}
|
|
|
# handle-reports ends here
|
|
|
|
|
|
-# handle-git, /home/swflint/.library/library.org
|
|
|
+# handle-git, /home/swflint/org/library.org
|
|
|
function do-git {
|
|
|
+ if [[ $# -lt 1 ]] ; then
|
|
|
+ echo "library git args*"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
FIRST=$1
|
|
|
if [[ $FIRST == "init" ]] ; then
|
|
|
OLD=`pwd`
|
|
@@ -71,13 +85,13 @@ function do-git {
|
|
|
}
|
|
|
# handle-git ends here
|
|
|
|
|
|
-# handle-query, /home/swflint/.library/library.org
|
|
|
+# handle-query, /home/swflint/org/library.org
|
|
|
function run-query {
|
|
|
recsel -t Book $@ ${LIBRARYFILE}
|
|
|
}
|
|
|
# handle-query ends here
|
|
|
|
|
|
-# add-book, /home/swflint/.library/library.org
|
|
|
+# add-book, /home/swflint/org/library.org
|
|
|
function add-single {
|
|
|
echo -n "Title: "
|
|
|
read TITLE
|
|
@@ -107,8 +121,12 @@ function add-single {
|
|
|
}
|
|
|
# add-book ends here
|
|
|
|
|
|
-# add-in-bulk, /home/swflint/.library/library.org
|
|
|
+# add-in-bulk, /home/swflint/org/library.org
|
|
|
function bulk-add {
|
|
|
+ if [[ $@ -lt 1 ]] ; then
|
|
|
+ echo "library bulk-add number"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
GITOLD=${GIT}
|
|
|
GIT=FALSE
|
|
|
for i in {1..$1} ; do
|
|
@@ -121,8 +139,12 @@ function bulk-add {
|
|
|
}
|
|
|
# add-in-bulk ends here
|
|
|
|
|
|
-# edit-field, /home/swflint/.library/library.org
|
|
|
+# edit-field, /home/swflint/org/library.org
|
|
|
function do-edit {
|
|
|
+ if [[ $# -lt 2 ]] ; then
|
|
|
+ echo "ledger edit id field [ value ]"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
ID=$1
|
|
|
shift
|
|
|
FIELD=$1
|
|
@@ -130,7 +152,7 @@ function do-edit {
|
|
|
|
|
|
if [[ $FIELD = "Withdrawn" ]] ; then
|
|
|
recset -e "ID = ${ID}" \
|
|
|
- -f "Withdrawn" -S `date "%a, %d %b %Y %H:%M:%S %z"` \
|
|
|
+ -f "Withdrawn" -S "`date +"%a, %d %b %Y %H:%M:%S %z"`" \
|
|
|
${LIBRARYFILE}
|
|
|
else
|
|
|
VALUE=$1
|
|
@@ -144,14 +166,14 @@ function do-edit {
|
|
|
}
|
|
|
# edit-field ends here
|
|
|
|
|
|
-# initialize-database, /home/swflint/.library/library.org
|
|
|
+# initialize-database, /home/swflint/org/library.org
|
|
|
function initialize {
|
|
|
OLD=`pwd`
|
|
|
mkdir -p ${LIBRARYDIRECTORY}
|
|
|
cd ${LIBRARYDIRECTORY}
|
|
|
[[ -ne `basename ${LIBRARYFILE}` ]] && \
|
|
|
cat <<EOF > `basename ${LIBRARYFILE}`
|
|
|
-# file-format, /home/swflint/.library/library.org
|
|
|
+# file-format, /home/swflint/org/library.org
|
|
|
# -*- mode: rec -*-
|
|
|
|
|
|
%rec: Book
|
|
@@ -166,22 +188,68 @@ function initialize {
|
|
|
%type: Publisher line
|
|
|
%type: Copyright int
|
|
|
%type: Location line
|
|
|
+%type: Withdrawn date
|
|
|
%type: Inserted date
|
|
|
+%type: LoanTo line
|
|
|
+%type: LoanOn date
|
|
|
%mandatory: Title Author LCCN Inserted
|
|
|
-%allowed: ISBN Publisher Copyright Location
|
|
|
+%allowed: ISBN Publisher Copyright Location Withdrawn LoanTo LoanOn
|
|
|
%auto: ID Inserted
|
|
|
# file-format ends here
|
|
|
EOF
|
|
|
}
|
|
|
# initialize-database ends here
|
|
|
|
|
|
-# view-in-emacs, /home/swflint/.library/library.org
|
|
|
+# view-in-emacs, /home/swflint/org/library.org
|
|
|
function view-in-emacs {
|
|
|
emacsclient --alternate-editor="" -n ${LIBRARYFILE}
|
|
|
}
|
|
|
# view-in-emacs ends here
|
|
|
|
|
|
-# process-commands, /home/swflint/.library/library.org
|
|
|
+# loan, /home/swflint/org/library.org
|
|
|
+function do-loan {
|
|
|
+ if [[ $# -lt 2 ]] ; then
|
|
|
+ echo "library loan id name"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
+
|
|
|
+ ID=$1
|
|
|
+ shift
|
|
|
+ NAME=$1
|
|
|
+ shift
|
|
|
+
|
|
|
+ recset -e "ID = ${ID}" \
|
|
|
+ -f "LoanTo" -S "${NAME}" \
|
|
|
+ ${LIBRARYFILE}
|
|
|
+ recset -e "ID = ${ID}" \
|
|
|
+ -f "LoanOn" -S "`date +"%a, %d %b %Y %H:%M:%S %z"`" \
|
|
|
+ ${LIBRARYFILE}
|
|
|
+ do-git add `basename ${LIBRARYFILE}`
|
|
|
+ do-git commit -m "Loaned Book ${ID} to ${NAME}"
|
|
|
+}
|
|
|
+
|
|
|
+function do-return {
|
|
|
+ if [[ $# -lt 1 ]] ; then
|
|
|
+ echo "library return-book id"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
+
|
|
|
+ ID=$1
|
|
|
+ shift
|
|
|
+
|
|
|
+ recset -e "ID = ${ID}" \
|
|
|
+ -f "LoanTo" -d \
|
|
|
+ ${LIBRARYFILE}
|
|
|
+ recset -e "ID = ${ID}" \
|
|
|
+ -f "LoanOn" -d \
|
|
|
+ ${LIBRARYFILE}
|
|
|
+
|
|
|
+ do-git add `basename ${LIBRARYFILE}`
|
|
|
+ do-git commit -m "Returned Book ${ID}"
|
|
|
+}
|
|
|
+# loan ends here
|
|
|
+
|
|
|
+# process-commands, /home/swflint/org/library.org
|
|
|
COMMAND=$1
|
|
|
shift
|
|
|
|
|
@@ -218,6 +286,14 @@ case ${COMMAND} in
|
|
|
do-edit $@
|
|
|
exit
|
|
|
;;
|
|
|
+ loan)
|
|
|
+ do-loan $@
|
|
|
+ exit
|
|
|
+ ;;
|
|
|
+ return-book)
|
|
|
+ do-return $@
|
|
|
+ exit
|
|
|
+ ;;
|
|
|
init)
|
|
|
initialize
|
|
|
exit
|