]> Git — Sourcephile - julm/julm-nix.git/blob - homes/programs/bash.nix
bash: rename aliases
[julm/julm-nix.git] / homes / programs / bash.nix
1 { pkgs, lib, config, ... }:
2 {
3 programs.bash = {
4 shellAliases = {
5 cl = "clear";
6 eic = "edit-in-commit";
7 eigg = "edit-in-git-grep";
8 g = "git";
9 grep = "grep --color";
10 j="sudo journalctl -u";
11 jb="sudo journalctl -b";
12 l = "ls -alh";
13 ll = "ls -al";
14 ls = "ls --color=tty";
15 md-toc = "grep '^#\\+' --color";
16 mem = "ps -e -orss=,user=,args= | sort -b -k1,1n";
17 mem-top = "smem --sort rss --autosize";
18 mpl = "mplayer";
19 nixos-clean="sudo nix-collect-garbage -d";
20 nixos-history="sudo nix-env --list-generations --profile /nix/var/nix/profiles/system";
21 nixos-rollback="sudo nixos-rebuild switch --rollback";
22 rsync = "rsync --no-inc-recursive --info=progress2 --inplace --partial";
23 s="sudo systemctl";
24 st="sudo systemctl status";
25 u="systemctl --user";
26 ut="systemctl --user status";
27 watch = "watch --color";
28 zfs-umount = "zfs-unmount";
29 };
30 initExtra = ''
31 shopt -s globstar
32 # Disable ctrl-s/ctrl-q flow control
33 stty -ixon
34
35 mkcd () {
36 mkdir -p "$1" &&
37 cd "$1"
38 }
39 smartctl-tbw () {
40 device=''${1:-/dev/sda}
41 sudo smartctl -A $device |
42 { awk '
43 $0 ~ /Power_On_Hours/ { poh=$10; printf "%s / %d hours / %d days / %.2f years\n", $2, $10, $10 / 24, $10 / 24 / 365.25 }
44 $0 ~ /Total_LBAs_Written/ {
45 lbas = $10;
46 bytes = $10 * 512;
47 mb = bytes / 1024^2;
48 gb = bytes / 1024^3;
49 tb = bytes / 1024^4;
50 printf "%s / %s / %d mb / %.1f gb / %.3f tb\n", $2, $10, mb, gb, tb
51 printf "mean writes per hour: / %.2f", mb/poh
52 }
53 $0 ~ /Airflow_Temperature_Cel/ { print $2 " / " $10}
54 $0 ~ /Wear_Leveling_Count/ { printf "%s / %d (%% health)\n", $2, int($4) }
55 '; echo; } |
56 sed -e 's:/:@:' |
57 sed -e "s\$^\$$device @ \$" |
58 column -ts@
59 }
60 swaplist () {
61 lastpid=
62 swap=0
63 sudo grep -H '^Swap:' /proc/*/smaps 2>/dev/null |
64 while IFS=: read -r file x size x
65 do
66 pid=''${file#/proc/}
67 pid=''${pid%/smaps}
68 size=''${size% kB}
69 size=''${size##* }
70 if test "$pid" = "$lastpid"
71 then swap=$(( swap + size ))
72 else
73 if test "$swap" -gt 0
74 then printf "%u pid=%u cmd=%s\n" "$swap" "$lastpid" "$(tr '\000' ' ' </proc/"$lastpid"/cmdline)"
75 fi
76 if test "$pid" = self
77 then break
78 else
79 lastpid=$pid
80 swap=$size
81 fi
82 fi
83 done |
84 sort -nk1,1
85 }
86 edit-in-commit () { $EDITOR $(git diff-tree --no-commit-id --name-only -r "$@"); }
87 edit-in-git-grep () { $EDITOR $(git grep --name-only --recursive "$@"); }
88 zfs-mount () { for d in $(zfs list -rH -o name "$@"); do sudo zfs mount -l "$d"; done; }
89 zfs-unmount () { sudo zfs unmount -u "$@"; }
90 '';
91 profileExtra = ''
92 '';
93 };
94 programs.direnv.enableBashIntegration = true;
95 programs.broot.enableBashIntegration = true;
96 home.sessionVariables = {
97 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)\$ '';
98 };
99 programs.readline = {
100 enable = lib.mkDefault config.programs.bash.enable;
101 includeSystemConfig = true;
102 bindings = {
103 "\\eOF" = "end-of-line";
104 "\\eOH" = "beginning-of-line";
105 "\\e[1;5C" = "forward-word";
106 "\\e[1;5D" = "backward-word";
107 "\\e[1~" = "beginning-of-line";
108 "\\e[4~" = "end-of-line";
109 "\\e[5C" = "forward-word";
110 "\\e[5D" = "backward-word";
111 "\\e[7~" = "beginning-of-line";
112 "\\e[8~" = "end-of-line";
113 "\\e[A" = "history-search-backward";
114 "\\e[B" = "history-search-forward";
115 "\\e[F" = "end-of-line";
116 "\\e[H" = "beginning-of-line";
117 "\\e\\e[C" = "forward-word";
118 "\\e\\e[D" = "backward-word";
119 };
120 variables = {
121 colored-completion-prefix = lib.mkDefault true;
122 colored-stats = lib.mkDefault true; # Note that this may cause completion text blink in some terminals (e.g. xterm).
123 echo-control-characters = lib.mkDefault true;
124 mark-symlinked-directories = lib.mkDefault true;
125 menu-complete-display-prefix = lib.mkDefault true;
126 show-all-if-ambiguous = lib.mkDefault true;
127 show-all-if-unmodified = lib.mkDefault true;
128 visible-stats = lib.mkDefault false; # Append char to indicate type
129 };
130 };
131 }