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