You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fzrepl 584B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. declare cmd
  3. declare default_query
  4. declare stdin
  5. declare output
  6. OPTERR=0
  7. while getopts ':q:c:' opt; do
  8. case "$opt" in
  9. q) default_query="$OPTARG" ;;
  10. c) cmd="$OPTARG" ;;
  11. esac
  12. done
  13. shift $(( OPTIND - 1 ))
  14. unset opt OPTARG OPTIND
  15. if [[ -z $cmd || $cmd != *'{q}'* ]]; then
  16. echo '-c must be set and contain {q} somewhere'
  17. exit
  18. fi
  19. echo $default_query
  20. stdin=$(< /dev/stdin)
  21. output=$(fzf \
  22. --print-query \
  23. --query="$default_query" \
  24. --preview="$cmd <<< '$stdin'" \
  25. --preview-window='up:99%' \
  26. < /dev/null)
  27. echo "${cmd//\{q\}/\'$output\'}"