From 67ca8e5e889d289f9758f303b67dbcaf99fcd742 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 13 Nov 2022 20:02:01 +0100 Subject: mkDevShell: more readable and coloured info prints --- lib/mk-dev-shell.nix | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/mk-dev-shell.nix b/lib/mk-dev-shell.nix index 0e2a265..87b9dbb 100644 --- a/lib/mk-dev-shell.nix +++ b/lib/mk-dev-shell.nix @@ -7,29 +7,33 @@ with pkgs.lib; let + mapAttrsToLines = mapping: attrs: + pkgs.lib.concatStringsSep "\n" (pkgs.lib.mapAttrsToList mapping attrs); + exportEnvVar = k: v: '' export ${escapeShellArg k}="${v}" ''; - exportEnvVarsHook = envVars: '' - ${pkgs.lib.concatStringsSep "\n" ( - pkgs.lib.mapAttrsToList exportEnvVar envVars - )} - ''; + exportEnvVarsHook = mapAttrsToLines exportEnvVar; + + fmt = rec { + codeBlock = code: text: ''"\e[${code}m"${text}"\e[0m"''; + keyword = codeBlock "1;36"; + section = codeBlock "4;35"; + printSectionTitle = title: ''echo -e "\n\n"${section title}"\n"''; + }; printEnvVar = k: v: '' - echo ${escapeShellArg k}=${escapeShellArg v} + echo -e ${fmt.keyword (escapeShellArg "$" + k)}: ${escapeShellArg v} ''; printEnvVarsHook = envVars: '' - echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:" - ${pkgs.lib.concatStringsSep "\n" ( - pkgs.lib.mapAttrsToList printEnvVar envVars - )} + ${fmt.printSectionTitle "DEVSHELL ENVIRONMENT VARIABLES"} + ${mapAttrsToLines printEnvVar envVars} ''; printToolsHook = tools: '' - echo -e "\nDEVSHELL COMMANDS:" + ${fmt.printSectionTitle "DEVSHELL TOOLS"} ls "${pkgs.symlinkJoin { name = "env"; paths = tools; }}/bin" ''; @@ -46,6 +50,7 @@ in pkgs.mkShell { ${optionalString (envVars != {}) (printEnvVarsHook envVars)} ${optionalString (tools != []) (printToolsHook tools)} + echo ${if (shell != null) then shell else startUserShellHook} exit $? -- cgit v1.2.3