Guest User

Untitled

a guest
Jul 15th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.22 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. COMIX=${COMIX:-"mcomix -fmdh"}
  4. COLLECT=${COLLECT:-"collect"}
  5. D=${PREFIX:-"/tmp/mb-$$"}
  6.  
  7.  
  8. ######
  9. ###### Initialize
  10. ######
  11.  
  12. set -m
  13. exec 2>/dev/null
  14.  
  15. ### tmp directory
  16. mkdir -p "$D"
  17. mkfifo "$D/event"
  18. mkfifo "$D/history"
  19. mkfifo "$D/book"
  20.  
  21. ### file descriptors
  22. exec 7<>"$D/event"
  23. exec 8<>"$D/history"
  24. exec 9<>"$D/book"
  25.  
  26. ### initial run
  27. echo next >&7 &
  28.  
  29. ### trap
  30. function cleanup () {
  31.     for pid in `jobs -p`; do
  32.         kill -TERM -"${pid}"
  33.     done
  34.     wait
  35.  
  36.     exec 7<&- 7>&-
  37.     exec 8<&- 8>&-
  38.     exec 9<&- 9>&-
  39.  
  40.     rm -rf "$D";
  41. }
  42. trap "cleanup" EXIT
  43.  
  44. ### working directory
  45. cd "${COLLECT}"
  46.  
  47.  
  48.  
  49. ######
  50. ###### Main
  51. ######
  52.  
  53. ### Generate Book List
  54. ls | sort -R >&9 &
  55.  
  56.  
  57. ### GUI
  58. (
  59.     yad --text-info --tail            \
  60.         --button=Jobs:'echo jobs'     \
  61.         --button=Delete:'echo delete' \
  62.         --button=Quit:'echo quit'     ;
  63.     echo quit
  64. ) <&8 >&7 &
  65.  
  66.  
  67. ### Event Loop
  68. while read event; do
  69.     case "${event}" in
  70.         delete)
  71.             ;;
  72.         next)
  73.             read book <&9
  74.             echo "${book}" >&8
  75.             ( ${COMIX} "${book}"; echo next >&7 ) &
  76.             ;;
  77.         quit) break ;;
  78.         jobs) jobs ;;
  79.     esac
  80. done <&7
Add Comment
Please, Sign In to add comment