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