st-copyoutput 494 B

1234567891011
  1. #!/bin/sh
  2. tmpfile=$(mktemp /tmp/st-cmd-output.XXXXXX)
  3. trap 'rm "$tmpfile"' 0 1 15
  4. sed -n "w $tmpfile"
  5. sed -i 's/\x0//g' "$tmpfile"
  6. ps1="$(grep "\S" "$tmpfile" | tail -n 1 | sed 's/^\s*//' | cut -d' ' -f1)"
  7. chosen="$(grep -F "$ps1" "$tmpfile" | sed '$ d' | tac | dmenu -p "Copy which command's output?" -i -l 10 | sed 's/[^^]/[&]/g; s/\^/\\^/g')"
  8. eps1="$(echo "$ps1" | sed 's/[^^]/[&]/g; s/\^/\\^/g')"
  9. awk "/^$chosen$/{p=1;print;next} p&&/$eps1/{p=0};p" "$tmpfile" | xclip -selection clipboard