My dotfiles. Period.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  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. cache="$(mktemp -t fixnl.XXXXXXXX)";
  14. cat > "$cache";
  15. nlcount=$(<"$cache" wc -l);
  16. lastchr=$(<"$cache" tail -c1 | hexdump -e '"%02x"');
  17. case $nlcount:$lastchr:$single in
  18. 0:??:*)
  19. cat "$cache"
  20. ;;
  21. 1:0a:chop)
  22. head -c -1 "$cache"
  23. ;;
  24. 1:0a:keep)
  25. cat "$cache"
  26. ;;
  27. *:0a:*)
  28. cat "$cache"
  29. ;;
  30. *:??:*)
  31. cat "$cache";
  32. echo
  33. ;;
  34. esac;
  35. rm "$cache"
  36. }
  37. main () {
  38. local body;
  39. body="$(xclip -o)"
  40. declare -p body >~/body.declare
  41. echo -n "$body" | hexdump -C >~/body.hexdump
  42. sleep 0.5s
  43. xdotool type "$body"
  44. }
  45. main "$@"