From 4e8caf4ebfda44d8e0f3d4d7a1342d5508caaa64 Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Tue, 28 Nov 2023 09:20:10 -0800 Subject: [PATCH] Name ANSI color codes --- common/components/shell.user.nix | 80 ++++++++++++++++---------------- common/resources/palette.nix | 12 ++++- 2 files changed, 52 insertions(+), 40 deletions(-) diff --git a/common/components/shell.user.nix b/common/components/shell.user.nix index a9c243c..93e08bc 100644 --- a/common/components/shell.user.nix +++ b/common/components/shell.user.nix @@ -3,6 +3,8 @@ let inherit (lib) concatLines concatStringsSep genAttrs mapAttrsToList toShellVar; + palette = import ../resources/palette.nix { inherit lib; }; + toAbbrs = kv: concatLines (mapAttrsToList (k: v: "abbr ${toShellVar k v}") kv); in { @@ -137,44 +139,44 @@ in undo = "git restore --patch"; }; - home.sessionVariables.EXA_COLORS = concatStringsSep ":" (mapAttrsToList (k: v: "${k}=${v}") { - ur = "2;37"; # the user-read permission bit - uw = "2;37"; # the user-write permission bit - ux = "1;32"; # the user-execute permission bit for regular files - ue = "1;32"; # the user-execute for other file kinds - gr = "2;37"; # the group-read permission bit - gw = "2;37"; # the group-write permission bit - gx = "2;37"; # the group-execute permission bit - tr = "1;35"; # the others-read permission bit - tw = "1;31"; # the others-write permission bit - tx = "2;37"; # the others-execute permission bit - su = "1;33"; # setuid, setgid, and sticky permission bits for files - sf = "1;33"; # setuid, setgid, and sticky for other file kinds - xa = "1;33"; # the extended attribute indicator - sn = "2;37"; # the numbers of a file’s size - ub = "1;37"; # the units of a file’s size if it is lower than 1 KB/Kib - uk = "1;34"; # the units of a file’s size if it is between 1 KB/KiB and 1 MB/MiB - um = "1;33"; # the units of a file’s size if it is between 1 MB/MiB and 1 GB/GiB - ug = "1;31"; # the units of a file’s size if it is between 1 GB/GiB and 1 TB/TiB - ut = "1;31"; # the units of a file’s size if it is 1 TB/TiB or higher - uu = "30"; # a user that’s you - un = "31"; # a user that’s someone else - gu = "30"; # a group that you belong to - gn = "31"; # a group you aren’t a member of - da = "2;3;37"; # a file’s date - lp = "2;37"; # the path of a symlink - cc = "1;33"; # an escaped character in a filename - }); + home.sessionVariables.EXA_COLORS = concatStringsSep ":" (mapAttrsToList (k: v: "${k}=${v}") (with palette.ansi; { + ur = dim.white; # the user-read permission bit + uw = dim.white; # the user-write permission bit + ux = bold.green; # the user-execute permission bit for regular files + ue = bold.green; # the user-execute for other file kinds + gr = dim.white; # the group-read permission bit + gw = dim.white; # the group-write permission bit + gx = dim.white; # the group-execute permission bit + tr = bold.magenta; # the others-read permission bit + tw = bold.red; # the others-write permission bit + tx = dim.white; # the others-execute permission bit + su = bold.yellow; # setuid, setgid, and sticky permission bits for files + sf = bold.yellow; # setuid, setgid, and sticky for other file kinds + xa = bold.yellow; # the extended attribute indicator + sn = dim.white; # the numbers of a file’s size + ub = bold.white; # the units of a file’s size if it is lower than 1 KB/Kib + uk = bold.blue; # the units of a file’s size if it is between 1 KB/KiB and 1 MB/MiB + um = bold.yellow; # the units of a file’s size if it is between 1 MB/MiB and 1 GB/GiB + ug = bold.red; # the units of a file’s size if it is between 1 GB/GiB and 1 TB/TiB + ut = bold.red; # the units of a file’s size if it is 1 TB/TiB or higher + uu = black; # a user that’s you + un = red; # a user that’s someone else + gu = black; # a group that you belong to + gn = red; # a group you aren’t a member of + da = dim.italic.white; # a file’s date + lp = dim.white; # the path of a symlink + cc = bold.yellow; # an escaped character in a filename + })); - home.sessionVariables.LS_COLORS = concatStringsSep ":" (mapAttrsToList (k: v: "${k}=${v}") { - di = "1;36"; # directories - ex = "32"; # executable files - fi = "37"; # regular files - pi = "3;34"; # named pipes - so = "3;34"; # sockets - bd = "1;34"; # block devices - cd = "1;34"; # character devices - ln = "35"; # symlinks - or = "31"; # symlinks with no target - }); + home.sessionVariables.LS_COLORS = concatStringsSep ":" (mapAttrsToList (k: v: "${k}=${v}") (with palette.ansi; { + di = bold.cyan; # directories + ex = green; # executable files + fi = white; # regular files + pi = italic.blue; # named pipes + so = italic.blue; # sockets + bd = bold.blue; # block devices + cd = bold.blue; # character devices + ln = magenta; # symlinks + or = red; # symlinks with no target + })); } diff --git a/common/resources/palette.nix b/common/resources/palette.nix index a006f63..53f2025 100644 --- a/common/resources/palette.nix +++ b/common/resources/palette.nix @@ -1,9 +1,12 @@ { lib }: let - inherit (builtins) mapAttrs substring; + inherit (builtins) listToAttrs mapAttrs substring; + inherit (lib) imap0 nameValuePair; inherit ((import { }).lib.conversions) hexToRGB; + ansiNames = [ "black" "red" "green" "yellow" "blue" "magenta" "cyan" "white" ]; + asHex = { # Monokai black = "#1b1b1b"; @@ -36,6 +39,13 @@ let }; in asHex // rec { + ansi = + let + base = listToAttrs (imap0 (i: n: nameValuePair n (toString (30 + i))) ansiNames); + effect = p: mapAttrs (_: a: "${p};${a}") base; + in + base // { bold = effect "1"; dim = effect "2" // { italic = effect "2;3"; }; italic = effect "3"; }; + asFloat = mapAttrs (_: cs: map (c: c / 255.0) cs) asInt; asInt = mapAttrs (_: h: hexToRGB (substring 1 6 h)) asHex;