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