Created
April 25, 2020 11:31
-
-
Save yuki-yano/371ceaacdc9db5045b49b5b8b774aadb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fzf-translate() { | |
| local out snippet key file candidate fzf_command command | |
| fzf_command="fzf --multi --phony --print-query --expect=ctrl-m,ctrl-q --bind=\"change:reload:echo '{q}' | nextword | tr ' ' '\n' | xargs -I WORD echo 'WORD' \" --preview='google-trans {q}'" | |
| IFS=$'\n' out=$(eval "echo '' | ${fzf_command}") | |
| while true; do | |
| query=$(echo "$out" | head -1) | |
| key=$(echo "$out" | head -2 | tail -1) | |
| select=$(echo "$out" | head -3 | tail -1) | |
| if [[ $key == "ctrl-q" ]]; then | |
| return | |
| else | |
| out=$(eval "echo "${query}${select}" | nextword | tr ' ' '\n' | ${fzf_command} --query='${query}${select}'") | |
| fi | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment