-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_bashrc
More file actions
163 lines (131 loc) · 4.87 KB
/
_bashrc
File metadata and controls
163 lines (131 loc) · 4.87 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
export HISTFILESIZE=
export HISTSIZE=1000000000
export HISTTIMEFORMAT="[%F %T] "
# Protect history against truncation.
# https://stackoverflow.com/a/19533853
# https://superuser.com/q/575479
export HISTFILE=~/.bash_eternal_history
export PATH=$HOME/.bin:$HOME/.cabal/bin:$PATH
export PYTHONPATH=$HOME/.bin
export TEXMFHOME=$HOME/.texmf
# Somehow this defaults to ~/.pythonrc on some systems.
unset PYTHONSTARTUP
export GPG_TTY=$(tty)
# Silence annoying warnings from grep.
unset GREP_OPTIONS
# Check for an interactive session
[ -z "$PS1" ] && return
# enable tab completion for tar on all types of files
complete tar && compopt -o default tar
# Enable tab completion for make targets.
complete -W "`make -qp 2>/dev/null | sed -n -E 's/^([^.#\s][^:=]*)(:$|:\s+.*$)/\1/p' | sort -u`" make
# git
__git_ps1 () { :; }
[ -e $HOME/.git-prompt.sh ] && source $HOME/.git-prompt.sh
[ -e $HOME/.bash-completion-git ] && source $HOME/.bash-completion-git
alias ls="ls --color=auto"
alias gdb="gdb -q"
alias cgdb="cgdb -q"
alias gl="git log --pretty=format:'%C(yellow)%h %Cred%ad %Cgreen%<(10,trunc)%ae %Creset%s' --date=format:'%Y/%m/%d %H:%M'"
alias gsl="git stash list --pretty=format:'%C(yellow)%h %Cred%ad %Cgreen%<(10,trunc)%ae %Creset%s' --date=format:'%Y/%m/%d %H:%M'"
alias gacp="git add --all && git commit -a -m More && git push"
gf () {
git rev-parse --is-inside-work-tree &>/dev/null || return 1
gl --color=always "$@" | \
fzf --reverse --multi --ansi --no-info --tiebreak index \
--preview 'git show --color=always {+1}' \
--preview-window down,75%,border-none
}
# https://stackoverflow.com/a/15009611
__git_complete gl _git_log
__git_complete gf _git_log
# ssh and cd to `pwd`.
sshh() { ssh -X -t "$@" "cd '$(pwd)' 2>/dev/null; bash -l"; }
sshc() { ssh -X "$1" "cd '$(pwd)' 2>/dev/null; ${@:2}"; }
# python virtualenv
export VIRTUAL_ENV_DISABLE_PROMPT=1
venv-activate() {
# alias doesn't work: http://stackoverflow.com/a/13261212
. $(find-venv .)
INVENV=$(python <<'EOF'
import sys
bp = getattr(sys, "base_prefix", sys.prefix) != sys.prefix
rp = hasattr(sys, "real_prefix")
print(1 if bp or rp else 0)
EOF
)
if [ "$INVENV" = "1" ] ; then
export _OLD_VIRTUAL_PS1="$PS1" # for deactivate()
PS1="\[\e[1;92m\][v] $PS1"
fi
}
p() {
if [ -x "$(command -v ptipython)" ]; then
ptipython "$@"
else
ptipython2 "$@"
fi
}
alias nx="(cd ~/sandbox/scratch/nx && venv-activate && ./check)"
# default editor
export VISUAL=vim
export EDITOR="$VISUAL"
# pretty print tsv
alias catt="column -s $'\t' -t"
# disable XON/XOFF, to use CTRL-S/Q
stty -ixon
# automatically fit to window size
shopt -s checkwinsize
# color grep
if echo hello|grep --color=auto l >/dev/null 2>&1; then
alias grep='grep --color=auto'
export GREP_COLORS="ms=01;37;41:mc=01;31:sl=:cx=:fn=4;34:ln=32:bn=32:se=1;31"
fi
# ripgrep
export RIPGREP_CONFIG_PATH="$HOME/.ripgreprc"
alias rgs="rg --sort-files"
# fd
alias fd="fd --color=never"
# fzf
[ -e $HOME/.fzf-key-bindings.bash ] && source $HOME/.fzf-key-bindings.bash
[ -e $HOME/.fzf-completion.bash ] && source $HOME/.fzf-completion.bash
export FZF_CTRL_T_COMMAND='rg --files --follow 2>/dev/null'
# PS1
PS1_NAME="home"
[ -e $HOME/.ps1-name ] && source $HOME/.ps1-name
case "$PS1_NAME" in
"home")
PS1='\[\e[0;33m\]\h \[\e[0;34m\]\w\[\e[1;36m\]$(__git_ps1 " [%s]") \[\e[0;33m\]\$ \[\e[0m\]';;
"home-git")
PS1='\[\e[1;30m\]\u\[\e[m\] \[\e[0;34m\]\w\[\e[m\]$(__git_ps1 " [%s]") \[\e[1;30m\]\$\[\e[m\] \[\e[0m\]';;
"home-root")
PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[0;34m\]\w\[\e[m\]$(__git_ps1 " [%s]") \[\e[0;32m\]\$\[\e[m\] \[\e[0m\]';;
"thinkpad")
PS1='\[\e[1;35m\]\h \[\e[0;34m\]\w\[\e[1;36m\]$(__git_ps1 " [%s]") \[\e[1;35m\]\$ \[\e[0m\]';;
"xps")
PS1='\[\e[1;35m\]\h \[\e[0;34m\]\w\[\e[1;36m\]$(__git_ps1 " [%s]") \[\e[1;35m\]\$ \[\e[0m\]';;
"office")
PS1='\[\e[0;36m\]\h \[\e[1;35m\]\w\[\e[1;36m\]$(__git_ps1 " [%s]") \[\e[0;33m\]\$ \[\e[0m\]';;
"office-root")
PS1='\[\e[1;35m\]\u \[\e[0;36m\]\w\[\e[1;36m\]$(__git_ps1 " [%s]") \[\e[0;33m\]\$ \[\e[0m\]';;
"conformal")
PS1='\[\e[1;31m\]\h \[\e[1;35m\]\w\[\e[1;36m\]$(__git_ps1 " [%s]") \[\e[0;33m\]\$ \[\e[0m\]';;
esac
# Adapted from /etc/profile.d/vte.sh,
# but without the "777;notify;Command completed;" nonsense.
__vte_prompt_command() {
local pwd='~'
[ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/}
printf "\033]0;%s:%s\007%s" "${HOSTNAME%%.*}" "${pwd}"
}
if test "$TERM" = "xterm" -o \
"$TERM" = "xterm-color" -o \
"$TERM" = "xterm-256color" -o \
"$TERM" = "xterm-termite" -o \
"$TERM" = "rxvt" -o \
"$TERM" = "rxvt-unicode" -o \
"$TERM" = "xterm-xfree86"; then
PROMPT_COMMAND="__vte_prompt_command"
export PROMPT_COMMAND
fi
[ -e /usr/share/bash-completion/completions/pass ] && source /usr/share/bash-completion/completions/pass