mirror of
https://github.com/SinTan1729/tmux_copy_last_command_output.git
synced 2025-04-19 01:20:02 -05:00
23 lines
514 B
Bash
Executable file
23 lines
514 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
x=$(tmux capture-pane -p -S '-' -J -t !)
|
|
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
|
|
break
|
|
fi
|
|
|
|
# prepend line to result array
|
|
result="$line"$'\n'"$result"
|
|
done
|
|
|
|
EDITOR_CMD=${EDITOR_CMD:-"$EDITOR -"}
|
|
|
|
echo "$result" | $EDITOR_CMD
|