From 0979d4e678514a8e0cdcbe1fbb174667c5361c8a Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 5 Oct 2025 19:53:46 +0530 Subject: Update readme + add drop to shell keymap --- README.md | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++- lib/Daffm/State.hs | 43 ++++++++++++++------------- media/screenshot.jpg | Bin 0 -> 119595 bytes notes.org | 11 +++---- 4 files changed, 109 insertions(+), 27 deletions(-) create mode 100644 media/screenshot.jpg diff --git a/README.md b/README.md index d5fcc74..0647cb9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,82 @@ # Daffm -Dumb as fuck file manager +Dumb as fuck file manager is a minimal tui file manager + +![screenshot](./media/screenshot.jpg) + +## Install +- Clone the repo and build it: `cabal build daffm` or `nix build` +- Nix flakes users can also install it as a flake: `github:phenax/daffm#daffm` + + +## Config +Configuration is managed in toml. +By default it will try to load `$XDG_CONFIG_HOME/daffm/config.toml`. +You can load config in a different path using `daffm -c `. +You can also store alternate configs in `$XDG_CONFIG_HOME/daffm/config.custom-thing.toml` and load it as `daffm -c @custom-thing`. + +Heres an example config for reference: + +```toml +# `opener` runs when opening a file or selections +opener = """ +echo "%F" | while IFS= read file; do + case "$(file --mime-type "$file" -bL)" in + text/*) $EDITOR "$file" ;; + *) xdg-open "$file" >/dev/null 2>&1 ;; + esac +done; +""" + +[keymap] +gdl = "cd ~/Downloads" +gdc = "cd ~/Documents" +gp = "cd ~/Pictures" + +rn = "!!echo '%F' | vidir -v -" # Uses vidir (moreutils) to rename selected files/directories +md = "cmdline-set !mkdir -p " # Prefills cmdline +mf = "cmdline-set !touch " +dd = "!rm -rfi %f" +sdd = "!sudo rm -rfi %f" +cp = "cmdline-set !cp -f % %" + +# Copes file to clipboard +"yy" = """! +xclip -selection clipboard -t $(file --mime-type '%' -bL) -i '%' +""" +``` + +The substituions (%,%f,%s,%F,%S) are replaced with absolute file paths +- `%`: File under cursor +- `%s`: Selected files separated by spaces +- `%S`: Selected files separated by newlines +- `%f`: Same as `%s` but if there are no selections, uses file under cursor +- `%F`: Same as `%S` but if there are no selections, uses file under cursor + + +## Default keys (no need to define these in config) + +```toml +[keymap] +q = "quit" +rr = "reload" +"!" = "cmdline-set !" +":" = "cmdline-enter" +l = "open" +h = "back" +"" = "open" +"" = "back" +v = "selection-toggle" # select/unselect files +"" = "selection-toggle" +C = "selection-clear" +"~" = "cd ~" +gh = "cd ~" # Go home +"$" = "$SHELL" # drop to shell +gx = "!xdg-open % >/dev/null 2>&1" # Open externally +gcfg = "cd ~/.config/daffm" # Open default configurations directory +``` + + +## Commands + +WIP + diff --git a/lib/Daffm/State.hs b/lib/Daffm/State.hs index 1ea8bfe..fd5818d 100644 --- a/lib/Daffm/State.hs +++ b/lib/Daffm/State.hs @@ -18,6 +18,27 @@ import System.FilePath (joinPath) import System.PosixCompat (fileExist) import qualified System.PosixCompat as Posix +defaultKeymaps :: Keymap +defaultKeymaps = + Map.fromList + [ ([K.KChar 'q'], CmdQuit), + ([K.KChar 'r'], CmdReload), + ([K.KChar '!'], CmdSetCmdline "!"), + ([K.KChar ':'], CmdEnterCmdline), + ([K.KChar 'l'], CmdOpenSelection), + ([K.KChar 'h'], CmdGoBack), + ([K.KEnter], CmdOpenSelection), + ([K.KBS], CmdGoBack), + ([K.KChar 'v'], CmdToggleSelection), + ([K.KChar '\t'], CmdToggleSelection), + ([K.KChar 'C'], CmdClearSelection), + ([K.KChar '~'], CmdChangeDir "~"), + ([K.KChar '$'], CmdShell False "$SHELL"), + ([K.KChar 'g', K.KChar 'x'], CmdShell False "!xdg-open % >/dev/null 2>&1"), + ([K.KChar 'g', K.KChar 'h'], CmdChangeDir "~"), + ([K.KChar 'g', K.KChar 'c', K.KChar 'f', K.KChar 'g'], CmdChangeDir "~/.config/daffm") + ] + mkEditor :: (Zipper.GenericTextZipper a) => a -> Editor.Editor a FocusTarget mkEditor = Editor.editor FocusCmdline (Just 1) @@ -34,24 +55,6 @@ mkEmptyAppState config = stateOpenerScript = configOpener config, stateKeySequence = [] } - where - defaultKeymaps = - Map.fromList - [ ([K.KChar 'q'], CmdQuit), - ([K.KChar 'r', K.KChar 'r'], CmdReload), - ([K.KChar '!'], CmdSetCmdline "!"), - ([K.KChar ':'], CmdEnterCmdline), - ([K.KChar 'l'], CmdOpenSelection), - ([K.KChar 'h'], CmdGoBack), - ([K.KEnter], CmdOpenSelection), - ([K.KBS], CmdGoBack), - ([K.KChar 'v'], CmdToggleSelection), - ([K.KChar '\t'], CmdToggleSelection), - ([K.KChar 'C'], CmdClearSelection), - ([K.KChar '~'], CmdChangeDir "~"), - ([K.KChar 'g', K.KChar 'h'], CmdChangeDir "~"), - ([K.KChar 'g', K.KChar 'c', K.KChar 'f', K.KChar 'g'], CmdChangeDir "~/.config/daffm") - ] toggleSetItem :: (Ord a) => a -> Set.Set a -> Set.Set a toggleSetItem val set = @@ -126,9 +129,7 @@ listFilesInDir dir = do cacheDirPosition :: AppState -> AppState cacheDirPosition appState@(AppState {stateListPositionHistory, stateCwd, stateFiles}) = - appState - { stateListPositionHistory = Map.insert stateCwd pos stateListPositionHistory - } + appState {stateListPositionHistory = Map.insert stateCwd pos stateListPositionHistory} where pos = fromMaybe 0 $ L.listSelected stateFiles diff --git a/media/screenshot.jpg b/media/screenshot.jpg new file mode 100644 index 0000000..588faea Binary files /dev/null and b/media/screenshot.jpg differ diff --git a/notes.org b/notes.org index dd6d71a..88db27c 100644 --- a/notes.org +++ b/notes.org @@ -18,15 +18,16 @@ - [X] Expand ~ to home in internal commands (cd) - [X] Show current pending keys in statusline - [X] Opener configuration -- [ ] Cmdline history -- [ ] Cli arg parsing (dir arg) -- [ ] Cli arg parsing (-c flag for custom config path) +- [X] Cli arg parsing (dir arg) +- [X] Cli arg parsing (-c flag for custom config path) +- [ ] Command: search, search-next, search-prev ** Right after - [ ] copy/paste across instances - user-land solution (write selections to file and read from second instance) - socket -- [ ] Command: open-external -- [ ] handle on open (for external integrations) +- [ ] Fix keymap evaluation: If v is bound, it doesnt evaluate vd since v was found +- [X] handle on open (for external integrations) (opener in custom config) +- [ ] Cmdline history - [ ] Command: pipe (think about this) (pipe selection file names/file contents) - [ ] Allow escaping % in commands - [ ] Rethink % substituions -- cgit v1.3.1