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