jrnl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!/bin/sh
  2. export JOURNAL_FILE=${JOURNAL_FILE:-~/.library/journals.rec}
  3. export LIBRARY_DIRECTORY=${LIBRARY_DIRECTOR:-~/.library}
  4. export LIBRARY_GIT=${LIBRARY_GIT:-detect}
  5. export LIBRARY_DEFAULT_FIELDS=${LIBRARY_DEFAULT_FIELDS:-ID,Title,Author,LCCN,Location,Course}
  6. PROGNAME=$(basename $0)
  7. if [[ $# -eq 0 ]] ; then
  8. echo "$PROGNAME [ help | add_journal | add_issue | many_issues | git ]"
  9. exit
  10. fi
  11. function display_help {
  12. cat <<EOF
  13. $PROGNAME [help | add-journal | add-issue | many-issues | git ]
  14. help: show this help
  15. add-journal: add entry for a journal
  16. add-issue: add entry for an issue
  17. many-issues: add many issues
  18. git: perform git command
  19. EOF
  20. }
  21. function do_git {
  22. if [[ $# -lt 1 ]] ; then
  23. echo "$PROGNAME git args*"
  24. exit 1
  25. fi
  26. FIRST=$1
  27. if [[ $FIRST == "init" ]] ; then
  28. OLD=`pwd`
  29. cd "${LIBRARY_DIRECTORY}"
  30. git "$@"
  31. cd ${OLD}
  32. else
  33. if [[ $LIBRARY_GIT == "detect" ]] ; then
  34. OLD=`pwd`
  35. cd "${LIBRARY_DIRECTORY}"
  36. git "$@"
  37. cd ${OLD}
  38. fi
  39. fi
  40. }
  41. function add_journal {
  42. if [[ $# -lt 2 ]] ; then
  43. echo -n "Title: "
  44. read TITLE
  45. echo -n "ISSN: "
  46. read ISSN
  47. echo -n "Publisher: "
  48. read PUBLISHER
  49. else
  50. TITLE=$1
  51. shift
  52. ISSN=$1
  53. shift
  54. PUBLISHER=$1
  55. shift
  56. fi
  57. TMPDIR=. recins -t Journal \
  58. -f Title -v "${TITLE}" \
  59. -f ISSN -v "${ISSN}" \
  60. -f Publisher -v "${PUBLISHER}" \
  61. "${JOURNAL_FILE}"
  62. do_git add `basename "${JOURNAL_FILE}"`
  63. do_git commit -m "Added entry for journal ${TITLE}."
  64. }
  65. function guess_journal {
  66. echo -n "Journal Name: "
  67. read NAME
  68. recsel -t Journal \
  69. -i -q "${NAME}" \
  70. -R ID,Title \
  71. "${JOURNAL_FILE}" |\
  72. awk -F' ' -e 'NF' |\
  73. awk -F' ' -e '{sub(/ /,"\t")}1'
  74. echo -n "Journal Number: "
  75. read JOURNAL
  76. }
  77. function add_issue {
  78. if [[ $# -lt 3 ]] ; then
  79. guess_journal
  80. echo -n "Volume: "
  81. read VOLUME
  82. echo -n "Issue: "
  83. read ISSUE
  84. echo -n "Location: "
  85. read LOCATION
  86. else
  87. JOURNAL=$1
  88. shift
  89. VOLUME=$1
  90. shift
  91. ISSUE=$1
  92. shift
  93. LOCATION=$1
  94. shift
  95. fi
  96. TMPDIR=. recins -t Issue \
  97. -f Journal -v "${JOURNAL}" \
  98. -f Volume -v "${VOLUME}" \
  99. -f Issue -v "${ISSUE}" \
  100. -f Location -v "${Location}" \
  101. "${JOURNAL_FILE}"
  102. do_git add `basename "${JOURNAL_FILE}"`
  103. do_git commit -m "Added entry for Journal Issue"
  104. }
  105. function many_issues {
  106. if [[ $@ -lt 1 ]] ; then
  107. echo "$PROGNAME many_issues number"
  108. exit 1
  109. fi
  110. echo $1
  111. GITOLD="${LIBRARY_GIT}"
  112. LIBRARY_GIT=FALSE
  113. for i in {1..$1} ; do
  114. add_issue
  115. done
  116. LIBRARY_GIT="${GITOLD}"
  117. do_git add `basename "${JOURNAL_FILE}"`
  118. do_git commit -m "Added ${1} Issues"
  119. }
  120. COMMAND=$1
  121. shift
  122. case "${COMMAND}" in
  123. help)
  124. display_help
  125. exit
  126. ;;
  127. add-journal)
  128. add_journal "$@"
  129. exit
  130. ;;
  131. add-issue)
  132. add_issue "$@"
  133. exit
  134. ;;
  135. git)
  136. do_git "$@"
  137. exit
  138. ;;
  139. many-issues)
  140. many_issues "$@"
  141. exit
  142. ;;
  143. *)
  144. display_help
  145. exit
  146. esac
  147. journal