tmux_copy_last_command_output/plugin.sh

24 lines
514 B
Bash
Raw Normal View History

2022-01-30 07:22:24 -06:00
#!/usr/bin/env bash
x=$(tmux capture-pane -p -S '-' -J -t !)
2022-01-30 07:22:24 -06:00
readarray -t pane_contents <<<"$x"
# reverse loop through pane contents lines
for (( idx=${#pane_contents[@]}-2 ; idx>=0 ; idx-- )) ; do
line=${pane_contents[idx]}
# strip trailing whitespace from line
line=$(sed 's/[[:space:]]*$//' <<<"$line")
if [[ $line =~ "$PROMPT_PATTERN" ]]; then
2022-01-30 07:22:24 -06:00
break
fi
# prepend line to result array
result="$line"$'\n'"$result"
done
EDITOR_CMD=${EDITOR_CMD:-"$EDITOR -"}
echo "$result" | $EDITOR_CMD