Skip to content

Instantly share code, notes, and snippets.

@yuki-yano
Created April 25, 2020 11:31
Show Gist options
  • Select an option

  • Save yuki-yano/371ceaacdc9db5045b49b5b8b774aadb to your computer and use it in GitHub Desktop.

Select an option

Save yuki-yano/371ceaacdc9db5045b49b5b8b774aadb to your computer and use it in GitHub Desktop.
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