all repos — dotfiles @ 9f2aa547dae45c6183baab3dbe54bae3bed6050b

my *nix dotfiles

nix/programs/bash.nix (view raw)

  1{ config
  2, pkgs
  3, ...
  4}:
  5
  6{
  7  programs.bash = {
  8    enable = true;
  9    historyControl = [ "erasedups" ];
 10    historyFile = "\$HOME/.bash_history";
 11    historyFileSize = 40000;
 12    historyIgnore = [ "ls" "exit" "kill" ];
 13    historySize = 40000;
 14
 15    shellAliases = {
 16      o = "xdg-open";
 17      gc = "git commit -v -S";
 18      gst = "git status --short";
 19      ga = "git add";
 20      gd = "git diff --minimal";
 21      gl = "git log --oneline --decorate --graph";
 22      k = "kubectl";
 23      n = "z";
 24    };
 25
 26    shellOptions = [
 27      "histappend"
 28      "autocd"
 29      "globstar"
 30      "checkwinsize"
 31      "cdspell"
 32      "dirspell"
 33      "expand_aliases"
 34      "dotglob"
 35      "gnu_errfmt"
 36      "histreedit"
 37      "nocasematch"
 38    ];
 39
 40    sessionVariables = {
 41
 42      TERM = "xterm-256color-italic";
 43      EDITOR = "nvim";
 44      MANPAGER = "nvim +Man!";
 45      PATH = "/etc/profiles/per-user/icy/bin:$PATH:$HOME/go/bin:$HOME/bin";
 46      CLICOLOR = "1";
 47
 48    };
 49
 50    # TODO: nixify this
 51    bashrcExtra = ''
 52      refresh_tmux() {
 53        tmux refresh-client -S
 54      }
 55
 56      PROMPT_COMMAND=refresh_tmux
 57      PS1="\n\001\e[0;36m\002\001\e[0m\002 ";
 58      PS2="> "
 59
 60      ggp() {
 61          if [[ "$1" == "-f" ]]; then 
 62              git push "$(git remote show)" -f "$(git branch --show-current)"
 63          else
 64              git push "$(git remote show)" "$(git branch --show-current)"
 65          fi
 66      }
 67
 68      gpl() {
 69          if [[ "$1" != "" ]]; then
 70              branch="$1"
 71          else
 72              branch="$(git branch --show-current)"
 73          fi
 74          git pull -r "$(git remote show)" "$branch"
 75      }
 76
 77      gco() {
 78          [[ "$1" == "" ]] && return 1
 79
 80          git rev-parse --verify "$1" &> /dev/null
 81          if [ $? -eq 0 ]; then
 82              git checkout "$1"
 83          else
 84              git checkout -b "$1"
 85          fi
 86      }
 87
 88      gaf() {
 89          git status --short | grep "^ M\|^ D\|^\?\?" | fzy | awk '{ print $2 }' | xargs git add
 90      }
 91    '';
 92
 93    initExtra = ''
 94      # Ctrl+W kills word
 95      stty werase undef
 96
 97      # fzy reverse search
 98      __fzy_history() {
 99          ch="$(fc -rl 1 | awk -F'\t' '{print $2}' | sort -u | fzy)"
100          : "''${ch#"''${ch%%[![:space:]]*}"}"
101          printf "$_"
102      }
103
104      bind -x '"\C-r": READLINE_LINE=$(__fzy_history); READLINE_POINT="''${#READLINE_LINE}"'
105
106      complete -cf doas
107      complete -F __start_kubectl k
108    '';
109
110  };
111}