From e0d79e6c570d02f353039a0057f0e8036b6e6511 Mon Sep 17 00:00:00 2001 From: JP Appel Date: Sun, 1 Sep 2024 17:23:35 -0400 Subject: feat: zsh file browser + previewer --- fzf/fzfrc | 4 ++++ scripts/preview | 38 ++++++++++++++++++++++++++++++++++++++ zsh/zshfzf | 11 +++++++++++ 3 files changed, 53 insertions(+) create mode 100644 fzf/fzfrc create mode 100755 scripts/preview create mode 100644 zsh/zshfzf diff --git a/fzf/fzfrc b/fzf/fzfrc new file mode 100644 index 0000000..ae1f599 --- /dev/null +++ b/fzf/fzfrc @@ -0,0 +1,4 @@ +--color='fg:-1,bg:-1,hl:#438566' +--color='fg+:#cfc797,bg+:#003136,hl+:#7ba47d' +--color='info:#908b69,prompt:#732d35,pointer:#e4a44d' +--color='marker:#438566,spinner:#e4a44d,header:#7ba47d' diff --git a/scripts/preview b/scripts/preview new file mode 100755 index 0000000..2528082 --- /dev/null +++ b/scripts/preview @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +path="$1" +lines="$2" + +# TODO: if lines is undefined set to 40 +# TODO: truncate long output to lines + +[ ! -e "$path" ] && { echo "$path not found" ; exit 1; } + +filetype=$(file -b "$path") + +if grep -q "text" <<< "$filetype"; then + filetype="text" +elif grep -q "archive" <<< "$filetpye"; then + filetype="archive" +elif grep -q "ISO" <<< "$filetype" ; then + filetype="iso" +fi + +case $filetype in + "directory") + fd . "$path" + ;; + "text") + bat -p -r ":$lines" --color=always "$path" + ;; + "archive") + echo "archive preview not currently supported" + file -b "$path" + ;; + "iso") + isoinfo -l -i "$path" | head -n "$lines" + ;; + *) + file -b "$path" + ;; +esac diff --git a/zsh/zshfzf b/zsh/zshfzf new file mode 100644 index 0000000..ff6e061 --- /dev/null +++ b/zsh/zshfzf @@ -0,0 +1,11 @@ +source <(fzf --zsh) + +fzf_widget() { + BUFFER=$(fd | fzf --multi --scheme=path\ + --preview 'preview {} $FZF_PREVIEW_LINES' --preview-label='File Preview') + CURSOR=$#BUFFER + zle redisplay +} +zle -N fzf_widget + +bindkey '^f' fzf_widget -- cgit v1.2.3