12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #!/bin/bash
-
-
- fixnl () {
- local arg=$1;
- local cache;
- local nlcount;
- local lastchr;
- local single=keep;
- case $arg in
- -c | --chop-single)
- single=chop
- ;;
- esac;
- cache="$(mktemp -t fixnl.XXXXXXXX)";
- cat > "$cache";
- nlcount=$(<"$cache" wc -l);
- lastchr=$(<"$cache" tail -c1 | hexdump -e '"%02x"');
- case $nlcount:$lastchr:$single in
- 0:??:*)
- cat "$cache"
- ;;
- 1:0a:chop)
- head -c -1 "$cache"
- ;;
- 1:0a:keep)
- cat "$cache"
- ;;
- *:0a:*)
- cat "$cache"
- ;;
- *:??:*)
- cat "$cache";
- echo
- ;;
- esac;
- rm "$cache"
- }
-
- main () {
- local body;
- body="$(xclip -o)"
- declare -p body >~/body.declare
- echo -n "$body" | hexdump -C >~/body.hexdump
- sleep 0.5s
- xdotool type "$body"
- }
-
- main "$@"
|