Portable environments files and scripts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

115 lines
2.2 KiB

  1. #!/bin/sh
  2. # mless [MSG] - less(1)-wrapper around mshow
  3. colorscan() {
  4. awk '
  5. function co(n, c) { e = ENVIRON["MCOLOR_" n]; return e ? e : c }
  6. function fg(c, s) { return sprintf("\033[38;5;%03dm%s\033[0m", c, s) }
  7. function so(s) { return sprintf("\033[1m%s\033[0m", s) }
  8. /^>/ { print so(fg(co("CUR",119), $0)); next }
  9. /^ *\\_/ { print fg(co("MISS",242), $0); next }
  10. { print }'
  11. }
  12. keyhandler() {
  13. case "$?" in
  14. 0|1) exit $?;;
  15. 36) # $ goto end
  16. mseq -C '$' 2>/dev/null
  17. ;;
  18. 78) # N go to next unseen message
  19. nu=$(magrep -v -m1 :S .:) && mseq -C "$nu"
  20. ;;
  21. 107) # k next thread
  22. mseq -C "$(mseq .+1: | sed -n '/^[^ <]/{p;q;}')"
  23. ;;
  24. 100) # d mark read
  25. mflag -S .
  26. mseq -f : | mseq -S
  27. mseq -C +
  28. ;;
  29. 82) # R toggle raw mode
  30. MLESS_RAW=$((1-$MLESS_RAW))
  31. ;;
  32. 72) # H toggle HTML mode
  33. MLESS_HTML=$((1-$MLESS_HTML))
  34. ;;
  35. 94) # ^ goto parent
  36. mseq -C '.^' 2>/dev/null
  37. ;;
  38. esac
  39. }
  40. if [ -n "${NO_COLOR+set}" ]; then
  41. colorscan() { cat -; }
  42. fi
  43. if [ "$1" = --filter ]; then
  44. if [ "$2" = //scan ]; then
  45. mscan : 2>/dev/null | colorscan
  46. exit $?
  47. fi
  48. mseq -C "$2"
  49. mscan .-2:.+3 2>/dev/null | colorscan
  50. echo
  51. if ! [ -f "$(mseq -r "$2")" ]; then
  52. mseq "$2"
  53. exit
  54. fi
  55. if [ $MLESS_RAW -eq 0 ]; then
  56. if [ $MLESS_HTML -eq 1 ]; then
  57. mshow -A text/html "$2"
  58. else
  59. mshow "$2"
  60. fi | mcolor
  61. else
  62. mseq -r "$2"
  63. echo
  64. cat "$(mseq -r "$2")"
  65. fi
  66. exit $?
  67. fi
  68. if [ "$#" -eq 0 ] && ! [ -t 0 ]; then
  69. mseq -S >/dev/null
  70. set -- :
  71. fi
  72. if ! [ -t 1 ]; then
  73. exec mseq :
  74. fi
  75. [ "$#" -eq 1 ] && set -- ${1:-.}
  76. if [ "$#" -ge 1 ]; then
  77. mseq -C "$1"
  78. fi
  79. nl="
  80. "
  81. export MLESS_RAW=0
  82. export MLESS_HTML=0
  83. if [ -f "$MBLAZE/mless" ]; then
  84. export LESSKEY="$MBLAZE/mless"
  85. elif [ -f "$HOME/.mblaze/mless" ]; then
  86. export LESSKEY="$HOME/.mblaze/mless"
  87. elif [ -f "$HOME/.mless" ]; then
  88. export LESSKEY="$HOME/.mless"
  89. fi
  90. if [ -f "$MBLAZE/mless-key-handler" ]; then
  91. . "$MBLAZE/mless-key-handler"
  92. elif [ -f "$HOME/.mblaze/mless-key-handler" ]; then
  93. . "$HOME/.mblaze/mless-key-handler"
  94. elif [ -f "$HOME/.mless-key-handler" ]; then
  95. . "$HOME/.mless-key-handler"
  96. fi
  97. while :; do
  98. LESSOPEN="|$0 --filter %s" \
  99. less -Ps"mless %f?m (message %i of %m).." -R \
  100. "+:e $(mscan -n .)$nl" //scan $(mscan -n :)
  101. keyhandler $?
  102. done