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