]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/bash.nix
yt-dlp: enable --embed-subs
[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 shopt -s histreedit
38 shopt -s histverify
39 # Disable ctrl-s/ctrl-q flow control
40 stty -ixon
41
42 ibm-fan () {
43 if [ $# -gt 0 ]
44 then sudo tee /proc/acpi/ibm/fan <<<"level $1"
45 else grep '^\(level\|speed\):' /proc/acpi/ibm/fan
46 fi
47 acpi -t
48 }
49 mkcd () {
50 mkdir -p "$1" &&
51 cd "$1"
52 }
53 smartctl-tbw () {
54 device=''${1:-/dev/sda}
55 sudo smartctl -A $device |
56 { awk '
57 $0 ~ /Power_On_Hours/ { poh=$10; printf "%s / %d hours / %d days / %.2f years\n", $2, $10, $10 / 24, $10 / 24 / 365.25 }
58 $0 ~ /Total_LBAs_Written/ {
59 lbas = $10;
60 bytes = $10 * 512;
61 mb = bytes / 1024^2;
62 gb = bytes / 1024^3;
63 tb = bytes / 1024^4;
64 printf "%s / %s / %d mb / %.1f gb / %.3f tb\n", $2, $10, mb, gb, tb
65 printf "mean writes per hour: / %.2f", mb/poh
66 }
67 $0 ~ /Airflow_Temperature_Cel/ { print $2 " / " $10}
68 $0 ~ /Wear_Leveling_Count/ { printf "%s / %d (%% health)\n", $2, int($4) }
69 '; echo; } |
70 sed -e 's:/:@:' |
71 sed -e "s\$^\$$device @ \$" |
72 column -ts@
73 }
74 swaplist () {
75 lastpid=
76 swap=0
77 sudo grep -H '^Swap:' /proc/*/smaps 2>/dev/null |
78 while IFS=: read -r file x size x
79 do
80 pid=''${file#/proc/}
81 pid=''${pid%/smaps}
82 size=''${size% kB}
83 size=''${size##* }
84 if test "$pid" = "$lastpid"
85 then swap=$(( swap + size ))
86 else
87 if test "$swap" -gt 0
88 then printf "%u pid=%u cmd=%s\n" "$swap" "$lastpid" "$(tr '\000' ' ' </proc/"$lastpid"/cmdline)"
89 fi
90 if test "$pid" = self
91 then break
92 else
93 lastpid=$pid
94 swap=$size
95 fi
96 fi
97 done |
98 sort -nk1,1
99 }
100 edit-in-commit () { $EDITOR $(git diff-tree --no-commit-id --name-only -r "$@"); }
101 edit-in-git-grep () { $EDITOR $(git grep --name-only --recursive "$@"); }
102 zfs-mount () { for d in $(zfs list -rH -o name "$@"); do sudo zfs mount -l "$d"; done; }
103 zfs-unmount () { sudo zfs unmount -u "$@"; }
104 '';
105 profileExtra = ''
106 '';
107 };
108 programs.direnv.enableBashIntegration = true;
109 #programs.broot.enableBashIntegration = true;
110 home.sessionVariables = {
111 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)\$ '';
112 };
113 programs.readline = {
114 enable = lib.mkDefault true;
115 includeSystemConfig = true;
116 bindings = {
117 "\\eOF" = "end-of-line";
118 "\\eOH" = "beginning-of-line";
119 "\\e[1;5C" = "forward-word";
120 "\\e[1;5D" = "backward-word";
121 "\\e[1~" = "beginning-of-line";
122 "\\e[4~" = "end-of-line";
123 "\\e[5C" = "forward-word";
124 "\\e[5D" = "backward-word";
125 "\\e[7~" = "beginning-of-line";
126 "\\e[8~" = "end-of-line";
127 "\\e[A" = "history-search-backward";
128 "\\e[B" = "history-search-forward";
129 "\\e[F" = "end-of-line";
130 "\\e[H" = "beginning-of-line";
131 "\\e\\e[C" = "forward-word";
132 "\\e\\e[D" = "backward-word";
133 };
134 variables = {
135 colored-completion-prefix = lib.mkDefault true;
136 colored-stats = lib.mkDefault true; # Note that this may cause completion text blink in some terminals (e.g. xterm).
137 echo-control-characters = lib.mkDefault true;
138 mark-symlinked-directories = lib.mkDefault true;
139 menu-complete-display-prefix = lib.mkDefault true;
140 show-all-if-ambiguous = lib.mkDefault true;
141 show-all-if-unmodified = lib.mkDefault true;
142 visible-stats = lib.mkDefault false; # Append char to indicate type
143 };
144 };
145 }