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 |
{ config
, pkgs
, ...
}:
let
awk = "${pkgs.gawk}/bin/awk";
fzy = "${pkgs.fzy}/bin/fzy";
in
{
programs.bash = {
enable = true;
historyControl = [ "erasedups" "ignoredups" "ignorespace" ];
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 = {
EDITOR = "nvim";
MANPAGER = "nvim +Man!";
PATH = "/etc/profiles/per-user/icy/bin:$PATH:$HOME/go/bin:$HOME/bin";
CLICOLOR = "1";
LANG = "en_US.UTF-8";
};
# 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 = ''
[[ $(HISTTIMEFORMAT="" builtin history 1) =~ [[:digit:]]+ ]]
__fzy_history__() {
ch="$(fc -rl 1 | ${awk} -F'\t' '{print $2}' | ${awk} '{!seen[$0]++};END{for(i in seen) if(seen[i]==1)print i}' | ${fzy})"
ch="$(echo "$ch" | ${awk} '{$1=$1;print}')"
READLINE_LINE=''${ch#*$'\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
if command -v kubectl &> /dev/null; then
source <(kubectl completion bash)
complete -F __start_kubectl k
fi
'';
};
}
|