find-and-run.sh 480 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. display_help(){
  4. echo "Usage: ${0##*/} [patterns]"
  5. exit 2
  6. }
  7. error() {
  8. echo "$0: $*" >&2
  9. exit 1
  10. }
  11. [[ $# -lt 1 ]] && display_help
  12. # FZF_DEFAULT_COMMAND="fdfind --ignore-file=${HOME}/.fdignore"
  13. # FZF_DEFAULT_OPTS="--layout=reverse --height 40%"
  14. actions=(vim nvim cd emacs 'emacsclient -a "" -c')
  15. file_or_dir="$(locate -i "${*}" | fzy)"
  16. action=$(printf "%s\n" "${actions[@]}" | fzy)
  17. $action "$file_or_dir"