aboutsummaryrefslogtreecommitdiff
path: root/lib/shell.nix
diff options
context:
space:
mode:
authorpacien2022-11-14 00:39:47 +0100
committerpacien2022-11-14 00:39:47 +0100
commite8459a4a34f2611a547b966b2c58867d99d0f40c (patch)
treea97b7d60808e210df1743d00d10b393c21484a59 /lib/shell.nix
parent67ca8e5e889d289f9758f303b67dbcaf99fcd742 (diff)
downloadflaky-utils-e8459a4a34f2611a547b966b2c58867d99d0f40c.tar.gz
mkDevShell: extract shell hooks
Diffstat (limited to 'lib/shell.nix')
-rw-r--r--lib/shell.nix44
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 @@
1flake:
2{ pkgs
3}:
4
5with pkgs.lib;
6
7let
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
18in 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}