all repos — dotfiles @ b2f871cb67114092cf8a3c4cfd404ab25ad56765

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 = "$PATH:$HOME/go/bin:$HOME/bin";
 46
 47    };
 48
 49    # TODO: nixify this
 50    bashrcExtra = ''
 51      refresh_tmux() {
 52        tmux refresh-client -S
 53      }
 54
 55      PROMPT_COMMAND=refresh_tmux
 56      PS1="\n\001\e[0;36m\002\001\e[0m\002 ";
 57      PS2="> "
 58
 59      ggp() {
 60          if [[ "$1" == "-f" ]]; then 
 61              git push "$(git remote show)" -f "$(git branch --show-current)"
 62          else
 63              git push "$(git remote show)" "$(git branch --show-current)"
 64          fi
 65      }
 66
 67      gpl() {
 68          if [[ "$1" != "" ]]; then
 69              branch="$1"
 70          else
 71              branch="$(git branch --show-current)"
 72          fi
 73          git pull -r "$(git remote show)" "$branch"
 74      }
 75
 76      gco() {
 77          [[ "$1" == "" ]] && return 1
 78
 79          git rev-parse --verify "$1" &> /dev/null
 80          if [ $? -eq 0 ]; then
 81              git checkout "$1"
 82          else
 83              git checkout -b "$1"
 84          fi
 85      }
 86
 87      gaf() {
 88          git status --short | grep "^ M\|^ D\|^\?\?" | fzy | awk '{ print $2 }' | xargs git add
 89      }
 90    '';
 91
 92    initExtra = ''
 93      # Ctrl+W kills word
 94      stty werase undef
 95
 96      # fzy reverse search
 97      __fzy_history() {
 98          ch="$(fc -rl 1 | awk -F'\t' '{print $2}' | sort -u | fzy)"
 99          : "''${ch#"''${ch%%[![:space:]]*}"}"
100          printf "$_"
101      }
102
103      bind -x '"\C-r": READLINE_LINE=$(__fzy_history); READLINE_POINT="''${#READLINE_LINE}"'
104
105      complete -cf doas
106      complete -F __start_kubectl k
107    '';
108
109  };
110}