all repos — dotfiles @ fbd4a0d2799ca35ab51aed3f1c6038c394fe3991

my *nix dotfiles

nix/programs/bash.nix (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
{ config
, pkgs
, ...
}:

{
  programs.bash = {
    enable = true;
    historyControl = [ "erasedups" ];
    historyFile = "\$HOME/.bash_history";
    historyFileSize = 40000;
    historyIgnore = [ "ls" "exit" "kill" ];
    historySize = 40000;

    shellAliases = {
      o = "xdg-open";
      gc = "git commit -v -S";
      gst = "git status --short";
      ga = "git add";
      gd = "git diff --minimal";
      gl = "git log --oneline --decorate --graph";
      k = "kubectl";
      n = "z";
    };

    shellOptions = [
      "histappend"
      "autocd"
      "globstar"
      "checkwinsize"
      "cdspell"
      "dirspell"
      "expand_aliases"
      "dotglob"
      "gnu_errfmt"
      "histreedit"
      "nocasematch"
    ];

    sessionVariables = {

      TERM = "xterm-256color-italic";
      EDITOR = "nvim";
      MANPAGER = "nvim +Man!";
      PATH = "/etc/profiles/per-user/icy/bin:$PATH:$HOME/go/bin:$HOME/bin";
      CLICOLOR = "1";

    };

    # TODO: nixify this
    bashrcExtra = ''
      refresh_tmux() {
        tmux refresh-client -S
      }

      PROMPT_COMMAND=refresh_tmux
      PS1="\n\001\002▲\001\002 ";
      PS2="> "

      ggp() {
          if [[ "$1" == "-f" ]]; then 
              git push "$(git remote show)" -f "$(git branch --show-current)"
          else
              git push "$(git remote show)" "$(git branch --show-current)"
          fi
      }

      gpl() {
          if [[ "$1" != "" ]]; then
              branch="$1"
          else
              branch="$(git branch --show-current)"
          fi
          git pull -r "$(git remote show)" "$branch"
      }

      gco() {
          [[ "$1" == "" ]] && return 1

          git rev-parse --verify "$1" &> /dev/null
          if [ $? -eq 0 ]; then
              git checkout "$1"
          else
              git checkout -b "$1"
          fi
      }

      gaf() {
          git status --short | grep "^ M\|^ D\|^\?\?" | fzy | awk '{ print $2 }' | xargs git add
      }
    '';

    initExtra = ''
      __fzy_history__() {
          script='function P(b) { ++n; sub(/^[ *]/, "", b); if (!seen[b]++) { printf "%d\t%s%c", '$((BASH_REMATCH + 1))' - n, b, 0 } }
              NR==1 { b = substr($0, 2); next }
              /^\t/ { P(b); b = substr($0, 2); next }
              { b = b RS $0 }
              END { if (NR) P(b) }'


          output=$(
            set +o pipefail
            builtin fc -lnr -2147483648 2> /dev/null |   # ( $'\t '<lines>$'\n' )* ; <lines> ::= [^\n]* ( $'\n'<lines> )*
              command awk "$script"           |   # ( <counter>$'\t'<lines>$'\000' )*
              fzy --query "$READLINE_LINE"
          ) || return
          READLINE_LINE=''${output#*$'\t'}
          if [[ -z "$READLINE_POINT" ]]; then
            echo "$READLINE_LINE"
          else
            READLINE_POINT=0x7fffffff
          fi
      }

      bind -m emacs-standard -x '"\C-r": __fzy_history__'

      complete -cf doas
    '';

  };
}