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