1
0
mirror of https://github.com/XNM1/linux-nixos-hyprland-config-dotfiles.git synced 2025-09-15 09:45:58 +03:00

fish scripts update

changelog:
- refactored fzf scripts
- nullify unused\remapped fzf bindings
- `list-op.fish` hotfix 3
- added `hexyl` package to the system
This commit is contained in:
xnm
2024-10-13 23:07:17 +03:00
parent 6b3fa50ae4
commit 59ea19d35d
10 changed files with 57 additions and 4 deletions

View File

@@ -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

View File

@@ -0,0 +1,4 @@
function dir-preview
set dir "$argv[1]"
lsd --tree --depth=1 --color=always --icon=always --icon-theme=fancy "$dir"
end

View File

@@ -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

View File

@@ -8,6 +8,10 @@ function fish_user_key_bindings
# The argument specifies the initial mode (insert, "default" or visual). # The argument specifies the initial mode (insert, "default" or visual).
fish_vi_key_bindings --no-erase insert 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 \er fzf-history-widget -M insert
bind \ef fzf-file-preview-widget -M insert bind \ef fzf-file-preview-widget -M insert
bind \ec fzf-cd-preview-widget -M insert bind \ec fzf-cd-preview-widget -M insert

View File

@@ -1,5 +1,5 @@
function fzf-cd-preview-widget 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" if test -n "$selected_dir"
cd "$selected_dir" cd "$selected_dir"

View File

@@ -1,4 +1,4 @@
function fzf-file-preview-widget 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 commandline -f repaint
end end

View File

@@ -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

View File

@@ -1,6 +1,6 @@
function list-op function list-op
echo \n echo \n
lsd -al lsd -Alg
echo "" echo \n\n
commandline -f repaint commandline -f repaint
end end

View File

@@ -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

View File

@@ -41,6 +41,7 @@
tokei tokei
fzf fzf
bat bat
hexyl
mdcat mdcat
pandoc pandoc
lsd lsd