From fc7ace626fc8dec5bb3ba692141a344c7b096e87 Mon Sep 17 00:00:00 2001 From: mintycube <90507714+mintycube@users.noreply.github.com> Date: Thu, 30 May 2024 12:32:00 +0500 Subject: [PATCH] Improve fuz script with cache --- .config/nvim/lazy-lock.json | 59 +++++++------ .config/nvim/lua/plugins/doc.lua | 33 +------ .config/x11/xprofile | 2 +- .config/zsh/.zshrc | 6 +- .local/bin/fuz | 102 +++++++++------------- .local/bin/fuz-cache | 45 ++++++++++ .local/bin/fuz-opener | 42 +++++++++ .local/bin/fuz-preview | 145 +++++++++++++++++++++++++++++++ .local/bin/fzf-grep | 2 +- 9 files changed, 310 insertions(+), 126 deletions(-) create mode 100755 .local/bin/fuz-cache create mode 100755 .local/bin/fuz-opener create mode 100755 .local/bin/fuz-preview diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index 103ce58..8744779 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -1,6 +1,6 @@ { "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, - "LuaSnip": { "branch": "master", "commit": "de1a287c9cb525ae52bc846e8f6207e5ef1da5ac" }, + "LuaSnip": { "branch": "master", "commit": "878ace11983444d865a72e1759dbcc331d1ace4c" }, "alpha-nvim": { "branch": "main", "commit": "41283fb402713fc8b327e60907f74e46166f4cfd" }, "cmp-async-path": { "branch": "main", "commit": "7df7f3721c45aac26b6e0474087538f4681c9c7a" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, @@ -10,56 +10,55 @@ "cmp-vimtex": { "branch": "master", "commit": "a64b1b5eec0460144c91c4f20a45c74b8ded48ae" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, "flit.nvim": { "branch": "main", "commit": "56490317983218b09698f8c960c3669958b12b32" }, - "friendly-snippets": { "branch": "main", "commit": "dd2fd1281d4b22e7b4a5bfafa3e142d958e251f2" }, - "fzf-lua": { "branch": "main", "commit": "677055fc5793ad6d52dac89957c8b015fc74de55" }, - "gitsigns.nvim": { "branch": "main", "commit": "805610a9393fa231f2c2b49cb521bfa413fadb3d" }, + "friendly-snippets": { "branch": "main", "commit": "d0610077b6129cf9f7f78afbe3a1425d60f6e2f1" }, + "fzf-lua": { "branch": "main", "commit": "b92220ec838c195eb1c711daa69c905b1d7b8d8c" }, + "gitsigns.nvim": { "branch": "main", "commit": "75dc649106827183547d3bedd4602442340d2f7f" }, "harpoon": { "branch": "harpoon2", "commit": "0378a6c428a0bed6a2781d459d7943843f374bce" }, - "indent-blankline.nvim": { "branch": "master", "commit": "ece00d5fb44d196680a81fd2761062d2fa44663b" }, - "lazy.nvim": { "branch": "main", "commit": "0de782a6b0ffba599dbd332a4019d852564bf28c" }, - "leap.nvim": { "branch": "main", "commit": "b1ecfb63c0b8babfd0dcd6b5ca6de37bbf3526cd" }, + "indent-blankline.nvim": { "branch": "master", "commit": "d98f537c3492e87b6dc6c2e3f66ac517528f406f" }, + "lazy.nvim": { "branch": "main", "commit": "24fa2a97085ca8a7220b5b078916f81e316036fd" }, + "leap.nvim": { "branch": "main", "commit": "f6cfd526ebaf56f005cca6a4a4735a854172982e" }, "lf.nvim": { "branch": "master", "commit": "69ab1efcffee6928bf68ac9bd0c016464d9b2c8b" }, - "lsp-zero.nvim": { "branch": "v3.x", "commit": "f12d50716e8e59ea9f5cf484eac6968c33a95917" }, + "lsp-zero.nvim": { "branch": "v3.x", "commit": "16de3b18c5f7b6230d89b8e64ce9a4801b6f8d08" }, "lspkind.nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" }, - "luarocks.nvim": { "branch": "main", "commit": "d3dda396d66e484590f253d1ac6d8980e3130807" }, + "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, "luasnip-latex-snippets.nvim": { "branch": "main", "commit": "4b91f28d91979f61a3e8aef1cee5b7c7f2c7beb8" }, "markdown-preview.nvim": { "branch": "main", "commit": "462ce41af003f5cdadab856f3a42dc27e39b89c8" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "a4caa0d083aab56f6cd5acf2d42331b74614a585" }, "mason-nvim-dap.nvim": { "branch": "main", "commit": "67210c0e775adec55de9826b038e8b62de554afc" }, "mason.nvim": { "branch": "main", "commit": "49ff59aded1047a773670651cfa40e76e63c6377" }, - "mini.ai": { "branch": "main", "commit": "a0262e61f79dfc7bb940d1719c00b0ede042ddd7" }, - "mini.statusline": { "branch": "main", "commit": "dfd3d2ba295473930f78f143852b9b53eb54ae2a" }, - "mini.surround": { "branch": "main", "commit": "c52aa751daf62d4a9e6ee24c4a91882ef6842f99" }, - "none-ls.nvim": { "branch": "main", "commit": "37671797d6e5f9bd0ee3ab965ab2e6de251e1930" }, + "mini.ai": { "branch": "main", "commit": "7859b6344f5cee567a94f173859d25e20ba1a77e" }, + "mini.surround": { "branch": "main", "commit": "27096c1a27324ee8f2044ea2adc77366d8a782de" }, + "none-ls.nvim": { "branch": "main", "commit": "f5b960a73418249aebcdae3455de320360509253" }, "nvim-autopairs": { "branch": "master", "commit": "c15de7e7981f1111642e7e53799e1211d4606cb9" }, "nvim-cmp": { "branch": "main", "commit": "5260e5e8ecadaf13e6b82cf867a909f54e15fd07" }, "nvim-colorizer.lua": { "branch": "master", "commit": "85855b38011114929f4058efc97af1059ab3e41d" }, - "nvim-dap": { "branch": "master", "commit": "5a2f7121869394502521c52b2bc581ab22c69447" }, - "nvim-dap-ui": { "branch": "master", "commit": "5934302d63d1ede12c0b22b6f23518bb183fc972" }, - "nvim-dap-virtual-text": { "branch": "master", "commit": "3e8e207513e6ef520894950acd76b79902714103" }, + "nvim-dap": { "branch": "master", "commit": "abb238f631609ea4be496ba7946f4f3aaec86c6a" }, + "nvim-dap-ui": { "branch": "master", "commit": "b7267003ba4dd860350be86f75b9d9ea287cedca" }, + "nvim-dap-virtual-text": { "branch": "master", "commit": "d7c695ea39542f6da94ee4d66176f5d660ab0a77" }, "nvim-html-css": { "branch": "main", "commit": "c514bd27ad560636ed39dea3e370b3103754e244" }, - "nvim-lspconfig": { "branch": "master", "commit": "9bda20fb967075355f253911bc066a8b5a03c77e" }, + "nvim-lspconfig": { "branch": "master", "commit": "38de86f82efd9ba0881203767d6a8e1815abca28" }, "nvim-markdown": { "branch": "master", "commit": "75639723c1a3a44366f80cff11383baf0799bcb5" }, - "nvim-nio": { "branch": "master", "commit": "8765cbc4d0c629c8158a5341e1b4305fd93c3a90" }, - "nvim-spectre": { "branch": "master", "commit": "50e96602153f14c913e1969aaf9720e080394eb3" }, - "nvim-treesitter": { "branch": "master", "commit": "7c9c5bed8340031f8a6dad47a58a26eaf15b9a56" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "5f9bf4b1ead7707e4e74e5319ee56bdc81fb73db" }, - "nvim-ts-autotag": { "branch": "main", "commit": "cb57b07803476ee902c89412aeff219a9a58be13" }, - "nvim-ts-context-commentstring": { "branch": "main", "commit": "cbab9ad88036915beebd13b47e100743ff2ed2d5" }, - "nvim-ufo": { "branch": "main", "commit": "4b4077850d1b3af09f4957b67144943cf3da401a" }, - "nvim-web-devicons": { "branch": "master", "commit": "e37bb1feee9e7320c76050a55443fa843b4b6f83" }, - "outline.nvim": { "branch": "main", "commit": "139e363dd5a44f66a51041264aabe3884df4dd98" }, + "nvim-nio": { "branch": "master", "commit": "632024157d01e8bc48fd7df6a7de8ffe3fdd4f3a" }, + "nvim-spectre": { "branch": "master", "commit": "366f46fdd4a1593cc237aea13d5ef113739a472c" }, + "nvim-treesitter": { "branch": "master", "commit": "b91ae14fc3bb801c7ea69bc283fe860b32b5163d" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "3557e41418b4a6c5b85d5d64abe94c9c50fa9b14" }, + "nvim-ts-autotag": { "branch": "main", "commit": "bcf3146864262ef2d3c877beba3e222b5c73780d" }, + "nvim-ts-context-commentstring": { "branch": "main", "commit": "cb064386e667def1d241317deed9fd1b38f0dc2e" }, + "nvim-ufo": { "branch": "main", "commit": "65dda6360879f6ffe0278163b9192a573a0d2a08" }, + "nvim-web-devicons": { "branch": "master", "commit": "b77921fdc44833c994fdb389d658ccbce5490c16" }, + "outline.nvim": { "branch": "main", "commit": "6a91568110684ac056e62e3b2d7409d7c8b2e5e1" }, "oxocarbon.nvim": { "branch": "main", "commit": "c5846d10cbe4131cc5e32c6d00beaf59cb60f6a2" }, "persistence.nvim": { "branch": "main", "commit": "5fe077056c821aab41f87650bd6e1c48cd7dd047" }, - "plenary.nvim": { "branch": "master", "commit": "b5c8de02a44ffeabff678090edd6a132ff8ab77d" }, + "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, "project.nvim": { "branch": "main", "commit": "8c6bad7d22eef1b71144b401c9f74ed01526a4fb" }, "promise-async": { "branch": "main", "commit": "93540c168c5ed2b030ec3e6c40ab8bbb85e36355" }, "qalc.nvim": { "branch": "main", "commit": "1b800b5d8f956c4780f079333cba4d8fb8c335a3" }, "refactoring.nvim": { "branch": "master", "commit": "d2786877c91aa409c824f27b4ce8a9f560dda60a" }, - "rose-pine": { "branch": "main", "commit": "b6fe88c3282cf9f117a3e836d761c2d78d02f417" }, - "todo-comments.nvim": { "branch": "main", "commit": "a7e39ae9e74f2c8c6dc4eea6d40c3971ae84752d" }, + "rose-pine": { "branch": "main", "commit": "87aa437172357ad8f916942bca249ceadc6c68b1" }, + "todo-comments.nvim": { "branch": "main", "commit": "e1549807066947818113a7d7ed48f637e49620d3" }, "toggleterm.nvim": { "branch": "main", "commit": "fee58a0473fd92b28c34f8f724e4918b15ba30a3" }, "tokyodark.nvim": { "branch": "master", "commit": "ba538ab69e8a4e3ebac127734b7deff9e7462463" }, - "tokyonight.nvim": { "branch": "main", "commit": "7fc18e82575f5b482b758b6dddfe97b606819a20" }, + "tokyonight.nvim": { "branch": "main", "commit": "0fae425aaab04a5f97666bd431b96f2f19c36935" }, "trouble.nvim": { "branch": "main", "commit": "a8264a65a0b894832ea642844f5b7c30112c458f" }, "undotree": { "branch": "main", "commit": "eab459ab87dd249617b5f7187bb69e614a083047" }, "vim-be-good": { "branch": "master", "commit": "4fa57b7957715c91326fcead58c1fa898b9b3625" }, diff --git a/.config/nvim/lua/plugins/doc.lua b/.config/nvim/lua/plugins/doc.lua index a091e21..1e2ceea 100644 --- a/.config/nvim/lua/plugins/doc.lua +++ b/.config/nvim/lua/plugins/doc.lua @@ -73,36 +73,5 @@ return { vim.g.vimtex_compiler_method = "tectonic" -- vim.cmd("call vimtex#init()") end, - }, - { - "vhyrro/luarocks.nvim", - priority = 1000, - config = true, - }, - { - "nvim-neorg/neorg", - enabled = false, - dependencies = { "luarocks.nvim" }, - lazy = false, -- Disable lazy loading as some `lazy.nvim` distributions set `lazy = true` by default - version = "*", -- Pin Neorg to the latest stable release - config = function() - require("neorg").setup { - load = { - ["core.defaults"] = {}, - ["core.concealer"] = {}, - ["core.dirman"] = { - config = { - workspaces = { - notes = "~/notes", - }, - default_workspace = "notes", - }, - }, - }, - } - - vim.wo.foldlevel = 99 - vim.wo.conceallevel = 2 - end, - }, + } } diff --git a/.config/x11/xprofile b/.config/x11/xprofile index dc11d36..e212de8 100755 --- a/.config/x11/xprofile +++ b/.config/x11/xprofile @@ -11,7 +11,7 @@ xrdbpid=$! # Uncomment to use Xresources colors/settings on startup pidof -sx dunst || dunst -config "${XDG_CONFIG_HOME:-$HOME/.config}"/dunst/config & -autostart="mpd pipewire unclutter remapd clipmenud" +autostart="mpd pipewire unclutter remapd clipmenud fuz-cache" for program in $autostart; do pidof -sx "$program" || "$program" & diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index e3aaf5f..d0e8e4e 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -44,6 +44,7 @@ z4h init || return # Extend PATH. export PATH="$PATH:${$(find ~/.local/bin -type d -printf %p:)%%:}" export PATH=$PATH:~/.local/share/npm/bin +export PATH=$PATH:~/.local/share/nvim/mason/bin # Export environment variables. export GPG_TTY=$TTY @@ -53,8 +54,7 @@ export TERMINAL_PROG="st" export BROWSER="firefox" export MANPAGER="nvim +Man!" export XDG_SESSION_TYPE="x11" -export FZF_DEFAULT_OPTS="--height=50% --reverse --info=inline-right \ ---height=100% --prompt='  ' --pointer=' ' --ellipsis='' --border=horizontal" +export FZF_DEFAULT_OPTS="--height=50% --reverse --prompt='  ' --pointer=' ' --ellipsis='' --color='16'" # ~/ Clean-up: export XDG_CONFIG_HOME="$HOME/.config" @@ -140,6 +140,8 @@ function lfcd () { function md() { [[ $# == 1 ]] && mkdir -p -- "$1" && cd -- "$1" } compdef _directories md +eval "$(navi widget zsh)" + # Set shell options: http://zsh.sourceforge.net/Doc/Release/Options.html. unsetopt PROMPT_SP setopt glob_dots diff --git a/.local/bin/fuz b/.local/bin/fuz index 03d2bed..83a47aa 100755 --- a/.local/bin/fuz +++ b/.local/bin/fuz @@ -1,67 +1,49 @@ #!/usr/bin/env bash -echo -ne '\e[3 q' # Use underline shape cursor on startup. -eval "$(dircolors --sh)" # Setup correct colors +# Populated by fuz-cache script through xprofile at startup +CACHE_DIR="/tmp/fuz_cache" + +# Define color escape sequences +c_blue='' +c_gray='' +c_norm='' +h_padding=$(printf '%*s' 23 ' ') +h_gap=" ${c_gray}::" + +# Define the header using the escape sequences +HEADER="${h_padding}\ + ${c_blue}Prefix${c_gray}:${c_norm}Alt${h_gap}\ + ${c_blue}1${c_gray}:${c_norm}All/Folders/Git${h_gap}\ + ${c_blue}2${c_gray}:${c_norm}Documents${h_gap}\ + ${c_blue}3${c_gray}:${c_norm}Images${h_gap}\ + ${c_blue}4${c_gray}:${c_norm}Videos" + +# --bind "alt-1:transform:[[ ! \$FZF_PROMPT =~ All ]] && +# echo 'change-prompt( All  )+reload(cat $CACHE_DIR/all)' || +# echo 'change-prompt( Folders  )+reload(cat $CACHE_DIR/folders)'" \ +fzf_main_func() { + cat $CACHE_DIR/all | fzf --ansi --prompt " All  " \ + --bind "alt-1:transform:( + ([[ \$FZF_PROMPT =~ All ]] && echo 'change-prompt( Folders  )+reload(cat $CACHE_DIR/folders)') || + ([[ \$FZF_PROMPT =~ Folders ]] && echo 'change-prompt( Git  )+reload(cat $CACHE_DIR/git)') || + echo 'change-prompt( All  )+reload(cat $CACHE_DIR/all)')" \ + --bind "alt-2:change-prompt( Documents  )+reload(cat $CACHE_DIR/documents)" \ + --bind "alt-3:change-prompt( Images  )+reload(cat $CACHE_DIR/images)" \ + --bind "alt-4:change-prompt( Videos  )+reload(cat $CACHE_DIR/videos)" \ + --header "$HEADER" \ + --height=100% --pointer=" " --ellipsis= --header-first --scheme=path --algo=v2 --color="16" \ + --preview-window "bottom,60%,border-top" --border=none --margin=5%,10%,5%,10% --info=inline-right \ + --preview "fuz-preview {}" +} + +echo -ne '\e[3 q' # Use underline shape cursor on startup. dwmc setlayoutex 2 -selection=$(fd --hidden --color=always -E .cache -E .git -E \*github\* -E .local/state -E .ssh -E .android -E GIMP -E Thunar -E .config/blender -E .config/mpv/script_modules -E .config/mpv/scripts -E .config/tmux/plugins -E fontforge -E fzf-tab-completion -E .gnupg -E libreoffice -E node_modules -E \*obsidian -E qBittorrent -E subversion -E \*terminfo | - fzfp --ansi --prompt " All  " \ - --bind "alt-1:transform:[[ ! \$FZF_PROMPT =~ All ]] && - echo 'change-prompt( All  )+reload(fd --hidden --color=always -E .cache -E .git -E \*github\* -E .local/state -E .ssh -E .android -E GIMP -E Thunar -E .config/blender -E .config/mpv/script_modules -E .config/mpv/scripts -E .config/tmux/plugins -E fontforge -E fzf-tab-completion -E .gnupg -E libreoffice -E node_modules -E \*obsidian -E qBittorrent -E subversion -E \*terminfo)' || - echo 'change-prompt( Folders  )+reload(fd --color=always --hidden --type directory -E .cache -E .git -E \*github\* -E .local/state -E .ssh -E .android -E GIMP -E Thunar -E .config/blender -E .config/mpv/script_modules -E .config/mpv/scripts -E .config/tmux/plugins -E fontforge -E fzf-tab-completion -E .gnupg -E libreoffice -E node_modules -E \*obsidian -E qBittorrent -E subversion -E \*terminfo)'" \ - --bind "alt-2:change-prompt( Git  )+reload( fd --color=always -HI '^.git$' --type d --base-directory ~ -E .cache -E \*github\* -E .local/state -E .ssh -E .android -E GIMP -E Thunar -E .config/blender -E .config/mpv/script_modules -E .config/mpv/scripts -E .config/tmux/plugins -E fontforge -E fzf-tab-completion -E .gnupg -E libreoffice -E node_modules -E \*obsidian -E qBittorrent -E subversion -E \*terminfo | sed 's|\\[1\;34m\.git\\[0m\\[1\;34m\/\\[0m||')" \ - --bind "alt-3:change-prompt( Documents  )+reload(fd --color=always --hidden -e pdf -e epub -e djvu -E .cache -E .git -E \*github\* -E .local/state -E .ssh -E .android -E GIMP -E Thunar -E .config/blender -E .config/mpv/script_modules -E .config/mpv/scripts -E .config/tmux/plugins -E fontforge -E fzf-tab-completion -E .gnupg -E libreoffice -E node_modules -E \*obsidian -E qBittorrent -E subversion -E \*terminfo)" \ - --bind "alt-4:change-prompt( Images  )+reload(fd --color=always --hidden -e jpg -e jpg -e jpeg -e png -e webp -e bmp -e tiff -e tif -e raw -e ico -e exif -e heic -e heif -e gif -e avif -e jxl -e JPG -e PNG -E .cache -E .git -E \*github\* -E .local/state -E .ssh -E .android -E GIMP -E Thunar -E .config/blender -E .config/mpv/script_modules -E .config/mpv/scripts -E .config/tmux/plugins -E fontforge -E fzf-tab-completion -E .gnupg -E libreoffice -E node_modules -E \*obsidian -E qBittorrent -E subversion -E \*terminfo)" \ - --bind "alt-5:change-prompt( Videos  )+reload(fd --color=always --hidden -e mkv -e mp4 -e mkv -e webm -e avi -E .cache -E .git -E \*github\* -E .local/state -E .ssh -E .android -E GIMP -E Thunar -E .config/blender -E .config/mpv/script_modules -E .config/mpv/scripts -E .config/tmux/plugins -E fontforge -E fzf-tab-completion -E .gnupg -E libreoffice -E node_modules -E \*obsidian -E qBittorrent -E subversion -E \*terminfo)" \ - --header "  Prefix:Alt :: 1:All/Folders :: 2:Git :: 3:Documents :: 4:Images :: 5:Videos" \ - --height=100% --pointer=" " --ellipsis= --info=inline-right --header-first --scheme=path --algo=v2 --color="16" \ - --preview-window "bottom,60%,border-top" --border=none --margin=5%,10%,5%,10% \ - --preview "fuz-preview {}") +selection=$(fzf_main_func) - # --color="fg:#c0caf5,bg:#16161e,hl:#ff9e64" \ - # --color="fg+:#c0caf5,bg+:#292e42,hl+:#ff9e64" \ - # --color="info:#7aa2f7,prompt:#7dcfff,pointer:#7dcfff" \ - # --color="marker:#9ece6a,spinner:#9ece6a,header:#9ece6a,border:#292e42" \ - - -[ -n "$selection" ] && - case $(file --mime-type "$(readlink -f "$selection")" -b) in - image/vnd.djvu | application/pdf | application/postscript | application/epub*) zathura "$selection" >/dev/null 2>&1 ;; - text/html) nvim "$selection" ;; - text/* | application/json | inode/x-empty | application/x-subrip | application/javascript) nvim "$selection" ;; - image/x-xcf) gimp "$selection" >/dev/null 2>&1 ;; - image/svg+xml) display -- "$selection" ;; - image/*) - shopt -s nullglob - dir="$(dirname "$selection")" - selected_file="$selection" - images=() - for file in "$dir"/*.{jpg,jpeg,png,webp,bmp,tiff,tif,raw,ico,exif,heic,heif,gif,avif,jxl,JPG,PNG}; do - [[ -f "$file" ]] && images+=("$file") - done - sorted_images=() - while IFS= read -r line; do - sorted_images+=("$line") - done < <(printf "%s\n" "${images[@]}" | sort -fV) - for ((i = 0; i < ${#sorted_images[@]}; i++)); do - [[ "${sorted_images[i]}" = "$selected_file" ]] && { - setsid nsxiv -aon "$((i + 1))" "${sorted_images[@]}" - break - } - done - ;; - audio/* | video/x-ms-asf) mpv --loop-file --profile=builtin-pseudo-gui "$selection" ;; - video/*) mpv --loop-file "$selection" -quiet >/dev/null 2>&1 ;; - application/pgp-encrypted) nvim "$selection" ;; - application/vnd.openxmlformats-officedocument.wordprocessingml.document | application/vnd.oasis.opendocument.text | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | application/vnd.oasis.opendocument.spreadsheet | application/vnd.oasis.opendocument.spreadsheet-template | application/vnd.openxmlformats-officedocument.presentationml.presentation | application/vnd.oasis.opendocument.presentation-template | application/vnd.oasis.opendocument.presentation | application/vnd.ms-powerpoint | application/vnd.oasis.opendocument.graphics | application/vnd.oasis.opendocument.graphics-template | application/vnd.oasis.opendocument.formula | application/vnd.oasis.opendocument.database) libreoffice "$selection" >/dev/null 2>&1 ;; - application/octet-stream) - case ${selection##*.} in - doc | docx | xls | xlsx | odt | ppt | pptx) libreoffice "$selection" >/dev/null 2>&1 ;; - ts) mpv "$selection" -quiet >/dev/null 2>&1 ;; - *) zathura "$selection" >/dev/null 2>&1 ;; - esac - ;; - *) lf -command "set hidden" "$selection" ;; - esac +if [ -n "$selection" ]; then + fuz-opener "$selection" +fi +# Reset layout to tile before exiting dwmc setlayoutex 0 diff --git a/.local/bin/fuz-cache b/.local/bin/fuz-cache new file mode 100755 index 0000000..a773c03 --- /dev/null +++ b/.local/bin/fuz-cache @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +eval "$(dircolors --sh)" # Setup correct colors + +# Cache directory +CACHE_DIR="/tmp/fuz_cache" +mkdir -p "$CACHE_DIR" + +FD_OPTIONS="--hidden --color=always" + +FD_EXCLUDE_ARGS="-E .cache -E .github -E github -E .local/state -E .ssh -E .android -E GIMP -E Thunar -E .config/blender -E .config/mpv/script_modules -E .config/mpv/scripts -E .config/tmux/plugins -E fontforge -E fzf-tab-completion -E .gnupg -E libreoffice -E node_modules -E obsidian -E .obsidian -E qBittorrent -E subversion -E .terminfo -E terminfo" + +# Function to populate the cache +populate_cache() { + fd $FD_OPTIONS $FD_EXCLUDE_ARGS -E .git >"$CACHE_DIR/all" + fd $FD_OPTIONS $FD_EXCLUDE_ARGS -E .git --type directory >"$CACHE_DIR/folders" + fd --color=always -HI '^.git$' --type d --base-directory ~ $FD_EXCLUDE_ARGS | + sed 's|\\[1\;34m\.git\\[0m\\[1\;34m\/\\[0m||' >"$CACHE_DIR/git" + fd $FD_OPTIONS $FD_EXCLUDE_ARGS -E .git -e pdf -e epub -e djvu >"$CACHE_DIR/documents" + fd $FD_OPTIONS $FD_EXCLUDE_ARGS -E .git -e jpg -e jpeg -e png -e webp -e bmp -e tiff -e tif -e raw -e ico -e exif -e heic -e heif -e gif -e avif -e jxl >"$CACHE_DIR/images" + fd $FD_OPTIONS $FD_EXCLUDE_ARGS -E .git -e mkv -e mp4 -e webm -e avi >"$CACHE_DIR/videos" +} + +# Populate the cache initially +populate_cache & + +EXCLUDE_DIRS=( + "$HOME/.cache" + "$HOME/.mozilla" + "$HOME/.local/state" +) + +# Combine excluded directories into a single regular expression pattern +EXCLUDE_PATTERN=$( + IFS="|" + echo "${EXCLUDE_DIRS[*]}" +) + +# Watch for changes in ~ and update the cache +inotifywait -m -q -r -e move -e create -e delete --exclude "$EXCLUDE_PATTERN" "$HOME" | + while read -r; do + # Throttle cache updates by sleeping for 1 second + sleep 10 + populate_cache + done diff --git a/.local/bin/fuz-opener b/.local/bin/fuz-opener new file mode 100755 index 0000000..851e282 --- /dev/null +++ b/.local/bin/fuz-opener @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +openee="$1" + +case $(file --mime-type "$(readlink -f "$openee")" -b) in +image/vnd.djvu | application/pdf | application/postscript | application/epub*) zathura "$openee" >/dev/null 2>&1 ;; +text/html) nvim "$openee" ;; +text/* | application/json | inode/x-empty | application/x-subrip | application/javascript) nvim "$openee" ;; +image/x-xcf) gimp "$openee" >/dev/null 2>&1 ;; +image/svg+xml) display -- "$openee" ;; +image/*) + shopt -s nullglob + dir="$(dirname "$openee")" + selected_file="$openee" + images=() + for file in "$dir"/*.{jpg,jpeg,png,webp,bmp,tiff,tif,raw,ico,exif,heic,heif,gif,avif,jxl,JPG,PNG}; do + [[ -f "$file" ]] && images+=("$file") + done + sorted_images=() + while IFS= read -r line; do + sorted_images+=("$line") + done < <(printf "%s\n" "${images[@]}" | sort -fV) + for ((i = 0; i < ${#sorted_images[@]}; i++)); do + [[ "${sorted_images[i]}" = "$selected_file" ]] && { + setsid nsxiv -aon "$((i + 1))" "${sorted_images[@]}" + break + } + done + ;; +audio/* | video/x-ms-asf) mpv --loop-file --profile=builtin-pseudo-gui "$openee" ;; +video/*) mpv --loop-file "$openee" -quiet >/dev/null 2>&1 ;; +application/pgp-encrypted) nvim "$openee" ;; +application/vnd.openxmlformats-officedocument.wordprocessingml.document | application/vnd.oasis.opendocument.text | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | application/vnd.oasis.opendocument.spreadsheet | application/vnd.oasis.opendocument.spreadsheet-template | application/vnd.openxmlformats-officedocument.presentationml.presentation | application/vnd.oasis.opendocument.presentation-template | application/vnd.oasis.opendocument.presentation | application/vnd.ms-powerpoint | application/vnd.oasis.opendocument.graphics | application/vnd.oasis.opendocument.graphics-template | application/vnd.oasis.opendocument.formula | application/vnd.oasis.opendocument.database) libreoffice "$openee" >/dev/null 2>&1 ;; +application/octet-stream) + case ${openee##*.} in + doc | docx | xls | xlsx | odt | ppt | pptx) libreoffice "$openee" >/dev/null 2>&1 ;; + ts) mpv "$openee" -quiet >/dev/null 2>&1 ;; + *) zathura "$openee" >/dev/null 2>&1 ;; + esac + ;; +*) lf -command "set hidden" "$openee" ;; +esac diff --git a/.local/bin/fuz-preview b/.local/bin/fuz-preview new file mode 100755 index 0000000..73089e9 --- /dev/null +++ b/.local/bin/fuz-preview @@ -0,0 +1,145 @@ +#!/usr/bin/env bash + +# The purpose of this script is to demonstrate how to preview a file or an +# image in the preview window of fzf. + +# Dependencies: +# - https://github.com/sharkdp/bat +# - https://github.com/hpjansson/chafa +# - https://iterm2.com/utilities/imgcat +# - pdftoppm +# - exiftool +# - ffmpegthumbnailer +# - ImageMagick (convert) + +if [[ $# -ne 1 ]]; then + >&2 echo "usage: $0 FILENAME" + exit 1 +fi + +file=${1/#\~\//$HOME/} +type=$(file --dereference --brief --mime-type -- "$file") + +# Debug: Print the detected MIME type +# echo "Detected MIME type: $type" + +# Array to hold temp files for cleanup +temp_files=() + +# Cleanup function to remove temp files +cleanup() { + for temp_file in "${temp_files[@]}"; do + rm -f "$temp_file" + done +} + +# Register the cleanup function to run on script exit +trap cleanup EXIT + +# Function to preview text files +preview_text() { + if command -v batcat >/dev/null; then + batname="batcat" + elif command -v bat >/dev/null; then + batname="bat" + else + cat "$1" + return + fi + + ${batname} --style="${BAT_STYLE:-numbers,header}" --color=always --pager=never -- "$file" +} + +# Function to preview images +preview_image() { + local image_file="$1" + dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES} + if [[ $dim = x ]]; then + dim=$(stty size /dev/null; then + chafa -f sixel -O 9 -w 1 -s "$dim" "$image_file" + echo + elif command -v imgcat >/dev/null; then + imgcat -W "${dim%%x*}" -H "${dim##*x}" "$image_file" + else + file "$image_file" + fi +} + +# Function to preview PDF files +preview_pdf() { + temp_image=$(mktemp /tmp/preview.XXXXXX) + temp_files+=("$temp_image" "${temp_image}.jpg") + if pdftoppm -jpeg -f 1 -singlefile "$file" "$temp_image" >/dev/null 2>&1; then + temp_image="${temp_image}.jpg" + preview_image "$temp_image" + else + file "$file" + fi +} + +# Function to preview audio files +preview_audio() { + if command -v exiftool >/dev/null; then + exiftool -FileName -Title -Artist -Album -Genre -ChannelMode -AudioBitrate -FileSize -MIMEType -SampleRate -Duration "$file" + else + echo "exiftool not found." + file "$file" + fi +} + +# Function to preview video files +preview_video() { + temp_image=$(mktemp /tmp/preview.XXXXXX.jpg) + temp_files+=("$temp_image") + if ffmpegthumbnailer -i "$file" -o "$temp_image" -s 0 >/dev/null 2>&1; then + convert "$temp_image" -resize 25% "$temp_image" + preview_image "$temp_image" + else + file "$file" + fi +} + +# Function to preview archives files +preview_zip() { + atool --list -- "$file" +} + +preview_dir() { + echo + eza -Ga --group-directories-first --icons=always --color=always "$file" +} + +# Dispatch based on MIME type +case "$type" in +inode/directory) + preview_dir "$file" + ;; +text/*) + preview_text "$file" + ;; +image/*) + preview_image "$file" + ;; +application/pdf) + preview_pdf "$file" + ;; +audio/*) + preview_audio "$file" + ;; +video/*) + preview_video "$file" + ;; +application/*zip) + preview_zip "$file" + ;; +*) + exiftool "$file" + ;; +esac diff --git a/.local/bin/fzf-grep b/.local/bin/fzf-grep index 9d036f6..95bc8c2 100755 --- a/.local/bin/fzf-grep +++ b/.local/bin/fzf-grep @@ -6,7 +6,7 @@ rm -f /tmp/rg-fzf-{r,f} [ -d "$1" ] && SEARCH_DIR="$1" && shift || SEARCH_DIR="." -RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case \ +RG_PREFIX="rg --column --line-number --no-heading --follow --color=always --smart-case \ --glob '!/.ssh' --glob '!/.android' --glob '!/.gnupg'" INITIAL_QUERY="${*:-}"