audio: move from pulseaudio to pipewire
[julm/julm-nix.git] / home-manager / profiles / bash.nix
index 29635ed1a483f13ca490f0349d5f74a492be9618..85cb858f040e9e2aeabc82a4c129a80f26b1df6f 100644 (file)
-{ pkgs, lib, config, ... }:
+{ pkgs, lib, ... }:
+with lib;
 {
-programs.bash = {
-  enable = lib.mkDefault true;
-  shellAliases = {
-    black-on-white = "echo -e '\\033]11;black\\007\\033]10;white\\007'";
-    c = "bat";
-    cl = "clear";
-    eic = "edit-in-commit";
-    eigg = "edit-in-git-grep";
-    emacs = "emacsclient --create-frame";
-    g = "git";
-    gg = "git grep";
-    grep = "grep --color";
-    j="sudo journalctl -u";
-    jb="sudo journalctl -b";
-    l = "ls -alh";
-    ll = "ls -al";
-    ls = "ls --color=tty";
-    md-toc = "grep '^#\\+' --color";
-    mem = "ps -e -orss=,user=,args= | sort -b -k1,1n";
-    mem-top = "smem --sort rss --autosize";
-    mpl = "mplayer";
-    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";
-    pass-gen = "tr -d -C A-Za-z0-9_- </dev/urandom | head -c";
-    rsync = "rsync --no-inc-recursive --info=progress2 --inplace --partial";
-    s="sudo systemctl";
-    st="sudo systemctl status";
-    u="systemctl --user";
-    ut="systemctl --user status";
-    watch = "watch --color --differences";
-    white-on-black = "echo -e '\\033]11;white\\007\\033]10;black\\007'";
-    yt = "yt-dlp";
-    zfs-umount = "zfs-unmount";
-  };
-  initExtra = ''
-    shopt -s globstar
-    shopt -s histreedit
-    shopt -s histverify
-    # Disable ctrl-s/ctrl-q flow control
-    stty -ixon
+  programs.bash = {
+    enable = mkDefault true;
+    shellAliases = {
+      black-on-white = "echo -e '\\033]11;black\\007\\033]10;white\\007'";
+      c = "bat";
+      cl = "clear";
+      eic = "edit-in-commit";
+      eigg = "edit-in-git-grep";
+      emacs = "emacsclient --create-frame";
+      g = "git";
+      gg = "git grep";
+      grep = "grep --color";
+      j = "sudo journalctl -u";
+      jb = "sudo journalctl -b";
+      l = "ls -alh";
+      ll = "ls -al";
+      ls = "ls --color=tty";
+      md-toc = "grep '^#\\+' --color";
+      mem = "ps -e -orss=,user=,args= | sort -b -k1,1n";
+      mem-top = "smem --sort rss --autosize";
+      mpl = "mplayer";
+      nf = "sudo nft list ruleset | less";
+      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";
+      pass-gen = "tr -d -C A-Za-z0-9_- </dev/urandom | head -c";
+      r = "reset";
+      rsync = "rsync --no-inc-recursive --info=progress2 --inplace --partial";
+      s = "sudo systemctl";
+      st = "sudo systemctl status";
+      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";
+      ut = "systemctl --user status";
+      w1 = "watch --color --differences --interval 1";
+      w5 = "watch --color --differences --interval 5";
+      w10 = "watch --color --differences --interval 10";
+      w = "watch --color --differences";
+      watch = "watch --color --differences";
+      yt = "yt-dlp";
+      zfs-umount = "zfs-unmount";
+    };
+    sessionVariables = {
+      HISTCONTROL = "erasedups:ignorespace";
+      HISTSIZE = "42000";
+      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)\$ '';
+    };
+    initExtra = ''
+      # Alias completion
+      . ${pkgs.complete-alias}/bin/complete_alias
+      complete -F _complete_alias "''${!BASH_ALIASES[@]}"
 
-    ibm-fan () {
-      if [ $# -gt 0 ]
-      then sudo tee /proc/acpi/ibm/fan <<<"level $1"
-      else grep '^\(level\|speed\):' /proc/acpi/ibm/fan
-      fi
-      acpi -t
-    }
-    mkcd () {
-      mkdir -p "$1" &&
-      cd "$1"
-    }
-    smartctl-tbw () {
-      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 ~ /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
-        }
-        $0 ~ /Airflow_Temperature_Cel/ { print $2 " / " $10}
-        $0 ~ /Wear_Leveling_Count/ { printf "%s / %d (%% health)\n", $2, int($4) }
-      '; echo; } |
-      sed -e 's:/:@:' |
-      sed -e "s\$^\$$device @ \$" |
-      column -ts@
-    }
-    swaplist () {
-      lastpid=
-      swap=0
-      sudo grep -H '^Swap:' /proc/*/smaps 2>/dev/null |
-      while IFS=: read -r file x size x
-      do
-        pid=''${file#/proc/}
-        pid=''${pid%/smaps}
-        size=''${size% kB}
-        size=''${size##* }
-        if test "$pid" = "$lastpid"
-        then swap=$(( swap + size ))
-        else
-          if test "$swap" -gt 0
-          then printf "%u pid=%u cmd=%s\n" "$swap" "$lastpid" "$(tr '\000' ' ' </proc/"$lastpid"/cmdline)"
-          fi
-          if test "$pid" = self
-          then break
+      shopt -s globstar
+      shopt -s histappend
+      shopt -s histreedit
+      shopt -s histverify
+      # Disable ctrl-s/ctrl-q flow control
+      stty -ixon
+
+      ibm-fan () {
+        if [ $# -gt 0 ]
+        then sudo tee /proc/acpi/ibm/fan <<<"level $1"
+        else grep '^\(level\|speed\):' /proc/acpi/ibm/fan
+        fi
+        acpi -t
+      }
+      mkcd () {
+        mkdir -p "$1" &&
+        cd "$1"
+      }
+      smartctl-tbw () {
+        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 ~ /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
+          }
+          $0 ~ /Airflow_Temperature_Cel/ { print $2 " / " $10}
+          $0 ~ /Wear_Leveling_Count/ { printf "%s / %d (%% health)\n", $2, int($4) }
+        '; echo; } |
+        sed -e 's:/:@:' |
+        sed -e "s\$^\$$device @ \$" |
+        column -ts@
+      }
+      stress-mem() { fac="$1"; stress-ng --vm 1 --vm-keep --vm-bytes $(awk "/MemAvailable/{ printf \"%d\n\", \$2 * $fac; }" </proc/meminfo)k; }
+      sysenter() { srv="$1"; shift; nsenter -a -t "$(systemctl show --property MainPID --value "$srv")" "$@"; }
+      systrace() { srv="$1"; shift; strace -f -p "$(systemctl show --property MainPID --value "$srv")" "$@"; }
+      swaplist () {
+        lastpid=
+        swap=0
+        sudo grep -H '^Swap:' /proc/*/smaps 2>/dev/null |
+        while IFS=: read -r file x size x
+        do
+          pid=''${file#/proc/}
+          pid=''${pid%/smaps}
+          size=''${size% kB}
+          size=''${size##* }
+          if test "$pid" = "$lastpid"
+          then swap=$(( swap + size ))
           else
-            lastpid=$pid
-            swap=$size
+            if test "$swap" -gt 0
+            then printf "%u pid=%u cmd=%s\n" "$swap" "$lastpid" "$(tr '\000' ' ' </proc/"$lastpid"/cmdline)"
+            fi
+            if test "$pid" = self
+            then break
+            else
+              lastpid=$pid
+              swap=$size
+            fi
           fi
-        fi
-      done |
-      sort -nk1,1
-    }
-    edit-in-commit () { $EDITOR $(git diff-tree --no-commit-id --name-only -r "$@"); }
-    edit-in-git-grep () { $EDITOR $(git grep --name-only --recursive "$@"); }
-    zfs-mount () { for d in $(zfs list -rH -o name "$@"); do sudo zfs mount -l "$d"; done; }
-    zfs-unmount () { sudo zfs unmount -u "$@"; }
-  '';
-  profileExtra = ''
-  '';
-};
-programs.direnv.enableBashIntegration = true;
-#programs.broot.enableBashIntegration = true;
-home.sessionVariables = {
-  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)\$ '';
-};
-programs.readline = {
-  enable = lib.mkDefault true;
-  includeSystemConfig = true;
-  bindings = {
-    "\\eOF"    = "end-of-line";
-    "\\eOH"    = "beginning-of-line";
-    "\\e[1;5C" = "forward-word";
-    "\\e[1;5D" = "backward-word";
-    "\\e[1~"   = "beginning-of-line";
-    "\\e[4~"   = "end-of-line";
-    "\\e[5C"   = "forward-word";
-    "\\e[5D"   = "backward-word";
-    "\\e[7~"   = "beginning-of-line";
-    "\\e[8~"   = "end-of-line";
-    "\\e[A"    = "history-search-backward";
-    "\\e[B"    = "history-search-forward";
-    "\\e[F"    = "end-of-line";
-    "\\e[H"    = "beginning-of-line";
-    "\\e\\e[C" = "forward-word";
-    "\\e\\e[D" = "backward-word";
+        done |
+        sort -nk1,1
+      }
+      edit-in-commit () { $EDITOR $(git diff-tree --no-commit-id --name-only -r "$@"); }
+      edit-in-git-grep () { $EDITOR $(git grep --name-only --recursive "$@"); }
+      zfs-mount () { for d in $(zfs list -rH -o name "$@"); do sudo zfs mount -l "$d"; done; }
+      zfs-unmount () { sudo zfs unmount -u "$@"; }
+    '';
+    profileExtra = ''
+    '';
   };
-  variables = {
-    colored-completion-prefix = lib.mkDefault true;
-    colored-stats = lib.mkDefault true; # Note that this may cause completion text blink in some terminals (e.g. xterm).
-    echo-control-characters = lib.mkDefault true;
-    mark-symlinked-directories = lib.mkDefault true;
-    menu-complete-display-prefix = lib.mkDefault true;
-    show-all-if-ambiguous = lib.mkDefault true;
-    show-all-if-unmodified = lib.mkDefault true;
-    visible-stats = lib.mkDefault false; # Append char to indicate type
+  programs.direnv.enableBashIntegration = true;
+  #programs.broot.enableBashIntegration = true;
+  programs.readline = {
+    enable = mkDefault true;
+    includeSystemConfig = true;
+    bindings = {
+      # Up/Down
+      "\\e[A" = "history-search-backward";
+      "\\e[B" = "history-search-forward";
+
+      # Ctrl-Left/Ctrl-Right
+      "\\e[1;5C" = "forward-word";
+      "\\e[1;5D" = "backward-word";
+      "\\e[5C" = "forward-word";
+      "\\e[5D" = "backward-word";
+      "\\e\\e[C" = "forward-word";
+      "\\e\\e[D" = "backward-word";
+
+      # Home/End
+      "\\e[1~" = "beginning-of-line";
+      "\\e[4~" = "end-of-line";
+
+      # Delete/Insert
+      "\\e[3~" = "delete-char";
+      "\\e[2~" = "quoted-insert";
+
+      # For non RH/Debian xterm, can't hurt for RH/Debian xterm
+      "\\eOF" = "end-of-line";
+      "\\eOH" = "beginning-of-line";
+
+      # For freebsd console
+      "\\e[F" = "end-of-line";
+      "\\e[H" = "beginning-of-line";
+
+      # $if term=rxvt
+      "\\e[7~" = "beginning-of-line";
+      "\\e[8~" = "end-of-line";
+      "\\eOc" = "forward-word";
+      "\\eOd" = "backward-word";
+      # $endif
+    };
+    variables = {
+      # Be 8 bit clean.
+      input-meta = mkDefault true;
+      output-meta = mkDefault true;
+      colored-completion-prefix = mkDefault true;
+      colored-stats = mkDefault true; # Note that this may cause completion text blink in some terminals (e.g. xterm).
+      echo-control-characters = mkDefault true;
+      mark-symlinked-directories = mkDefault true;
+      menu-complete-display-prefix = mkDefault true;
+      show-all-if-ambiguous = mkDefault true;
+      show-all-if-unmodified = mkDefault true;
+      visible-stats = mkDefault false; # Append char to indicate type
+    };
   };
-};
 }