My dotfiles. Period.

xt.dash 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/dash
  2. fixnl () {
  3. local arg=$1;
  4. local cache;
  5. local nlcount;
  6. local lastchr;
  7. local single=keep;
  8. case $arg in
  9. -c | --chop-single)
  10. single=chop
  11. ;;
  12. esac;
  13. # TODO: ^^ should probably be:
  14. #
  15. # test -n "$UID" || return 3
  16. # cache="$(mktemp "/run/user/$UID/fixnl.XXXXXXXX")";
  17. #
  18. # but UID is not supported in bash, so..
  19. cat > "$cache";
  20. nlcount=$(<"$cache" wc -l);
  21. lastchr=$(<"$cache" tail -c1 | hexdump -e '"%02x"');
  22. case $nlcount:$lastchr:$single in
  23. 0:??:*)
  24. cat "$cache"
  25. ;;
  26. 1:0a:chop)
  27. head -c -1 "$cache"
  28. ;;
  29. 1:0a:keep)
  30. cat "$cache"
  31. ;;
  32. *:0a:*)
  33. cat "$cache"
  34. ;;
  35. *:??:*)
  36. cat "$cache";
  37. echo
  38. ;;
  39. esac;
  40. rm "$cache"
  41. }
  42. main () {
  43. local body;
  44. body="$(xclip -o)"
  45. # declare -p body >~/body.declare
  46. # echo -n "$body" | hexdump -C >~/body.hexdump
  47. sleep 0.25s
  48. xdotool type "$body"
  49. }
  50. main "$@"