fzf-action.sh 789 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SCRIPT_NAME="${0##*/}"
  4. # # i have this defined in ~/.bash_profile
  5. # FZF_DEFAULT_COMMAND="locate \$(pwd)"; export FZF_DEFAULT_COMMAND
  6. # export FZF_DEFAULT_OPTS="--layout=reverse --height 40%"
  7. display_help() {
  8. echo "Usage: ${SCRIPT_NAME} <action>"
  9. echo "Dependencies: fzf fzy"
  10. echo "Examples:"
  11. echo "- ${SCRIPT_NAME} run"
  12. echo "Available actions:"
  13. echo "- run"
  14. exit 2
  15. }
  16. fzf_cmd(){
  17. file="$(fzf)"
  18. # file="$(find -mount | fzy)"
  19. if [[ -f $file && $(file -b --mime-type "${file}") == 'text/plain' ]]; then
  20. cd "$(dirname "${file}")"
  21. $EDITOR "$file"
  22. elif [[ -d $file ]]; then
  23. cd "$file"
  24. fi
  25. file "$file"
  26. }
  27. if [[ "${1:-}" == 'run' ]]; then
  28. fzf_cmd
  29. else
  30. display_help
  31. fi