1 { pkgs, lib, config, ... }:
6 eic = "edit-in-commit";
7 eigg = "edit-in-git-grep";
8 emacs = "emacsclient --create-frame";
10 grep = "grep --color";
11 j="sudo journalctl -u";
12 jb="sudo journalctl -b";
15 ls = "ls --color=tty";
16 md-toc = "grep '^#\\+' --color";
17 mem = "ps -e -orss=,user=,args= | sort -b -k1,1n";
18 mem-top = "smem --sort rss --autosize";
20 nixos-clean="sudo nix-collect-garbage -d";
21 nixos-history="sudo nix-env --list-generations --profile /nix/var/nix/profiles/system";
22 nixos-rollback="sudo nixos-rebuild switch --rollback";
23 rsync = "rsync --no-inc-recursive --info=progress2 --inplace --partial";
25 st="sudo systemctl status";
27 ut="systemctl --user status";
28 watch = "watch --color";
29 zfs-umount = "zfs-unmount";
33 # Disable ctrl-s/ctrl-q flow control
41 device=''${1:-/dev/sda}
42 sudo smartctl -A $device |
44 $0 ~ /Power_On_Hours/ { poh=$10; printf "%s / %d hours / %d days / %.2f years\n", $2, $10, $10 / 24, $10 / 24 / 365.25 }
45 $0 ~ /Total_LBAs_Written/ {
51 printf "%s / %s / %d mb / %.1f gb / %.3f tb\n", $2, $10, mb, gb, tb
52 printf "mean writes per hour: / %.2f", mb/poh
54 $0 ~ /Airflow_Temperature_Cel/ { print $2 " / " $10}
55 $0 ~ /Wear_Leveling_Count/ { printf "%s / %d (%% health)\n", $2, int($4) }
58 sed -e "s\$^\$$device @ \$" |
64 sudo grep -H '^Swap:' /proc/*/smaps 2>/dev/null |
65 while IFS=: read -r file x size x
71 if test "$pid" = "$lastpid"
72 then swap=$(( swap + size ))
75 then printf "%u pid=%u cmd=%s\n" "$swap" "$lastpid" "$(tr '\000' ' ' </proc/"$lastpid"/cmdline)"
87 edit-in-commit () { $EDITOR $(git diff-tree --no-commit-id --name-only -r "$@"); }
88 edit-in-git-grep () { $EDITOR $(git grep --name-only --recursive "$@"); }
89 zfs-mount () { for d in $(zfs list -rH -o name "$@"); do sudo zfs mount -l "$d"; done; }
90 zfs-unmount () { sudo zfs unmount -u "$@"; }
95 programs.direnv.enableBashIntegration = true;
96 programs.broot.enableBashIntegration = true;
97 home.sessionVariables = {
98 PS1 = ''\[\033[1;32m\]\[\e]0;\u@\h: \w\a\]\W\[\033[0m\] \$(e=\$?; if [ \$e != 0 ]; then echo '\[\e[0;91m\]'\$e'\[\e[0m\]'; fi)\$ '';
100 programs.readline = {
101 enable = lib.mkDefault config.programs.bash.enable;
102 includeSystemConfig = true;
104 "\\eOF" = "end-of-line";
105 "\\eOH" = "beginning-of-line";
106 "\\e[1;5C" = "forward-word";
107 "\\e[1;5D" = "backward-word";
108 "\\e[1~" = "beginning-of-line";
109 "\\e[4~" = "end-of-line";
110 "\\e[5C" = "forward-word";
111 "\\e[5D" = "backward-word";
112 "\\e[7~" = "beginning-of-line";
113 "\\e[8~" = "end-of-line";
114 "\\e[A" = "history-search-backward";
115 "\\e[B" = "history-search-forward";
116 "\\e[F" = "end-of-line";
117 "\\e[H" = "beginning-of-line";
118 "\\e\\e[C" = "forward-word";
119 "\\e\\e[D" = "backward-word";
122 colored-completion-prefix = lib.mkDefault true;
123 colored-stats = lib.mkDefault true; # Note that this may cause completion text blink in some terminals (e.g. xterm).
124 echo-control-characters = lib.mkDefault true;
125 mark-symlinked-directories = lib.mkDefault true;
126 menu-complete-display-prefix = lib.mkDefault true;
127 show-all-if-ambiguous = lib.mkDefault true;
128 show-all-if-unmodified = lib.mkDefault true;
129 visible-stats = lib.mkDefault false; # Append char to indicate type