mirror of
https://github.com/SinTan1729/tmux_copy_last_command_output.git
synced 2025-04-19 09:30:01 -05:00
make changes so that the contents are copied
This commit is contained in:
parent
bfd0f897b3
commit
707e4429b2
3 changed files with 15 additions and 32 deletions
24
plugin.sh
24
plugin.sh
|
@ -1,23 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
x=$(tmux capture-pane -p -S '-' -J -t !)
|
x=$(tmux capture-pane -p -S '-')
|
||||||
readarray -t pane_contents <<<"$x"
|
PROMPT_PATTERN=${1:-' ) '}
|
||||||
|
result=$(echo "$x" | tac | sed -e "0,/$PROMPT_PATTERN/d" | sed "/$PROMPT_PATTERN/,\$d" | tac)
|
||||||
|
|
||||||
# reverse loop through pane contents lines
|
echo -n "$result" | xclip -sel clip
|
||||||
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
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
||||||
|
|
||||||
default_capture_key="t"
|
|
||||||
CAPTURE_KEY=$(tmux show-option -gqv @command-capture-key)
|
|
||||||
CAPTURE_KEY=${CAPTURE_KEY:-$default_capture_key}
|
|
||||||
|
|
||||||
PROMPT_PATTERN=$(tmux show-option -gqv @command-capture-prompt-pattern)
|
|
||||||
EDITOR_CMD=$(tmux show-option -gqv @command-capture-editor-cmd)
|
|
||||||
|
|
||||||
tmux bind $CAPTURE_KEY new-window -n last-command-output -e PROMPT_PATTERN="$PROMPT_PATTERN" -e EDITOR_CMD="$EDITOR_CMD" "$CURRENT_DIR/plugin.sh"
|
|
11
tmux_copy_last_command_output.tmux
Executable file
11
tmux_copy_last_command_output.tmux
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
default_capture_key="g"
|
||||||
|
CAPTURE_KEY=$(tmux show-option -gqv @command-copy-key)
|
||||||
|
CAPTURE_KEY=${CAPTURE_KEY:-$default_capture_key}
|
||||||
|
|
||||||
|
PROMPT_PATTERN=$(tmux show-option -gqv @command-copy-prompt-pattern)
|
||||||
|
|
||||||
|
tmux bind $CAPTURE_KEY run-shell "$CURRENT_DIR/plugin.sh $PROMPT_PATTERN"
|
Loading…
Reference in a new issue