st/scripts/st_copyout
2023-01-21 00:07:08 +01:00

12 lines
652 B
Bash
Executable file

#!/bin/sh
# original script by Jaywalker and Luke Smith (https://github.com/Lukesmithxyz/st)
[ -z "$RUNLAUNCHER" ] && RUNLAUNCHER=spmenu
tmpfile=$(mktemp /tmp/st-cmd-output.XXXXXX)
trap 'rm -f "$tmpfile"' 0 1 15
sed -n "w $tmpfile"
sed -i 's/\x0//g' "$tmpfile"
ps1="$(grep "\S" "$tmpfile" | tail -n 1 | sed 's/^\s*//' | cut -d' ' -f1)"
chosen="$(grep -F "$ps1" "$tmpfile" | sed '$ d' | tac | $RUNLAUNCHER -p "Copy which command's output?" -na -i -l 10 -w $WINDOWID -g 1 | sed 's/[^^]/[&]/g; s/\^/\\^/g')"
eps1="$(echo "$ps1" | sed 's/[^^]/[&]/g; s/\^/\\^/g')"
awk "/^$chosen$/{p=1;print;next} p&&/$eps1/{p=0};p" "$tmpfile" | xclip -selection clipboard