[英]How do I defer shell completion to another command in bash and zsh?
[英]piping zsh functions to another shell command
我正在嘗試以更通用的方式應用這種方法。 我采用了~/.zshrc
中的代碼如下:
27 │ irg() {
28 │ RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
29 │ INITIAL_QUERY="${*:-}"
30 ~ │ FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
31 ~ │ fzf --ansi \
32 ~ │ --color "hl:-1:underline,hl+:-1:underline:reverse" \
33 ~ │ --disabled --query "$INITIAL_QUERY" \
34 ~ │ --bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
35 ~ │ --bind "ctrl-f:unbind(change,ctrl-f)+change-prompt(2. fzf> )+enable-search+clear-query+rebind(ctrl-r)" \
36 ~ │ --bind "ctrl-r:unbind(ctrl-r)+change-prompt(1. ripgrep> )+disable-search+reload($RG_PREFIX {q} || true)+rebind(change,ctrl-f)" \
37 ~ │ --prompt '1. Ripgrep> ' \
38 ~ │ --delimiter : \
39 ~ │ --header '╱ CTRL-R (Ripgrep mode) ╱ CTRL-F (fzf mode) ╱' \
40 ~ │ --preview 'bat --color=always {1} --highlight-line {2}' \
41 ~ │ --preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
42 │ }
我想要的結果是使用 function 作為常規的 linux 命令,將 output 流水線化到其他一些實用程序,如下所示:
irg someReg | cat
irg someReg | cat
或irg someReg | code -r
irg someReg | code -r
顯然,這就是現在應該如何完成的,因為沒有使用 echo 的 output。 很感謝任何形式的幫助。
一個解決方案是像這樣使用命令替換:
code -r -g $(irg <pattern> | cut -d: -f1,2,3)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.