about summary refs log blame commit diff stats
path: root/home-manager/config/lf/default.nix
blob: 3991ba193a7a47e466826c27524af06fc193ef26 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

         
         
      




                                       
                                           
                    
                                                                                  
     
                                         




                 
                                                  






                         
                                                  






                                           
                                                  






                                          
                                                  
                                               
    
                                               
 
                                             
 
                 

                  
                              
                                            






                  

                          
                                 


                                            




                                  
                                            



                  
          
                              


                                            
                

             
                             






                                            
                                        





                                            
                                  


                                            

             
                               
                                            
                             
          
























                                                                            
                                            




                                                                        
          
                                    

                                            
               


                  








                                     

                                            
                  
                     

             
                                

                                            

                                        
            
                 

             


                            
                     













                               
                     















                               
                        







                       
                   




                          

                     
                   
                            









                                                      
                                              
 









                                      
                     



                                   
                     















                                                








                             
                       
                                       
      
                


                                                                 
                                                                                      
                     
                                                                        
                                         
                                        
                                                                
                                                    
                   
                                                                         
      
                                                 
                    
                                               


                                                     
       


           
{
  config,
  pkgs,
  sysLib,
  ...
}: let
  functionCall = {
    file,
    dependencies,
    ...
  }:
    sysLib.makeShellScriptWithLibrary {
      name = "${builtins.baseNameOf file}";
      script = file;
      dependencies = dependencies ++ (builtins.attrValues {inherit (pkgs) dash;});
    }
    + "/bin/${builtins.baseNameOf file}";
  shell = {
    file,
    dependencies,
    ...
  }: ''
    ''${{
      ${functionCall {inherit file dependencies;}}
    }}
  ''; # closes the lf tui
  pipe = {
    file,
    dependencies,
    ...
  }: ''
    %{{
      ${functionCall {inherit file dependencies;}}
    }}
  ''; # runs the command in the ui/term bar
  async = {
    file,
    dependencies,
    ...
  }: ''
    &{{
      ${functionCall {inherit file dependencies;}}
    }}
  ''; # runs the command in the background
  wait = {
    file,
    dependencies,
    ...
  }: ''
    !{{
      ${functionCall {inherit file dependencies;}}
    }}
  ''; # adds a prompt after the command has run
