jrnl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/sh
  2. export JOURNAL_FILE=${LIBRARY_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 add_issue {
  66. if [[ $# -lt 3 ]] ; then
  67. echo -n "Journal: "
  68. read JOURNAL
  69. echo -n "Volume: "
  70. read VOLUME
  71. echo -n "Issue: "
  72. read ISSUE
  73. echo -n "Location: "
  74. read LOCATION
  75. else
  76. JOURNAL=$1
  77. shift
  78. VOLUME=$1
  79. shift
  80. ISSUE=$1
  81. shift
  82. LOCATION=$1
  83. shift
  84. fi
  85. TMPDIR=. recins -t Issue \
  86. -f Journal -v "${JOURNAL}" \
  87. -f Volume -v "${VOLUME}" \
  88. -f Issue -v "${ISSUE}" \
  89. -f Location -v "${Location}" \
  90. "${JOURNAL_FILE}"
  91. do_git add `basename "${JOURNAL_FILE}"`
  92. do_git commit -m "Added entry for Journal Issue"
  93. }
  94. function many_issues {
  95. if [[ $@ -lt 1 ]] ; then
  96. echo "$PROGNAME many_issues number"
  97. exit 1
  98. fi
  99. echo $1
  100. GITOLD="${LIBRARY_GIT}"
  101. LIBRARY_GIT=FALSE
  102. for i in {1..$1} ; do
  103. add_issue
  104. done
  105. LIBRARY_GIT="${GITOLD}"
  106. do_git add `basename "${JOURNAL_FILE}"`
  107. do_git commit -m "Added ${1} Issues"
  108. }
  109. COMMAND=$1
  110. shift
  111. case "${COMMAND}" in
  112. help)
  113. display_help
  114. exit
  115. ;;
  116. add_journal)
  117. add_journal "$@"
  118. exit
  119. ;;
  120. add_issue)
  121. add_issue "$@"
  122. exit
  123. ;;
  124. git)
  125. do_git "$@"
  126. exit
  127. ;;
  128. many_issues)
  129. many_issues "$@"
  130. exit
  131. ;;
  132. *)
  133. display_help
  134. exit
  135. esac
  136. journal