diff options
author | pacien | 2022-11-14 00:39:47 +0100 |
---|---|---|
committer | pacien | 2022-11-14 00:39:47 +0100 |
commit | e8459a4a34f2611a547b966b2c58867d99d0f40c (patch) | |
tree | a97b7d60808e210df1743d00d10b393c21484a59 /lib/shell.nix | |
parent | 67ca8e5e889d289f9758f303b67dbcaf99fcd742 (diff) | |
download | flaky-utils-e8459a4a34f2611a547b966b2c58867d99d0f40c.tar.gz |
mkDevShell: extract shell hooks
Diffstat (limited to 'lib/shell.nix')
-rw-r--r-- | lib/shell.nix | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/shell.nix b/lib/shell.nix new file mode 100644 index 0000000..3f6defc --- /dev/null +++ b/lib/shell.nix | |||
@@ -0,0 +1,44 @@ | |||
1 | flake: | ||
2 | { pkgs | ||
3 | }: | ||
4 | |||
5 | with pkgs.lib; | ||
6 | |||
7 | let | ||
8 | mapAttrsToLines = mapping: attrs: | ||
9 | pkgs.lib.concatStringsSep "\n" (pkgs.lib.mapAttrsToList mapping attrs); | ||
10 | |||
11 | fmt = rec { | ||
12 | codeBlock = code: text: ''"\e[${code}m"${text}"\e[0m"''; | ||
13 | keyword = codeBlock "1;36"; | ||
14 | section = codeBlock "4;35"; | ||
15 | printSectionTitle = title: ''echo -e "\n\n"${section title}"\n"''; | ||
16 | }; | ||
17 | |||
18 | in rec { | ||
19 | exportEnvVar = k: v: '' | ||
20 | export ${escapeShellArg k}="${v}" | ||
21 | ''; | ||
22 | |||
23 | exportEnvVars = mapAttrsToLines exportEnvVar; | ||
24 | |||
25 | printEnvVar = k: v: '' | ||
26 | echo -e ${fmt.keyword (escapeShellArg "$" + k)}: ${escapeShellArg v} | ||
27 | ''; | ||
28 | |||
29 | printEnvVars = envVars: '' | ||
30 | ${fmt.printSectionTitle "ENVIRONMENT VARIABLES"} | ||
31 | ${mapAttrsToLines printEnvVar envVars} | ||
32 | ''; | ||
33 | |||
34 | printBins = packagePaths: '' | ||
35 | ${fmt.printSectionTitle "TOOLS"} | ||
36 | ls "${pkgs.symlinkJoin { name = "env"; paths = packagePaths; }}/bin" | ||
37 | ''; | ||
38 | |||
39 | # Use the default user shell instead of Bash | ||
40 | startUserShell = '' | ||
41 | $(${pkgs.finger_bsd}/bin/finger $USER \ | ||
42 | | ${pkgs.gnugrep}/bin/grep -oP 'Shell: \K.*') | ||
43 | ''; | ||
44 | } | ||