josean-dev / dev-environment-files

2.98k stars 800 forks source link

Issue: [bat error]: 'Folder' is a directory #63

Closed PtrckM closed 5 months ago

PtrckM commented 5 months ago

Getting an error [bat error]: 'folder' is a directory. when viewing a folder and not showing folder contents like said on the video tutorial made when using cd ** image

PtrckM commented 5 months ago

Reference: https://github.com/sharkdp/bat/issues/1940

josean-dev commented 5 months ago

Hello! I've just fixed this (d48a879e2e32) with this slight change so that we check first if it's a directory or not. If it is, we use eza, if it isn't we use bat.

show_file_or_dir_preview="if [ -d {} ]; then eza --tree --color=always {} | head -200; else bat -n --color=always --line-range :500 {}; fi"

export FZF_CTRL_T_OPTS="--preview '$show_file_or_dir_preview'"
export FZF_ALT_C_OPTS="--preview 'eza --tree --color=always {} | head -200'"

# Advanced customization of fzf options via _fzf_comprun function
# - The first argument to the function is the name of the command.
# - You should make sure to pass the rest of the arguments to fzf.
_fzf_comprun() {
  local command=$1
  shift

  case "$command" in
    cd)           fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;;
    export|unset) fzf --preview "eval 'echo \${}'"         "$@" ;;
    ssh)          fzf --preview 'dig {}'                   "$@" ;;
    *)            fzf --preview "$show_file_or_dir_preview" "$@" ;;
  esac
}
josean-dev commented 5 months ago

Thanks for the feedback!

PtrckM commented 5 months ago

❤️ works very smooth now.. thank you so much!!! very fast resp!!! 🙌

earn a lifetime subscriber on both gh and yt 😍

josean-dev commented 5 months ago

That means a lot! Love the change on my setup too. Thanks again!!