aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorpacien2022-11-13 20:02:01 +0100
committerpacien2022-11-13 20:22:58 +0100
commit67ca8e5e889d289f9758f303b67dbcaf99fcd742 (patch)
tree7784b9b04edb0c240620cd372bc7b7bd52ebcd80 /lib
parent511dcc29a2e0fb39dc413f8c7cfab8d28a93afab (diff)
downloadflaky-utils-67ca8e5e889d289f9758f303b67dbcaf99fcd742.tar.gz
mkDevShell: more readable and coloured info prints
Diffstat (limited to 'lib')
-rw-r--r--lib/mk-dev-shell.nix27
1 files 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 @@
7with pkgs.lib; 7with pkgs.lib;
8 8
9let 9let
10 mapAttrsToLines = mapping: attrs:
11 pkgs.lib.concatStringsSep "\n" (pkgs.lib.mapAttrsToList mapping attrs);
12
10 exportEnvVar = k: v: '' 13 exportEnvVar = k: v: ''
11 export ${escapeShellArg k}="${v}" 14 export ${escapeShellArg k}="${v}"
12 ''; 15 '';
13 16
14 exportEnvVarsHook = envVars: '' 17 exportEnvVarsHook = mapAttrsToLines exportEnvVar;
15 ${pkgs.lib.concatStringsSep "\n" ( 18
16 pkgs.lib.mapAttrsToList exportEnvVar envVars 19 fmt = rec {
17 )} 20 codeBlock = code: text: ''"\e[${code}m"${text}"\e[0m"'';
18 ''; 21 keyword = codeBlock "1;36";
22 section = codeBlock "4;35";
23 printSectionTitle = title: ''echo -e "\n\n"${section title}"\n"'';
24 };
19 25
20 printEnvVar = k: v: '' 26 printEnvVar = k: v: ''
21 echo ${escapeShellArg k}=${escapeShellArg v} 27 echo -e ${fmt.keyword (escapeShellArg "$" + k)}: ${escapeShellArg v}
22 ''; 28 '';
23 29
24 printEnvVarsHook = envVars: '' 30 printEnvVarsHook = envVars: ''
25 echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:" 31 ${fmt.printSectionTitle "DEVSHELL ENVIRONMENT VARIABLES"}
26 ${pkgs.lib.concatStringsSep "\n" ( 32 ${mapAttrsToLines printEnvVar envVars}
27 pkgs.lib.mapAttrsToList printEnvVar envVars
28 )}
29 ''; 33 '';
30 34
31 printToolsHook = tools: '' 35 printToolsHook = tools: ''
32 echo -e "\nDEVSHELL COMMANDS:" 36 ${fmt.printSectionTitle "DEVSHELL TOOLS"}
33 ls "${pkgs.symlinkJoin { name = "env"; paths = tools; }}/bin" 37 ls "${pkgs.symlinkJoin { name = "env"; paths = tools; }}/bin"
34 ''; 38 '';
35 39
@@ -46,6 +50,7 @@ in pkgs.mkShell {
46 50
47 ${optionalString (envVars != {}) (printEnvVarsHook envVars)} 51 ${optionalString (envVars != {}) (printEnvVarsHook envVars)}
48 ${optionalString (tools != []) (printToolsHook tools)} 52 ${optionalString (tools != []) (printToolsHook tools)}
53 echo
49 54
50 ${if (shell != null) then shell else startUserShellHook} 55 ${if (shell != null) then shell else startUserShellHook}
51 exit $? 56 exit $?