]> Git — Sourcephile - julm/julm-nix.git/blob - homes/softwares/bash.nix
git: cleanup aliases
[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 };
70 programs.direnv.enableBashIntegration = true;
71 programs.broot.enableBashIntegration = true;
72 home.sessionVariables = {
73 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)\$ '';
74 };
75 home.file.".inputrc".text = ''
76 "\e[1~": beginning-of-line
77 "\e[4~": end-of-line
78 "\e[7~": beginning-of-line
79 "\e[8~": end-of-line
80 "\eOH": beginning-of-line
81 "\eOF": end-of-line
82 "\e[H": beginning-of-line
83 "\e[F": end-of-line
84 "\e[1;5C": forward-word
85 "\e[1;5D": backward-word
86 "\e[5C": forward-word
87 "\e[5D": backward-word
88 "\e\e[C": forward-word
89 "\e\e[D": backward-word
90 '';
91 }