#!/bin/sh
#
# fed - open the selected file with the default editor

files=$(
  fzf --query="$1" \
    --multi \
    --select-1 \
    --exit-0 \
    --bind=ctrl-x:toggle-sort \
    --header='(view:ctrl-v) (sort:ctrl-x)' \
    --preview-window=':nohidden,right:65%:wrap' \
    --preview='([ -f {} ] && (bat --style=numbers --color=always {})) \
        || ([ -d {} ] && (eza -TL 3 --color=always --icons {} | less)) \
        || echo {} 2> /dev/null | head -200'
)
[ -n "${files-}" ] && ${EDITOR:-vim} "${files-*}"
