all repos — dotfiles @ df4f1038a6a0e9e406776296665d816e8285acac

my *nix dotfiles

programs/bash.nix (view raw)

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