Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #########################################################
  4. ## Uses mformat to format text, then feed it to pandoc ##
  5. ## to create a pdf. Displays the pdf with zathura if ##
  6. ## no output file is specified. ##
  7. #########################################################
  8.  
  9. TMP=$(mktemp /tmp/mrender.XXXXXXXX.pdf)
  10. DIR=$(pwd)
  11.  
  12. function render()
  13. {
  14. F=$(cat "$1")
  15. cd ~
  16. echo "$F"
  17. pandoc \
  18. --standalone --latex-engine=pdflatex \
  19. -H "$HOME/bin/mrender.tex" -o "$2" \
  20. <<< "$F"
  21. cd "$DIR"
  22. }
  23.  
  24. function fileinfo()
  25. {
  26. ls -l --time-style=full-iso "$1"
  27. }
  28.  
  29. trap "rm \"$TMP\"; exit 0" 2
  30.  
  31. FILE="$1"
  32.  
  33. if [ "$FILE" = "" ]; then
  34. FILE="-"
  35. fi
  36.  
  37. render "$FILE" "$TMP"
  38.  
  39. if [ "$1" = "" ]; then
  40. zathura "$TMP"
  41. rm "$TMP"
  42.  
  43. elif [ "$2" = "" ]; then
  44. zathura "$TMP" &
  45. PID="$!"
  46.  
  47. sleep 1;
  48. OLD=$(ls -R --full-time "$FILE")
  49. while :; do
  50. NEW=$(ls -R --full-time "$FILE")
  51.  
  52. # Rerender if file changes
  53. if [ "$OLD" != "$NEW" ]; then
  54. echo "File changed, rerendering."
  55. OLD="$NEW"
  56. render "$FILE" "$TMP"
  57. fi
  58.  
  59. # Die if zathura dies
  60. if ! kill -0 "$PID" > /dev/null 2>&1; then
  61. rm "$TMP"
  62. exit 0
  63. fi
  64.  
  65. sleep 0.1
  66. done
  67.  
  68. rm "$TMP"
  69.  
  70. else
  71. mv "$TMP" "$2"
  72. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement