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