nix: improve desktop responsiveness when updating the system
[julm/julm-nix.git] / home-manager / profiles / bash.nix
index 8eaad68d26eaaf610e5c526a77e99fa8762642a3..191b6613da4ebfada87e551e93ce67a1945331d6 100644 (file)
@@ -4,6 +4,7 @@ with lib;
   programs.bash = {
     enable = mkDefault true;
     shellAliases = {
+      afk = "xset s activate dpms force off";
       black-on-white = "echo -e '\\033]11;black\\007\\033]10;white\\007'";
       c = "bat";
       cl = "clear";
@@ -24,6 +25,7 @@ with lib;
       mem-top = "smem --sort rss --autosize";
       mpl = "mplayer";
       nf = "sudo nft list ruleset | less";
+      nix-du-svg = "nix-du | dot -Tsvg >nix-du.svg";
       nixos-clean = "sudo nix-collect-garbage -d";
       nixos-history = "sudo nix-env --list-generations --profile /nix/var/nix/profiles/system";
       nixos-rollback = "sudo nixos-rebuild switch --rollback";
@@ -35,6 +37,9 @@ with lib;
       s = "sudo systemctl";
       st = "sudo systemctl status";
       t = "tmux";
+      t0 = "tmux new -t 0";
+      t1 = "tmux new -t 1";
+      t2 = "tmux new -t 2";
       theme-black-on-white = "echo -e '\\033]10;black\\007\\033]11;white\\007'";
       theme-white-on-black = "echo -e '\\033]10;white\\007\\033]11;black\\007'";
       u = "systemctl --user";
@@ -44,7 +49,14 @@ with lib;
       w10 = "watch --color --differences --interval 10";
       w = "watch --color --differences";
       watch = "watch --color --differences";
+      ze = "sudo zpool export";
       zfs-umount = "zfs-unmount";
+      zi = "sudo zpool import";
+      zl = "zfs list";
+      zlb = "zfs list -t bookmarks";
+      zls = "zfs list -t snap";
+      zm = "zfs-mount";
+      zu = "zfs-unmount";
     };
     sessionVariables = {
       HISTCONTROL = "erasedups:ignorespace";
@@ -63,6 +75,16 @@ with lib;
       # Disable ctrl-s/ctrl-q flow control
       stty -ixon
 
+      ffmpeg-audio () {
+        for i in "$@"; do
+          ffmpeg -i "$i" -vn -map 0:a -acodec copy "''${i%.*}".audio
+        done
+      }
+      ffmpeg-opus () {
+        for i in "$@"; do
+          ffmpeg -i "$i" -vn -map 0:a -c:a libopus -b:a 64k -application voip "''${i%.*}".opus
+        done
+      }
       ibm-fan () {
         if [ $# -gt 0 ]
         then sudo tee /proc/acpi/ibm/fan <<<"level $1"
@@ -88,18 +110,22 @@ with lib;
         device=''${1:-/dev/sda}
         sudo smartctl -A $device |
         { awk '
-          $0 ~ /Power_On_Hours/ { poh=$10; printf "%s / %d hours / %d days / %.2f years\n",  $2, $10, $10 / 24, $10 / 24 / 365.25 }
+          $0 ~ /Power_On_Hours/ {
+            poh=$10;
+            printf "%s / %d hours / %d days / %.2f years\n",  $2, $10, $10 / 24, $10 / 24 / 365.25
+          }
           $0 ~ /Total_LBAs_Written/ {
-              lbas = $10;
-              bytes = $10 * 512;
-              mb = bytes / 1024^2;
-              gb = bytes / 1024^3;
-              tb = bytes / 1024^4;
-              printf "%s / %s  / %d mb / %.1f gb / %.3f tb\n", $2, $10, mb, gb, tb
-              printf "mean writes per hour:  / %.2f",  mb/poh
+            lbas = $10;
+            bytes = $10 * 512;
+            mb = bytes / 1024^2;
+            gb = bytes / 1024^3;
+            tb = bytes / 1024^4;
+            printf "%s / %s  / %d mb / %.1f gb / %.3f tb\n", $2, $10, mb, gb, tb
+            printf "mean writes per hour / %.2f",  mb/poh
           }
           $0 ~ /Airflow_Temperature_Cel/ { print $2 " / " $10}
           $0 ~ /Wear_Leveling_Count/ { printf "%s / %d (%% health)\n", $2, int($4) }
+          $0 ~ /Percentage Used:/ { printf "Percentage_Used / %d\n", int($3) }
         '; echo; } |
         sed -e 's:/:@:' |
         sed -e "s\$^\$$device @ \$" |
@@ -141,6 +167,8 @@ with lib;
       # loading their keys if needed.
       zfs-mount () {
         local d
+        local -
+        set -e
         for d in $(zfs list -rH -o name "$@"); do
           mountpoint /mnt/"$d" 2>/dev/null ||
           sudo zfs mount -l "$d"
@@ -150,6 +178,22 @@ with lib;
       # unloading their keys.
       zfs-unmount () { sudo zfs unmount -u "$@"; }
 
+      # Create bookmarks for all the snapshots of the given datasets.
+      # Bookmarks are only useful on source datasets
+      # But syncoid --create-bookmark only creates
+      # a bookmark for the latest snapshot,
+      # possibly leaving the *_daily or *_monthly snapshots without a bookmark.
+      zfs-fix-bookmarks () {
+        local d
+        local -
+        set -x
+        for d in "$@"; do
+          for s in $(zfs list -Hrpt snapshot -o name "$d"); do
+            zfs bookmark "$s" "''${s//@/#}"
+          done
+        done
+      }
+
       # Restore the inheritance of encryptionroot,
       # usually broken by zfs send --raw.
       # Note that it needs to decrypt the datasets.
@@ -184,6 +228,8 @@ with lib;
       # Up/Down
       "\\e[A" = "history-search-backward";
       "\\e[B" = "history-search-forward";
+      "\\eOA" = "history-search-backward";
+      "\\eOB" = "history-search-forward";
 
       # Ctrl-Left/Ctrl-Right
       "\\e[1;5C" = "forward-word";