From 3e232a2bc7f5c8ea33804be1ea071a91c5f98055 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Fri, 24 Apr 2026 01:48:30 +0530 Subject: replacing tools with programs to be more consistent with config options --- modules/programs/lf/default.nix | 48 ++++++ modules/programs/lf/icons | 342 ++++++++++++++++++++++++++++++++++++++++ modules/programs/lf/lfrc | 279 ++++++++++++++++++++++++++++++++ 3 files changed, 669 insertions(+) create mode 100644 modules/programs/lf/default.nix create mode 100644 modules/programs/lf/icons create mode 100644 modules/programs/lf/lfrc (limited to 'modules/programs/lf') diff --git a/modules/programs/lf/default.nix b/modules/programs/lf/default.nix new file mode 100644 index 0000000..eb605f5 --- /dev/null +++ b/modules/programs/lf/default.nix @@ -0,0 +1,48 @@ +{ + pkgs, + lib, + config, + ... +}: + +# lf - terminal file manager +{ + config = lib.mkIf config.programs.lf.enable { + home.packages = with pkgs; [ + ctpv + ]; + + programs.lf = { + settings = { + number = true; + icons = true; + drawbox = true; + hidden = true; + preview = true; + + shell = if config.programs.zsh.enable then lib.getExe pkgs.zsh else "bash"; + shellopts = "'-eu'"; + ifs = "\n"; + scrolloff = "4"; + period = "1"; + incsearch = true; + smartcase = true; + info = "size"; + sortby = "natural"; + dirfirst = true; + + cleaner = lib.getExe config.scripts.file-preview-clean.package; + }; + + previewer = { + source = lib.getExe config.scripts.file-preview.package; + }; + + extraConfig = '' + ${builtins.readFile ./lfrc} + ''; + }; + + home.file.".config/lf/icons".source = ./icons; + }; +} diff --git a/modules/programs/lf/icons b/modules/programs/lf/icons new file mode 100644 index 0000000..8697cf2 --- /dev/null +++ b/modules/programs/lf/icons @@ -0,0 +1,342 @@ +# vim:ft=conf + +# file types (with matching order) +ln  # LINK +or  # ORPHAN +tw t # STICKY_OTHER_WRITABLE +ow  # OTHER_WRITABLE +st t # STICKY +di  # DIR +pi p # FIFO +so s # SOCK +bd b # BLK +cd c # CHR +su u # SETUID +sg g # SETGID +ex  # EXEC +fi  # FILE + +# file extensions (vim-devicons) +*.styl  +*.sass  +*.scss  +*.htm  +*.html  +*.slim  +*.haml  +*.ejs  +*.css  +*.less  +*.md  +*.mdx  +*.markdown  +*.rmd  +*.json  +*.webmanifest  +*.js  +*.mjs  +*.jsx  +*.rb  +*.gemspec  +*.rake  +*.php  +*.py  +*.pyc  +*.pyo  +*.pyd  +*.coffee  +*.mustache  +*.hbs  +*.conf  +*.ini  +*.yml  +*.yaml  +*.toml  +*.bat  +*.mk  +*.jpg  +*.jpeg  +*.bmp  +*.png  +*.webp  +*.gif  +*.ico  +*.twig  +*.cpp  +*.c++  +*.cxx  +*.cc  +*.cp  +*.c  +*.cs 󰌛 +*.h  +*.hh  +*.hpp  +*.hxx  +*.hs  +*.lhs  +*.nix  +*.lua  +*.java  +*.sh  +*.fish  +*.bash  +*.zsh  +*.ksh  +*.csh  +*.awk  +*.ps1  +*.ml λ +*.mli λ +*.diff  +*.db  +*.sql  +*.dump  +*.clj  +*.cljc  +*.cljs  +*.edn  +*.scala  +*.go  +*.dart  +*.xul  +*.sln  +*.suo  +*.pl  +*.pm  +*.t  +*.rss  +'*.f#'  +*.fsscript  +*.fsx  +*.fs  +*.fsi  +*.rs  +*.rlib  +*.d  +*.erl  +*.hrl  +*.ex  +*.exs  +*.eex  +*.leex  +*.heex  +*.vim  +*.ai  +*.psd  +*.psb  +*.ts  +*.tsx  +*.jl  +*.pp  +*.vue  +*.elm  +*.swift  +*.xcplayground  +*.tex 󰙩 +*.r 󰟔 +*.rproj 󰗆 +*.sol 󰡪 +*.pem  + +# file names (vim-devicons) (case-insensitive not supported in lf) +*gruntfile.coffee  +*gruntfile.js  +*gruntfile.ls  +*gulpfile.coffee  +*gulpfile.js  +*gulpfile.ls  +*mix.lock  +*dropbox  +*.ds_store  +*.gitconfig  +*.gitignore  +*.gitattributes  +*.gitlab-ci.yml  +*.bashrc  +*.zshrc  +*.zshenv  +*.zprofile  +*.vimrc  +*.gvimrc  +*_vimrc  +*_gvimrc  +*.bashprofile  +*favicon.ico  +*license  +*node_modules  +*react.jsx  +*procfile  +*dockerfile  +*docker-compose.yml  +*docker-compose.yaml  +*compose.yml  +*compose.yaml  +*rakefile  +*config.ru  +*gemfile  +*makefile  +*cmakelists.txt  +*robots.txt 󰚩 + +# file names (case-sensitive adaptations) +*Gruntfile.coffee  +*Gruntfile.js  +*Gruntfile.ls  +*Gulpfile.coffee  +*Gulpfile.js  +*Gulpfile.ls  +*Dropbox  +*.DS_Store  +*LICENSE  +*React.jsx  +*Procfile  +*Dockerfile  +*Docker-compose.yml  +*Docker-compose.yaml  +*Rakefile  +*Gemfile  +*Makefile  +*CMakeLists.txt  + +# file patterns (vim-devicons) (patterns not supported in lf) +# .*jquery.*\.js$  +# .*angular.*\.js$  +# .*backbone.*\.js$  +# .*require.*\.js$  +# .*materialize.*\.js$  +# .*materialize.*\.css$  +# .*mootools.*\.js$  +# .*vimrc.*  +# Vagrantfile$  + +# file patterns (file name adaptations) +*jquery.min.js  +*angular.min.js  +*backbone.min.js  +*require.min.js  +*materialize.min.js  +*materialize.min.css  +*mootools.min.js  +*vimrc  +Vagrantfile  + +# archives or compressed (extensions from dircolors defaults) +*.tar  +*.tgz  +*.arc  +*.arj  +*.taz  +*.lha  +*.lz4  +*.lzh  +*.lzma  +*.tlz  +*.txz  +*.tzo  +*.t7z  +*.zip  +*.z  +*.dz  +*.gz  +*.lrz  +*.lz  +*.lzo  +*.xz  +*.zst  +*.tzst  +*.bz2  +*.bz  +*.tbz  +*.tbz2  +*.tz  +*.deb  +*.rpm  +*.jar  +*.war  +*.ear  +*.sar  +*.rar  +*.alz  +*.ace  +*.zoo  +*.cpio  +*.7z  +*.rz  +*.cab  +*.wim  +*.swm  +*.dwm  +*.esd  + +# image formats (extensions from dircolors defaults) +*.jpg  +*.jpeg  +*.mjpg  +*.mjpeg  +*.gif  +*.bmp  +*.pbm  +*.pgm  +*.ppm  +*.tga  +*.xbm  +*.xpm  +*.tif  +*.tiff  +*.png  +*.svg  +*.svgz  +*.mng  +*.pcx  +*.mov  +*.mpg  +*.mpeg  +*.m2v  +*.mkv  +*.webm  +*.ogm  +*.mp4  +*.m4v  +*.mp4v  +*.vob  +*.qt  +*.nuv  +*.wmv  +*.asf  +*.rm  +*.rmvb  +*.flc  +*.avi  +*.fli  +*.flv  +*.gl  +*.dl  +*.xcf  +*.xwd  +*.yuv  +*.cgm  +*.emf  +*.ogv  +*.ogx  + +# audio formats (extensions from dircolors defaults) +*.aac  +*.au  +*.flac  +*.m4a  +*.mid  +*.midi  +*.mka  +*.mp3  +*.mpc  +*.ogg  +*.ra  +*.wav  +*.oga  +*.opus  +*.spx  +*.xspf  + +# other formats +*.pdf  diff --git a/modules/programs/lf/lfrc b/modules/programs/lf/lfrc new file mode 100644 index 0000000..11a9959 --- /dev/null +++ b/modules/programs/lf/lfrc @@ -0,0 +1,279 @@ +# ─── lf config — nvim-tree style keybindings ─────────────────────────────── + +# ─── Colors (optional — remove if you use a color scheme plugin) ────────────── +# set color256 true + +# ─── Custom commands ────────────────────────────────────────────────────────── + +# Create a new file (like nvim-tree 'a' with no trailing /) +cmd touch %{{ + printf "New file name: " + read -r name + touch "$name" + lf -remote "send $id select '$name'" +}} + +# Create a new directory (like nvim-tree 'a' with trailing /) +cmd mkdir %{{ + printf "New directory name: " + read -r name + mkdir -p "$name" + lf -remote "send $id select '$name'" +}} + +# Rename — full name (like nvim-tree 'r') +cmd rename ${{ + printf "Rename '%s' to: " "$f" + read -r newname + mv -- "$f" "$(dirname "$f")/$newname" + lf -remote "send $id select '$newname'" +}} + +# Rename — only basename without extension (like nvim-tree 'e' in some configs) +cmd rename_stem ${{ + stem="${f##*/}" + stem="${stem%.*}" + printf "Rename stem to: " + read -r newname + ext="${f##*.}" + if [ "${f##*/}" = "$stem" ]; then + mv -- "$f" "$(dirname "$f")/$newname" + else + mv -- "$f" "$(dirname "$f")/$newname.$ext" + fi +}} + +# Delete — trash (safe) using trash-cli if available, else rm +cmd trash %{{ + set -f + files=$(printf '%s\n' $fx | wc -l) + printf "Trash $files item(s)? [y/N] " + read -r ans + [ "$ans" = "y" ] || [ "$ans" = "Y" ] || exit 0 + if command -v trash-put >/dev/null 2>&1; then + printf '%s\n' $fx | xargs trash-put -- + else + printf '%s\n' $fx | xargs rm -rf -- + fi +}} + +# Delete — permanent, no confirmation prompt (use carefully) +cmd delete ${{ + set -f + printf "Permanently delete? [y/N] " + read -r ans + [ "$ans" = "y" ] || [ "$ans" = "Y" ] || exit 0 + rm -rf -- $fx +}} + +# Paste (move or copy depending on operation) +cmd paste &{{ + set -f + load=$(lf -remote 'load') + mode=$(echo "$load" | sed -n '1p') + list=$(echo "$load" | sed -n '2,$p') + if [ "$mode" = "copy" ]; then + cp -rn -- $list . + elif [ "$mode" = "move" ]; then + mv -n -- $list . + lf -remote 'send clear' + fi + lf -remote 'send reload' + lf -remote 'send clear' +}} + +# Paste with overwrite +cmd paste_overwrite &{{ + set -f + load=$(lf -remote 'load') + mode=$(echo "$load" | sed -n '1p') + list=$(echo "$load" | sed -n '2,$p') + if [ "$mode" = "copy" ]; then + cp -r -- $list . + elif [ "$mode" = "move" ]; then + mv -- $list . + lf -remote 'send clear' + fi + lf -remote 'send reload' + lf -remote 'send clear' +}} + +# Open in nvim +cmd edit $nvim "$f" + +# Open with xdg-open (GUI apps) +cmd open_gui &xdg-open "$f" + +# Toggle hidden files (like nvim-tree 'H') +cmd toggle_hidden :{{ + set hidden! + set info +}} + +# Bulk rename with $EDITOR (like vimv / nvim-tree mass rename) +cmd bulk_rename ${{ + index=$(mktemp /tmp/lf-bulk-index.XXXXXX) + names=$(mktemp /tmp/lf-bulk-names.XXXXXX) + printf '%s\n' $fx > "$index" + sed 's|.*/||' "$index" > "$names" + $EDITOR "$names" + paste "$index" "$names" | while IFS=$'\t' read -r old new; do + if [ "$old" != "$(dirname "$old")/$new" ]; then + mv -- "$old" "$(dirname "$old")/$new" + fi + done + rm -- "$index" "$names" + lf -remote 'send reload' +}} + +# Create symlink (relative) +cmd symlink %{{ + printf "Symlink target name: " + read -r name + ln -s "$f" "$name" +}} + +# Copy path to clipboard (needs xclip / xsel / wl-copy) +cmd copy_path &{{ + printf '%s' "$f" | xclip -selection clipboard 2>/dev/null \ + || printf '%s' "$f" | xsel --clipboard --input 2>/dev/null \ + || printf '%s' "$f" | wl-copy 2>/dev/null +}} + +# Show file info (like nvim-tree 'i') +cmd info %{{ + stat -- "$f" + printf '\nPress ENTER...' + read -r _ +}} + +# Jump to bookmarks (requires fzf) +cmd bookmark_jump ${{ + bm="$HOME/.config/lf/bookmarks" + [ -f "$bm" ] || touch "$bm" + dest=$(cat "$bm" | fzf --prompt "Jump to: ") + [ -n "$dest" ] && lf -remote "send $id cd '$dest'" +}} + +# Add bookmark +cmd bookmark_add %{{ + bm="$HOME/.config/lf/bookmarks" + printf '%s\n' "$PWD" >> "$bm" + sort -u "$bm" -o "$bm" + echo "Bookmarked: $PWD" +}} + +# fzf-based fuzzy find & cd/select +cmd fzf_cd ${{ + dest=$(find . -type d 2>/dev/null | fzf --prompt "cd: ") + [ -n "$dest" ] && lf -remote "send $id cd '$dest'" +}} + +cmd fzf_file ${{ + file=$(find . -type f 2>/dev/null | fzf --prompt "open: ") + [ -n "$dest" ] && lf -remote "send $id select '$file'" +}} + +# ─── Keybindings — clear defaults and remap ─────────────────────────────────── + +# Unmap keys we'll remap +map d +map y +map p +map c +map r +map a +map e +map f +map g +map G +map i +map o +map H +map m + +# ── Navigation ──────────────────────────────────────────────────────────────── +map h updir # go up one dir +map l open # open file/dir (maps to $EDITOR for files) +map j down +map k up +map J half-down +map K half-up +map gg top +map G bottom +map gd cd ~/Downloads +map gh cd ~ +map gc cd ~/.config +map gp cd ~/projects + +# Page navigation (nvim-style) +map half-down +map half-up +map page-down +map page-up + +# ── Opening / editing ───────────────────────────────────────────────────────── +map open # open with default +map o open_gui # open with GUI app +map e edit # open in nvim explicitly + +# ── File / dir creation ─────────────────────────────────────────────────────── +map af touch # a → file (like nvim-tree 'a' without /) +map ad mkdir # a → dir (like nvim-tree 'a' with /) + +# ── Rename ──────────────────────────────────────────────────────────────────── +map r rename # full rename (like nvim-tree 'r') +map R bulk_rename # bulk rename in $EDITOR +map cw rename # alias: cw like vim's 'change word' +map I rename # alias: go to start (lf positions cursor) +map A rename # alias: go to end + +# ── Delete ──────────────────────────────────────────────────────────────────── +map dd trash # move to trash (safe delete — like nvim-tree 'd') +map dD delete # permanent delete (no trash) + +# ── Yank / Copy / Cut / Paste ───────────────────────────────────────────────── +map yy copy # yank/copy selection (like nvim-tree 'c') +map yn copy_path # yank path to clipboard +map dd cut # cut selection (like nvim-tree 'x') — overrides trash above; + # uncomment the trash line below if you prefer separate keys +# map dt trash # use 'dt' for trash if 'dd' is used for cut +map pp paste # paste (like nvim-tree 'p') +map po paste_overwrite # paste with overwrite +map P paste # alias + +# ── Marking / selection ─────────────────────────────────────────────────────── +map toggle # toggle mark on current item (like nvim-tree space) +map v invert # invert selection +map V invert # alias +map u unselect # clear all marks +map * glob-select '*' # select all via glob + +# ── Search ──────────────────────────────────────────────────────────────────── +map / search # incremental search forward +map n search-next +map N search-prev +map f fzf_file # fuzzy find file (requires fzf) +map F fzf_cd # fuzzy cd into dir (requires fzf) + +# ── View toggles ────────────────────────────────────────────────────────────── +map H toggle_hidden # toggle hidden files (like nvim-tree 'H') +map zi set icons! +map zr set reverse! +map zh set hidden! +map zn set sortby natural +map zs set sortby size +map zm set sortby modified +map ze set sortby ext + +# ── Info / misc ─────────────────────────────────────────────────────────────── +map i info # show stat info (like nvim-tree 'i') +map reload # reload directory +map clear # clear selection +map q quit +map Q quit +map m bookmark_add # add bookmark +map ' bookmark_jump # jump to bookmark (requires fzf) + +# Symlink +map S symlink -- cgit v1.2.3