| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!/bin/dash
-
-
- fixnl () {
- local arg=$1;
- local cache;
- local nlcount;
- local lastchr;
- local single=keep;
- case $arg in
- -c | --chop-single)
- single=chop
- ;;
- esac;
- # TODO: ^^ should probably be:
- #
- # test -n "$UID" || return 3
- # cache="$(mktemp "/run/user/$UID/fixnl.XXXXXXXX")";
- #
- # but UID is not supported in bash, so..
- 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.25s
- xdotool type "$body"
- }
-
- main "$@"
|