From 707e4429b21f3bd19056b4d3ae40bc753a18c4f2 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Wed, 17 Aug 2022 00:54:46 -0500 Subject: [PATCH] make changes so that the contents are copied --- plugin.sh | 24 ++++-------------------- tmux_capture_last_command_output.tmux | 12 ------------ tmux_copy_last_command_output.tmux | 11 +++++++++++ 3 files changed, 15 insertions(+), 32 deletions(-) delete mode 100755 tmux_capture_last_command_output.tmux create mode 100755 tmux_copy_last_command_output.tmux diff --git a/plugin.sh b/plugin.sh index af894c9..ff0b8e7 100755 --- a/plugin.sh +++ b/plugin.sh @@ -1,23 +1,7 @@ #!/usr/bin/env bash -x=$(tmux capture-pane -p -S '-' -J -t !) -readarray -t pane_contents <<<"$x" +x=$(tmux capture-pane -p -S '-') +PROMPT_PATTERN=${1:-' ) '} +result=$(echo "$x" | tac | sed -e "0,/$PROMPT_PATTERN/d" | sed "/$PROMPT_PATTERN/,\$d" | tac) -# 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 +echo -n "$result" | xclip -sel clip diff --git a/tmux_capture_last_command_output.tmux b/tmux_capture_last_command_output.tmux deleted file mode 100755 index 42704e1..0000000 --- a/tmux_capture_last_command_output.tmux +++ /dev/null @@ -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" diff --git a/tmux_copy_last_command_output.tmux b/tmux_copy_last_command_output.tmux new file mode 100755 index 0000000..2389104 --- /dev/null +++ b/tmux_copy_last_command_output.tmux @@ -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"