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