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