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