有时您想要输入屏幕上的文本,但复制粘贴速度并不那么快。
有没有办法根据缓冲区内容在命令行上自动完成文本?
答案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"
重击外壳
感谢@juanitocalero 添加了 bash 版本。
#!/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__"'