-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
154 lines (139 loc) · 3.91 KB
/
.bashrc
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
# If not running interactively, don't do anything.
[[ "$-" != *i* ]] && return
# Bash {{{
shopt -s no_empty_cmd_completion
# History Options {{{
export HISTCONTROL=erasedups
export HISTSIZE=5000
export HISTFILESIZE=5000
# History Sharing
shopt -u histappend
export PROMPT_COMMAND_SYNC_HISTORY='history -a; history -c; history -r'
#}}}
#}}}
# Homebrew {{{
if type brew &>/dev/null; then
# bash-completion {{{
# shellcheck source=/dev/null
test -f "$(brew --prefix)/etc/bash_completion" && . "$_"
#}}}
fi
#}}}
# Git {{{
show_current_git_branch='true'
if type git &>/dev/null; then
show_current_git_branch='__git_ps1'
if type __git_ps1 &>/dev/null; then
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREAM=auto
export GIT_PS1_DESCRIBE_STYLE=default
export GIT_PS1_SHOWCOLORHINTS=
else
function __git_ps1() {
local current_branch_name
current_branch_name=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [[ -z "$current_branch_name" ]]; then
echo ''
else
echo " ($current_branch_name)"
fi
}
fi
# Aliases {{{
alias g='git'
alias ga='g add'
alias gb='g branch --verbose'
alias gc='g commit --verbose'
alias gcm='gc -m'
alias gcma='gc --allow-empty -m'
alias gcd='cd "$(g rev-parse --show-toplevel)"'
alias gco='g checkout'
alias gcom='gco master'
alias gcob='gco -b'
alias gd='g diff --ignore-space-change'
alias gdw='gd --word-diff-regex="\w+"'
alias gf='g fetch'
alias gfp='gf --prune'
alias gl='g log --graph --decorate --oneline'
alias gm='g merge'
alias gmm='gm master'
alias gp='g push'
alias gpuo='gp -u origin'
alias gs='g status --short --branch'
alias grpo='g remote prune origin'
alias gwt='g worktree'
alias gwta='gwt add'
alias gwtp='gwt prune'
# Autocompletion with aliases
if type __git_complete &>/dev/null; then
type __git_main &>/dev/null && __git_complete g __git_main
type _git_add &>/dev/null && __git_complete ga _git_add
type _git_branch &>/dev/null && __git_complete gb _git_branch
type _git_commit &>/dev/null && __git_complete gc _git_commit
if type _git_checkout &>/dev/null; then
__git_complete gco _git_checkout
__git_complete gcom _git_checkout
__git_complete gcob _git_checkout
fi
if type _git_diff &>/dev/null; then
__git_complete gd _git_diff
__git_complete gdc _git_diff
__git_complete gdw _git_diff
__git_complete gdwc _git_diff
fi
if type _git_fetch &>/dev/null; then
__git_complete gf _git_fetch
__git_complete gfp _git_fetch
fi
type _git_log &>/dev/null && __git_complete gl _git_log
if type _git_merge &>/dev/null; then
__git_complete gm _git_merge
__git_complete gmm _git_merge
fi
if type _git_push &>/dev/null; then
__git_complete gp _git_push
__git_complete gpuo _git_push
fi
type _git_status &>/dev/null && __git_complete gs _git_status
if type _git_remote &>/dev/null; then
__git_complete grpo _git_remote
fi
if type _git_worktree &>/dev/null; then
__git_complete gwt _git_worktree
__git_complete gwta _git_worktree
__git_complete gwtp _git_worktree
fi
fi
#}}}
fi
#}}}
# direnv {{{
if type direnv &>/dev/null; then
eval "$(direnv hook bash)"
fi
#}}}
# Prompt {{{
# $PS1 {{{
# Example
#
# [1970-01-01T00:00:00] ~ (master)
# $ _
export PS1='\[\e[0;36m\][\D{%FT%T}] \[\e[0;32m\]\W\[\e[0;33m\]$($show_current_git_branch)\n\[\e[0;32m\]\$ \[\e[0m\]'
#}}}
# $PROMPT_COMMAND {{{
function __eval_prompt_commands {
export EXIT_STATUS="$?"
local prompt_command
for prompt_command in ${!PROMPT_COMMAND_*}; do
eval "${!prompt_command}"
done
}
if ! [[ $PROMPT_COMMAND =~ __eval_prompt_commands ]]; then
PROMPT_COMMAND="__eval_prompt_commands;$PROMPT_COMMAND"
fi
#}}}
#}}}
# shellcheck source=/dev/null
test -f "$HOME/.bashrc.local" && . "$_"