fzf.sh 641 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. SCRIPT_NAME="${0##*/}"
  4. display_help() {
  5. echo "Usage: ${SCRIPT_NAME} <bat, chafa, audio>"
  6. echo "Dependencies: fzf, bat, chafa, ffplay"
  7. echo "Example:"
  8. echo "- ${SCRIPT_NAME} bat"
  9. echo "- ${SCRIPT_NAME} chafa"
  10. exit 2
  11. }
  12. [[ $# -lt 1 ]] && display_help
  13. action="$1"
  14. CMD="fzf --preview"
  15. run_fzf(){
  16. rest="${*}"
  17. $CMD "${rest} {}"
  18. }
  19. case "$action" in
  20. bat) params=bat ;;
  21. chafa) params=chafa ;;
  22. audio) params="ffplay -nodisp -autoexit"
  23. # params='mpv --no-audio-display'
  24. ;;
  25. *) display_help ;;
  26. esac
  27. run_fzf "$params"