diff --git a/home/.config/fish/functions/archive-preview.fish b/home/.config/fish/functions/archive-preview.fish new file mode 100644 index 0000000..982e637 --- /dev/null +++ b/home/.config/fish/functions/archive-preview.fish @@ -0,0 +1,11 @@ +function archive-preview + set archive "$argv[1]" + set supported_archive_formats tar.gz tar.bz2 tar.xz zip rar 7z + + for format in $supported_archive_formats + if string match -q "application/$format" (file -b --mime-type "$archive") + ouch list --tree --no "$archive" + exit 0 + end + end +end diff --git a/home/.config/fish/functions/dir-preview.fish b/home/.config/fish/functions/dir-preview.fish new file mode 100644 index 0000000..4c38729 --- /dev/null +++ b/home/.config/fish/functions/dir-preview.fish @@ -0,0 +1,4 @@ +function dir-preview + set dir "$argv[1]" + lsd --tree --depth=1 --color=always --icon=always --icon-theme=fancy "$dir" +end diff --git a/home/.config/fish/functions/file-preview.fish b/home/.config/fish/functions/file-preview.fish new file mode 100644 index 0000000..bef3712 --- /dev/null +++ b/home/.config/fish/functions/file-preview.fish @@ -0,0 +1,4 @@ +function file-preview + set file "$argv[1]" + bat --color=always --style=numbers,header-filesize,grid --line-range=:15 --wrap=auto "$file" +end diff --git a/home/.config/fish/functions/fish_user_key_bindings.fish b/home/.config/fish/functions/fish_user_key_bindings.fish index 52fc046..e4f6908 100644 --- a/home/.config/fish/functions/fish_user_key_bindings.fish +++ b/home/.config/fish/functions/fish_user_key_bindings.fish @@ -8,6 +8,10 @@ function fish_user_key_bindings # The argument specifies the initial mode (insert, "default" or visual). fish_vi_key_bindings --no-erase insert + # Nullify fzf default keybindings + bind \cT '' -M insert + bind \cR '' -M insert + bind \er fzf-history-widget -M insert bind \ef fzf-file-preview-widget -M insert bind \ec fzf-cd-preview-widget -M insert diff --git a/home/.config/fish/functions/fzf-cd-preview-widget.fish b/home/.config/fish/functions/fzf-cd-preview-widget.fish index 38e31f9..47335d0 100644 --- a/home/.config/fish/functions/fzf-cd-preview-widget.fish +++ b/home/.config/fish/functions/fzf-cd-preview-widget.fish @@ -1,5 +1,5 @@ function fzf-cd-preview-widget - set selected_dir (fd --type d --hidden --no-ignore --exclude .git --exclude .direnv | fzf --height 40% --reverse --preview 'lsd --tree --depth=1 {}' --preview-window=right:40%) + set selected_dir (fd --type d --hidden --no-ignore --exclude .git --exclude .direnv | fzf --height 40% --reverse --preview 'dir-preview {}' --preview-window=right:40%) if test -n "$selected_dir" cd "$selected_dir" diff --git a/home/.config/fish/functions/fzf-file-preview-widget.fish b/home/.config/fish/functions/fzf-file-preview-widget.fish index 53b39f8..dce458c 100644 --- a/home/.config/fish/functions/fzf-file-preview-widget.fish +++ b/home/.config/fish/functions/fzf-file-preview-widget.fish @@ -1,4 +1,4 @@ function fzf-file-preview-widget - commandline -i (fd --hidden --no-ignore --exclude .git --exclude .direnv | fzf --height 40% --preview-window=right:40% --reverse --preview "test -f {}; and file {} | grep -q text; and bat --color=always --style=numbers --line-range=:500 --wrap=auto {}; or echo 'Preview unavailable for binary files and directories'") + commandline -i (fd --hidden --no-ignore --exclude .git --exclude .direnv | fzf --height 40% --preview-window=right:40% --reverse --preview 'switch-preview {}') commandline -f repaint end diff --git a/home/.config/fish/functions/image-preview.fish b/home/.config/fish/functions/image-preview.fish new file mode 100644 index 0000000..99b8972 --- /dev/null +++ b/home/.config/fish/functions/image-preview.fish @@ -0,0 +1,9 @@ +function image-preview + set image "$argv[1]" + + # Retrieve the current terminal dimensions and reduce them slightly to avoid boundary issues + set term_width (math (tput cols) - 1) + set term_height (math (tput lines) - 1) + + chafa "$image" --size="$term_width"x"$term_height" +end diff --git a/home/.config/fish/functions/list-op.fish b/home/.config/fish/functions/list-op.fish index 39b8820..14a74e8 100644 --- a/home/.config/fish/functions/list-op.fish +++ b/home/.config/fish/functions/list-op.fish @@ -1,6 +1,6 @@ function list-op echo \n - lsd -al - echo "" + lsd -Alg + echo \n\n commandline -f repaint end diff --git a/home/.config/fish/functions/switch-preview.fish b/home/.config/fish/functions/switch-preview.fish new file mode 100644 index 0000000..361a039 --- /dev/null +++ b/home/.config/fish/functions/switch-preview.fish @@ -0,0 +1,20 @@ +function switch-preview + set path "$argv[1]" + + if test -f "$path" + if test ! -s "$path" + echo "File is empty" + else + archive-preview "$path" + if string match -q "image/*" (file -b --mime-type "$path") + image-preview "$path" + else + file-preview "$path" + end + end + else if test -d "$path" + dir-preview "$path" + else + echo "Preview unavailable" + end +end diff --git a/nixos/terminal-utils.nix b/nixos/terminal-utils.nix index cce953c..91f176e 100644 --- a/nixos/terminal-utils.nix +++ b/nixos/terminal-utils.nix @@ -41,6 +41,7 @@ tokei fzf bat + hexyl mdcat pandoc lsd