From 24cb2ea2c901b4cef50a2dcbd24e770f54b8538f Mon Sep 17 00:00:00 2001 From: Minijackson Date: Sun, 5 Mar 2023 21:28:52 +0100 Subject: commandline: configure exa, expand dircolors --- common/commandline.nix | 64 ++++--- common/commandline/dircolors.nix | 390 ++++++++++++++++++++++++++++++++------- 2 files changed, 358 insertions(+), 96 deletions(-) (limited to 'common') diff --git a/common/commandline.nix b/common/commandline.nix index 74adfa2..212534e 100644 --- a/common/commandline.nix +++ b/common/commandline.nix @@ -1,14 +1,14 @@ -inputs: - -{ config, pkgs, lib, ... }: - -with inputs.self.lib.theme; -let +inputs: { + config, + pkgs, + lib, + ... +}: +with inputs.self.lib.theme; let dominantEscapeCode = fgEscapeCode config.theme.colors.dominant; bgDominantEscapeCode = bgEscapeCode config.theme.colors.dominant; backgroundEscapeCode = fgEscapeCode config.theme.colors.background; -in -{ +in { imports = [ (import ./commandline/dircolors.nix inputs) (import ./commandline/git.nix inputs) @@ -19,7 +19,7 @@ in ]; console = { - packages = with pkgs; [ terminus_font ]; + packages = with pkgs; [terminus_font]; font = "ter-d22n"; colors = [ "282a2e" @@ -43,7 +43,6 @@ in }; environment.shellAliases = { - ll = "ls -l"; e = "\${EDITOR}"; cpr = "${pkgs.rsync}/bin/rsync -ah --inplace --info=progress2"; }; @@ -60,22 +59,20 @@ in }; }; - security.sudo.extraConfig = - let - lectureFile = builtins.toFile "sudoers.lecture" '' -  - ${dominantEscapeCode}"Bee" careful __ - ${dominantEscapeCode}with sudo! // \ - \\_/ // - '''-.._.-'''-.._.. -(||)(') - '''' + security.sudo.extraConfig = let + lectureFile = builtins.toFile "sudoers.lecture" '' +  + ${dominantEscapeCode}"Bee" careful __ + ${dominantEscapeCode}with sudo! // \ + \\_/ // + '''-.._.-'''-.._.. -(||)(') + '''' - ''; - in - '' - Defaults lecture = always - Defaults lecture_file = "${lectureFile}" ''; + in '' + Defaults lecture = always + Defaults lecture_file = "${lectureFile}" + ''; home-manager.users.minijackson = { programs.bash.enable = true; @@ -88,9 +85,26 @@ in }; programs.pazi.enable = true; + + programs.exa = { + enable = true; + enableAliases = true; + }; + + home.sessionVariables = { + EXA_COLORS = let + spec = set: + lib.concatStringsSep ":" + (lib.mapAttrsToList + (key: value: "${key}=${value}") + set); + in + spec { + }; + }; }; - home-manager.users.root = { ... }: { + home-manager.users.root = {...}: { programs.bash.enable = true; programs.pazi = lib.mkDefault config.home-manager.users.minijackson.programs.pazi; programs.bat = lib.mkDefault config.home-manager.users.minijackson.programs.bat; diff --git a/common/commandline/dircolors.nix b/common/commandline/dircolors.nix index f7bdae1..3d27f73 100644 --- a/common/commandline/dircolors.nix +++ b/common/commandline/dircolors.nix @@ -1,76 +1,324 @@ -inputs: - -{ config, lib, ... }: - -{ - home-manager.users.minijackson = { ... }: - { - programs.dircolors = { - enable = true; - settings = { - # Enable on the alacritty terminal - TERM = "alacritty*"; - - DIR = "01;94"; - EXEC = "01;92"; - - FIFO = "93"; # pipe" - BLK = "93;01"; # block device driver" - CHR = "93;01"; # character device driver" - - # archives or compressed (yellow) - ".tar" = "01;33"; - ".tgz" = "01;33"; - ".arc" = "01;33"; - ".arj" = "01;33"; - ".taz" = "01;33"; - ".lha" = "01;33"; - ".lz4" = "01;33"; - ".lzh" = "01;33"; - ".lzma" = "01;33"; - ".tlz" = "01;33"; - ".txz" = "01;33"; - ".tzo" = "01;33"; - ".t7z" = "01;33"; - ".zip" = "01;33"; - ".z" = "01;33"; - ".dz" = "01;33"; - ".gz" = "01;33"; - ".lrz" = "01;33"; - ".lz" = "01;33"; - ".lzo" = "01;33"; - ".xz" = "01;33"; - ".zst" = "01;33"; - ".tzst" = "01;33"; - ".bz2" = "01;33"; - ".bz" = "01;33"; - ".tbz" = "01;33"; - ".tbz2" = "01;33"; - ".tz" = "01;33"; - ".deb" = "01;33"; - ".rpm" = "01;33"; - ".jar" = "01;33"; - ".war" = "01;33"; - ".ear" = "01;33"; - ".sar" = "01;33"; - ".rar" = "01;33"; - ".alz" = "01;33"; - ".ace" = "01;33"; - ".zoo" = "01;33"; - ".cpio" = "01;33"; - ".7z" = "01;33"; - ".rz" = "01;33"; - ".cab" = "01;33"; - ".wim" = "01;33"; - ".swm" = "01;33"; - ".dwm" = "01;33"; - ".esd" = "01;33"; - }; - }; +inputs: { + config, + lib, + ... +}: { + programs.bash.enableLsColors = false; + + home-manager.users.minijackson = {config, ...}: { + # Due to GRML calling dircolors, despite the fact that LS_COLORS is already + # defined + programs.zsh.initExtra = '' + ${lib.toShellVar "LS_COLORS" config.home.sessionVariables.LS_COLORS} + zstyle ':completion:*:default' list-colors ''${(s.:.)LS_COLORS} + ''; + + # TODO: this is not really compatible with 'ls', and hence not compatible + # with other tools e.g. bash + home.sessionVariables.LS_COLORS = let + ls_colors = set: + lib.concatStringsSep ":" + (lib.mapAttrsToList + (key: value: "${key}=${value}") + set); + + bold = "01"; + underline = "04"; + + red = "31"; + green = "32"; + yellow = "33"; + blue = "34"; + purple = "35"; + cyan = "36"; + white = "37"; + + # Partially from: + # https://github.com/ogham/exa/blob/fc6a6d0b38bcf4849e67955d4b60d5d786fceba1/src/info/filetype.rs#L17 + + immediate_files = [ + # Bash expects file types in LS_COLORS to start with "*", so we add + # them, despite adding false positives + + "*readme*" + "*Readme*" + "*README*" + + # Bash and zsh doesn't support globs except the starting one + "*README.md" + "*README.rst" + + "*.ninja" + + "*BUILD" + "*BUILD.bazel" + "*Brewfile" + "*CMakeLists.txt" + "*Cargo.toml" + "*Containerfile" + "*Dockerfile" + "*Gemfile" + "*Gruntfile.coffee" + "*Gruntfile.js" + "*Justfile" + "*Makefile" + "*PKGBUILD" + "*Pipfile" + "*Podfile" + "*Procfile" + "*Rakefile" + "*RoboFile.php" + "*SConstruct" + "*Vagrantfile" + "*WORKSPACE" + "*bsconfig.json" + "*build.gradle" + "*build.sbt" + "*build.xml" + "*composer.json" + "*meson.build" + "*mix.exs" + "*package.json" + "*pom.xml" + "*tsconfig.json" + "*webpack.config.js" + ]; + immediate_style = "${bold};${underline};${yellow}"; + + image_files = [ + "*.arw" + "*.avif" + "*.bmp" + "*.cbr" + "*.cbz" + "*.cr2" + "*.dvi" + "*.eps" + "*.gif" + "*.heif" + "*.ico" + "*.j2c" + "*.j2k" + "*.jfi" + "*.jfif" + "*.jif" + "*.jp2" + "*.jpe" + "*.jpeg" + "*.jpf" + "*.jpg" + "*.jpx" + "*.jxl" + "*.nef" + "*.orf" + "*.pbm" + "*.pgm" + "*.png" + "*.pnm" + "*.ppm" + "*.ps" + "*.raw" + "*.stl" + "*.svg" + "*.tif" + "*.tiff" + "*.webp" + "*.xpm" + ]; + image_style = "${purple}"; + + video_files = [ + "*.avi" + "*.flv" + "*.heic" + "*.m2ts" + "*.m2v" + "*.m4v" + "*.mkv" + "*.mov" + "*.mp4" + "*.mpeg" + "*.mpg" + "*.ogm" + "*.ogv" + "*.vob" + "*.webm" + "*.wmv" + ]; + video_style = "${purple}"; + + audio_files = [ + "*.aac" + "*.alac" + "*.ape" + "*.flac" + "*.m4a" + "*.mka" + "*.mp3" + "*.ogg" + "*.opus" + "*.wav" + "*.wma" + ]; + audio_style = "${cyan}"; + + crypto_files = [ + "*.asc" + "*.enc" + "*.gpg" + "*.p12" + "*.pfx" + "*.pgp" + "*.sig" + "*.signature" + ]; + crypto_style = "${bold};${cyan}"; + + document_files = [ + "*.djvu" + "*.doc" + "*.docx" + "*.dvi" + "*.eml" + "*.eps" + "*.fotd" + "*.key" + "*.keynote" + "*.numbers" + "*.odp" + "*.odt" + "*.pages" + "*.pdf" + "*.ppt" + "*.pptx" + "*.rtf" + "*.xls" + "*.xlsx" + ]; + document_style = "${yellow}"; + + compressed_files = [ + "*.7z" + "*.Z" + "*.a" + "*.ace" + "*.alz" + "*.ar" + "*.arc" + "*.arj" + "*.bz" + "*.bz2" + "*.cab" + "*.cpio" + "*.deb" + "*.dwm" + "*.dz" + "*.ear" + "*.esd" + "*.gz" + "*.iso" + "*.jar" + "*.lha" + "*.lrz" + "*.lz" + "*.lz4" + "*.lzh" + "*.lzma" + "*.lzo" + "*.rar" + "*.rpm" + "*.rz" + "*.sar" + "*.swm" + "*.t7z" + "*.tar" + "*.taz" + "*.tbz" + "*.tbz2" + "*.tgz" + "*.tlz" + "*.txz" + "*.tz" + "*.tzo" + "*.tzst" + "*.war" + "*.wim" + "*.xz" + "*.z" + "*.zip" + "*.zoo" + "*.zst" + ]; + compressed_style = "${red}"; + + temp_files = [ + "*#" + "*~" + "*.bak" + "*.bk" + "*.bkp" + "*.dpkg-dist" + "*.dpkg-old" + "*.old" + "*.orig" + "*.part" + "*.rej" + "*.rpmnew" + "*.rpmorig" + "*.rpmsave" + "*.swn" + "*.swo" + "*.swp" + "*.tmp" + "*.ucf-dist" + "*.ucf-new" + "*.ucf-old" + ]; + # Gray + temp_style = "38;5;244"; + + compiled_files = [ + "*.class" + "*.elc" + "*.hi" + "*.ko" + "*.o" + "*.pyc" + "*.zwc" + ]; + # Gray + compiled_style = "38;5;137"; + + style = files: style: lib.genAttrs files (_: style); + + colors = ls_colors ({ + # directory + di = "${bold};${blue}"; + # executable + ex = "${bold};${green}"; + + # pipe + pi = "${yellow}"; + # block device + bd = "${bold};${yellow}"; + # character device + cd = "${bold};${yellow}"; + + so = "${bold};${purple}"; + } + // (style immediate_files immediate_style) + // (style image_files image_style) + // (style video_files video_style) + // (style audio_files audio_style) + // (style crypto_files crypto_style) + // (style document_files document_style) + // (style compressed_files compressed_style) + // (style temp_files temp_style) + // (style compiled_files compiled_style)); + in "rs=0:${colors}"; }; - home-manager.users.root = { ... }: - { + home-manager.users.root = {...}: { programs.dircolors = lib.mkDefault config.home-manager.users.minijackson.programs.dircolors; }; -- cgit v1.2.3