Repository navigation
Expand file tree
/
Copy path.bashrc
More file actions
108 lines (89 loc) · 2.61 KB
/
Copy path.bashrc
File metadata and controls
108 lines (89 loc) · 2.61 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
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
HISTSIZE=100000
HISTFILESIZE=200000
# check the window size after each command
shopt -s checkwinsize
# make less more friendly for non-text input files
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# Shared portable config (aliases, env, functions) lives in ~/.shellrc
[ -f ~/.shellrc ] && source ~/.shellrc
# Alias definitions.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# Fzf shortcuts.
if [ -f ~/.bashrc_fzf ]; then
source ~/.bashrc_fzf
fi
# Fzf install
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# enable programmable completion features
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
_git_alias() {
_alias=$1
_operation=$2
alias $_alias="git $_operation"
__git_complete $_alias _git_$_operation
}
if [ -f "/usr/share/bash-completion/completions/git" ]; then
source /usr/share/bash-completion/completions/git
_git_alias "ga" "add"
_git_alias "gb" "branch"
_git_alias "gco" "checkout"
_git_alias "gcm" "commit"
_git_alias "gl" "log"
_git_alias "gr" "rebase"
_git_alias "gs" "status"
fi
PROMPT_DIRTRIM=3
[ -f /.dockerenv ] && _IN_DOCKER=1
parse_git_branch() {
local branch
branch=$(git --no-optional-locks symbolic-ref --short HEAD 2>/dev/null) \
|| branch=$(git --no-optional-locks rev-parse --short HEAD 2>/dev/null) \
|| return
if git --no-optional-locks diff-index --cached --quiet HEAD -- 2>/dev/null; then
echo '\[\e[0;32m\]'"($branch)"
else
echo '\[\e[0;33m\]'"($branch)"
fi
}
__set_prompt() {
local EXIT="$?" # This needs to be first
PS1=""
local Red='\[\e[0;31m\]'
local Yel='\[\e[1;33m\]'
local Blu='\[\e[1;34m\]'
local BluBG='\[\e[48;5;27m\e[38;5;231m\]'
local Clear='\[\e[0m\]'
if [ "$EXIT" != 0 ]; then
PS1+="[${Red}${EXIT}${Clear}]" # Add red if exit code non 0
fi
local _kube_ctx
_kube_ctx=$(kubectl config current-context 2>/dev/null)
if [[ -n "$_kube_ctx" && ! "$_kube_ctx" =~ "dev" ]]; then
PS1+="${Yel}[CAUTION: K8S PROD CONTEXT]${Clear} "
fi
[ -n "$VIRTUAL_ENV" ] && PS1+="(${VIRTUAL_ENV##*/}) "
if [ -n "$_IN_DOCKER" ]; then
PS1+="${BluBG}\u@\h${Clear}"
else
PS1+="\u@\h"
fi
PS1+="${Blu}\w ${Clear}$(parse_git_branch)${Clear}$ "
}
PROMPT_COMMAND=__set_prompt