aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar@proton.me>2026-04-22 19:31:05 +0530
committerArpit Chakladar <arpitchakladar@proton.me>2026-04-22 19:31:05 +0530
commit321a3c7201afaf1f6bdb5bf684aea4b81525be44 (patch)
treed29125cd000a30255a2afc9ee0bd678a8acbb6f9 /modules
parentee00ac65777fefc805d28990d177492a08580b34 (diff)
downloadhome-manager-config-321a3c7201afaf1f6bdb5bf684aea4b81525be44.tar.gz
home-manager-config-321a3c7201afaf1f6bdb5bf684aea4b81525be44.zip
fixed keybindings of lf
Diffstat (limited to 'modules')
-rw-r--r--modules/tools/lf/default.nix67
-rw-r--r--modules/tools/lf/lfrc279
2 files changed, 291 insertions, 55 deletions
diff --git a/modules/tools/lf/default.nix b/modules/tools/lf/default.nix
index bce2244..1b61fd8 100644
--- a/modules/tools/lf/default.nix
+++ b/modules/tools/lf/default.nix
@@ -24,6 +24,17 @@
drawbox = true;
hidden = true;
preview = true;
+
+ shell = if config.tools.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;
};
previewer = {
@@ -34,61 +45,7 @@
&${lib.getExe' pkgs.ctpv "ctpv"} -s $id
cmd on-quit %${lib.getExe' pkgs.ctpv "ctpv"} -e $id
set cleaner ${lib.getExe' pkgs.ctpv "ctpvclear"}
- # 1. WIPE DEFAULTS
- clearmaps
-
- # --- NAVIGATION ---
- map k up
- map j down
- map h updir # Left to go out
- map l open # Right to go in
- map g top # nvim-tree 'g' (can also use gg)
- map G bottom
- map <c-u> half-up
- map <c-d> half-down
- map <c-b> page-up
- map <c-f> page-down
-
- # --- FILE MANIPULATION (Nvim-Tree Style) ---
- map a push :touch<space> # 'a' for Add file
- map A push :mkdir<space> # 'A' for Add directory
- map r rename # 'r' for Rename
- map d delete # 'd' for Delete (immediate prompt)
- map x cut # 'x' for Cut (Move)
- map y copy # 'y' for Copy
- map p paste # 'p' for Paste
- map c clear # 'c' for Clear selection/clipboard
-
- # --- SELECTION & VISUAL ---
- map <space> toggle # Space to select/mark
- map v invert # 'v' to invert selection
- map u unselect # 'u' to unselect all
- map V visual # 'V' for visual selection mode
-
- # --- SEARCH & FILTER ---
- map / search
- map ? search-back
- map n search-next
- map N search-prev
- map f find # 'f' like nvim-tree live filter
- map F find-back
- map ; find-next
- map , find-prev
- map . set hidden! # Toggle hidden files (Dotfiles)
-
- # --- SYSTEM & UI ---
- map : read # ':' to enter command mode
- map $ shell # Shell command
- map ! shell-wait # Shell command (Wait for key)
- map & shell-async # Async shell command
- map R reload # 'R' for Refresh
- map q quit # 'q' for Quit
- map <c-l> redraw # Refresh screen UI
-
- # --- MARKS (Bookmarks) ---
- map m mark-save # 'm' + letter to save bookmark
- map ' mark-load # ' + letter to jump to bookmark
- map " mark-remove # " + letter to remove bookmark
+ ${builtins.readFile ./lfrc}
'';
};
diff --git a/modules/tools/lf/lfrc b/modules/tools/lf/lfrc
new file mode 100644
index 0000000..11a9959
--- /dev/null
+++ b/modules/tools/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 <c-d> half-down
+map <c-u> half-up
+map <c-f> page-down
+map <c-b> page-up
+
+# ── Opening / editing ─────────────────────────────────────────────────────────
+map <enter> 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 <space> 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 <c-r> reload # reload directory
+map <esc> 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