in {
  xdg.configFile."lf/icons".source = ./icons;
  xdg.configFile."lf/colors".source = ./colors;

  # TODO add the systemd tempfile option here

  programs.lf = {
    enable = true;

    commands = {
      archive = shell {
        file = ./cmds/archive;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            fzf
            gnutar
            xz
            p7zip
            zip
            ;
        };
      };
      broot_jump = shell {
        file = ./cmds/broot_jump;
        dependencies = builtins.attrValues {
          inherit (pkgs) broot;
        };
      };
      chmod = pipe {
        file = ./cmds/chmod;
        dependencies = [];
      };
      clear_trash = shell {
        file = ./cmds/clear_trash;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            fzf
            trashy
            ;
        };
      };
      dl_file = pipe {
        file = ./cmds/dl_file;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            xdragon
            curl
            ;
        };
      };
      dragon = pipe {
        file = ./cmds/dragon;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            xdragon
            ;
        };
      };
      dragon_individual = pipe {
        file = ./cmds/dragon_individual;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            xdragon
            ;
        };
      };
      dragon_stay = pipe {
        file = ./cmds/dragon_stay;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            xdragon
            ;
        };
      };
      fzf_jump = shell {
        file = ./cmds/fzf_jump;
        dependencies = builtins.attrValues {
          inherit (pkgs) fzf;
        };
      };
      help = shell {
        file = ./cmds/help;
        dependencies = [];
      };
      mk_dir = pipe {
        file = ./cmds/mk_dir;
        dependencies = [];
      };
      mk_file = shell {
        file = ./cmds/mk_file;
        dependencies = [];
      };
      mk_ln = pipe {
        file = ./cmds/mk_ln;
        dependencies = [];
      };
      mk_scr = shell {
        file = ./cmds/mk_scr;
        dependencies = [];
      };
      open = shell {
        file = ./cmds/open;
        dependencies = builtins.attrValues {inherit (pkgs) file xdg-utils;};
      };
      open_config = shell {
        file = ./cmds/open_config;
        dependencies = builtins.attrValues {
          #inherit
          #(pkgs)
          ## TODO rewrite this:  bookmenu, https://github.com/jarun/buku
          #
          #buku
          #;
        };
      };
      restore_trash = shell {
        file = ./cmds/restore_trash;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            fzf
            trashy
            ;
        };
      };
      set_wall_paper = pipe {
        file = ./cmds/set_wall_paper;
        dependencies = [];
      };
      stripspace = pipe {
        file = ./cmds/stripspace;
        dependencies = [];
      };
      trash = pipe {
        file = ./cmds/trash;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            trashy
            trash-cli
            findutils
            ;
        };
      };
      unarchive = pipe {
        file = ./cmds/unarchive;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            gnutar
            unzip
            # TODO this is unfree! unrar
            
            p7zip
            ;
        };
      };
    };
    keybindings = {
      # Remove some defaults
      m = null;
      "\"'\"" = null;
      "'\"'" = null;
      d = null;
      c = null;
      e = null;
      j = null;
      k = null;
      l = null;
      ";" = null;

      # File Openers
      ee = "\$\$EDITOR \"$f\"";
      u = "%\$IVIEWER \"$f\"";
      cc = "\$sudo -e \"$f\"";

      # Archive Mappings
      au = "unarchive";
      aa = "archive";

      # Trash Mappings
      dd = "trash";
      jc = "clear_trash";
      jr = "restore_trash";

      # Broot Mapping
      f = "broot_jump";

      # Dragon Mapping
      dr = "dragon";
      ds = "dragon-stay";
      di = "dragon-individual";
      #dm = "mvdragon";
      #dc = "cpdragon";
      dl = "dlfile";

      cs = "stripspace";

      # Vim keys
      h = "updir";
      t = "down";
      n = "up";
      s = "open";

      # Basic Functions
      bn = "help";
      kk = "mk_ln";
      "." = "set hidden!";
      DD = "delete";
      p = "paste";
      x = "cut";
      y = "copy";
      "<enter>" = "open";
      mf = "mk_file";
      md = "mk_dir";
      ms = "mk_scr";
      ch = "chmod";
      bg = "set_wall_paper";
      o = "open_config";
      br = "\$vimv \$fx"; # TODO what is this command?
      r = "rename";
      H = "top";
      L = "bottom";
      R = "reload";
      C = "clear";
      U = "unselect";

      # Movement
      gjr = "cd ~/.local/share/Trash/files";
      gus = "cd /run/${config.home.username}";

      "gr." = "cd ~/repos";
      grr = "cd ~/repos/rust";
      grp = "cd ~/repos/python";
      grc = "cd ~/repos/c";
      gra = "cd ~/repos/auto_hot_key";
      grt = "cd ~/repos/tex";
      grs = "cd ~/repos/shell";
      grch = "cd ~/repos/chroot";
      grpe = "cd ~/repos/perl";
      grja = "cd ~/repos/java";
      grjs = "cd ~/repos/java_script";
      # -------------
      "gm." = "cd ~/media";
      gmpi = "cd ~/media/pictures";
      gmd = "cd ~/media/downloads";
      gmpl = "cd ~/media/playlist";
      gmi = "cd ~/media/isos";
      # -------------
      "gs." = "cd ~/school";
      gsgs = "cd ~/school/geschichte";
      gsch = "cd ~/school/chemie";
      gsen = "cd ~/school/english";
      gsgo = "cd ~/school/geographie";
      gsin = "cd ~/school/infomatik";
      gsso = "cd ~/school/sozialkunde";
      gskr = "cd ~/school/katholische_religion";
      gsmu = "cd ~/school/musik";
      gsla = "cd ~/school/latein";
      gsde = "cd ~/school/deutsch";
      gsma = "cd ~/school/mathematik";
      gspr = "cd ~/school/praktikum";
      gsbi = "cd ~/school/biologie";
      gssp = "cd ~/school/sport";
      gsphy = "cd ~/school/physik";
      gsphi = "cd ~/school/philosophie";

      gc = "cd ~/.config";
      gl = "cd ~/.local";
      gE = "cd /etc";

      "gU." = "cd /usr";
      gUs = " cd /usr/share";

      gt = "cd /tmp";
    };
    previewer = {
      keybinding = "i";
      source = "${pkgs.ctpv}/bin/ctpv";
    };
    settings = {
      # TODO this needs to be added to nixos:
      #autoquit = true; # quit the server, if no clients are left
      #dirpreviews = true; # preview for directories

      dircounts = true; # count things in directories TODO this has performance impact
      drawbox = true;
      # errorfmt = "\\033[1;91m==> ERROR:\\033[0m\\033[1;93m%s\\033[0m";
      errorfmt = "\\033[1;91m%s\\033[0m";
      hidden = true; # show hidden files
      icons = true;
      ifs = "\\n"; # internal field separator for shell commands
      #info = "size"; # show the size of a directory
      shell = "sh";
      shellopts = "-eu"; # e: exit on error; u: error for unset variables
    };
    # TODO remove auto quit, if it has been added
    extraConfig = ''
      &${pkgs.ctpv}/bin/ctpv -s $id
      cmd on-quit %${pkgs.ctpv}/bin/ctpv -e $id
      set cleaner ${pkgs.ctpv}/bin/ctpvclear

      # close the server, after the last client exits
      set autoquit true
    '';
  };
}
# vim: ts=2