때로는 화면에 있는 텍스트를 입력하고 싶지만 복사하여 붙여넣기가 그렇게 빠르지 않을 때가 있습니다.
버퍼 내용을 기반으로 명령줄에서 텍스트를 자동 완성하는 방법이 있습니까?
답변1
생선 껍질
fzf-complete-from-tmux.sh
#!/bin/bash
tmux capture-pane -pS -100000 | # Dump the tmux buffer.
tac | # Reverse so duplicates use the first match.
pcregrep -o "[\w\d_\-\.\/]+" | # Extract the words.
awk '{ if (!seen[$0]++) print }' | # De-duplicate them with awk, then pass to fzf.
fzf --no-sort --exact +i # Pass to fzf for completion.
생선 껍질과 결합한 예입니다.
# Ctrl-N: Complete based on the tmux buffer content.
bind \cn "commandline -i (fzf-complete-from-tmux.sh) 2>/dev/null"
쿵쿵거리는 껍질
Bash 버전을 추가해 주신 @juanitocalero에게 감사드립니다.
#!/bin/bash
__screen-autocomplete__() {
tmux capture-pane -pS -100000 | # Dump the tmux buffer.
tac | # Reverse so duplicates use the first match.
grep -P -o "[\w\d_\-\.\/]+" | # Extract the words.
awk '{ if (!seen[$0]++) print }' | # De-duplicate them with awk, then pass to fzf.
fzf --no-sort --exact +i # Pass to fzf for completion.
}
__screen_autocomplete-inline__() {
local selected="$(__screen-autocomplete__)"
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
}
# Example binding with bash shell.
bind -x '"\C-n": "__screen_autocomplete-inline__"'