{ pkgs, ... }:
let
  lfimg = pkgs.fetchFromGitHub {
    owner = "neeshy";
    repo = "lfimg";
    rev = "e9154721514a1384a89f2713092c15dc77992f37";
    sha256 = "sha256-n4H+oREay96sxenF9S02uJp5xV7ow/URaQWaV/sPsuk=";
  };
in
{
  home.packages = [
    pkgs.lf
    #(pkgs.writeShellScriptBin "lfimg" (lib.readFile "${lfimg}/lfimg"))
    pkgs.pistol # For previewing
    pkgs.ranger # Only for rifle, to replace xdg-open
    #pkgs.ueberzug # For previewing images
  ];
  xdg.configFile."lf/lfrc".text = ''
    # Do not fork
    #cmd open $xdg-open "$f"
    cmd open $rifle "$f"
    map <enter> open
    map d delete
    map f filter
    map i up
    map j updir
    map k down
    #set cleaner ${lfimg}/cls
    set dircache
    set dirfirst
    set hidden
    set incfilter
    set incsearch
    set mouse
    set noglobsearch
    set noicons
    set preview
    set previewer pistol
    set ratios 1:2
    set scrolloff 10
    set sortby natural
    set tabstop 4
  '';
  xdg.configFile."pistol/pistol.conf".text = ''
    text/* bat --paging=never --color=always %pistol-filename%
    #image/.* ${lfimg}/pv %pistol-filename% %pistol-extra0% %pistol-extra1% %pistol-extra2% %pistol-extra3%
  '';
  # xdg-open is harder to configure and slower to launch than rifle
  #xdg.mimeApps.enable = true;
  # Initial config from https://raw.githubusercontent.com/ranger/ranger/master/ranger/config/rifle.conf
  xdg.configFile."ranger/rifle.conf".source = ranger/rifle.conf;
}