spacepaste

.tmux.conf

  1.  
  2. bind-key v command-prompt -p "enter digraph:" "set-buffer \"%%\"; save-buffer /tmp/tmux-input; delete-buffer; if-shell '/home/username/bin/digraph.py < /tmp/tmux-input > /tmp/tmux-output' 'load-buffer /tmp/tmux-output; paste-buffer -d; run-shell \"rm /tmp/tmux-output /tmp/tmux-input\"'"
  3.  

digraph.py

  1.  
  2. #!/usr/bin/python
  3. import logging
  4. import os.path
  5. import sys
  6. import unicodedata
  7. logfile = os.path.join(os.path.dirname(__file__), 'exceptions.log')
  8. logging.basicConfig(filename=logfile)
  9. COMBINE_MAP = {
  10. "`": u'\u0300',
  11. "!": u'\u0300',
  12. "'": u'\u0301',
  13. '"': u'\u0301',
  14. "^": u'\u0302',
  15. "~": u'\u0303',
  16. "-": u'\u0304',
  17. ":": u'\u0308',
  18. }
  19. REPLACE = {
  20. "...": u'\N{HORIZONTAL ELLIPSIS}',
  21. "``": u'\N{LEFT DOUBLE QUOTATION MARK}',
  22. "''": u'\N{RIGHT DOUBLE QUOTATION MARK}',
  23. "<3": u'\N{BLACK HEART SUIT}',
  24. "--": u'\N{EM DASH}',
  25. "AE": u'\N{LATIN CAPITAL LETTER AE}',
  26. "ae": u'\N{LATIN SMALL LETTER AE}',
  27. "s": u'\N{LATIN SMALL LETTER LONG S}',
  28. "ss": u'\N{LATIN SMALL LETTER SHARP S}',
  29. }
  30. def main(value):
  31. if value.startswith('U+'):
  32. value = value[2:]
  33. sys.stdout.write(unichr(int(value, 16)).encode('utf8'))
  34. return
  35. if value in REPLACE:
  36. sys.stdout.write(REPLACE[value].encode('utf8'))
  37. return
  38. if len(value) != 2:
  39. raise Exception("invalid value: " + value)
  40. if value[1] in COMBINE_MAP:
  41. s = value[0].decode('ascii') + COMBINE_MAP[value[1]]
  42. s = unicodedata.normalize('NFC', s)
  43. sys.stdout.write(s.encode('utf8'))
  44. return
  45. raise Exception("invalid value: " + value)
  46. if __name__ == '__main__':
  47. try:
  48. main(sys.stdin.read())
  49. except Exception, e:
  50. logging.exception('blargh')
  51. raise
  52.