-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
executable file
·158 lines (123 loc) · 4.02 KB
/
Copy pathbashrc
File metadata and controls
executable file
·158 lines (123 loc) · 4.02 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
# shellcheck shell=bash
# If not running interactively, don't do anything
[[ "$-" != *i* ]] && return
################################################################################
# History
################################################################################
# Make bash append rather than overwrite the history on disk.
shopt -s histappend
# When changing directory small typos can be ignored by bash
# for example, cd /vr/lgo/apaache would find /var/log/apache
shopt -s cdspell
# Keep LINES and COLUMNS updated after terminal resizes.
shopt -s checkwinsize
# History options
export HISTFILESIZE=20000
export HISTSIZE=20000
export HISTCONTROL=ignoredups:erasedups
################################################################################
# Aliases
################################################################################
if type -a vim > /dev/null 2>&1; then
alias vi=vim
alias view='vim -R'
fi
case "$(uname -s)" in
Darwin)
alias ls='ls -G'
alias ll='ls -lG'
alias la='ls -laG'
;;
*)
alias ls='ls --color=auto'
alias ll='ls -lh --color=auto'
alias la='ls -lah --color=auto'
alias grep='grep --color=auto'
;;
esac
alias ..='cd ..'
alias ...='cd ../..'
################################################################################
# Completion
################################################################################
if [[ -r /usr/share/bash-completion/bash_completion ]]; then
# shellcheck disable=SC1091
source /usr/share/bash-completion/bash_completion
elif [[ -r /etc/bash_completion ]]; then
# shellcheck disable=SC1091
source /etc/bash_completion
fi
################################################################################
# Readline
################################################################################
set -o vi
if bind -V >/dev/null 2>&1; then
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
fi
################################################################################
# Prompt
################################################################################
PROMPT_DIRTRIM=3
Color_Off=
Red=
Green=
Yellow=
Cyan=
Bold=
if [[ -t 1 ]] && command -v tput >/dev/null 2>&1; then
if [[ $(tput colors 2>/dev/null || printf 0) -ge 8 ]]; then
Color_Off="\[$(tput sgr0)\]"
Red="\[$(tput setaf 1)\]"
Green="\[$(tput setaf 2)\]"
Yellow="\[$(tput setaf 3)\]"
Cyan="\[$(tput setaf 6)\]"
Bold="\[$(tput bold)\]"
fi
fi
__prompt_git_ref() {
local ref
command -v git >/dev/null 2>&1 || return
git -C "$PWD" rev-parse --is-inside-work-tree >/dev/null 2>&1 || return
ref=$(git -C "$PWD" symbolic-ref --quiet --short HEAD 2>/dev/null)
if [[ -z $ref ]]; then
ref=$(git -C "$PWD" rev-parse --short HEAD 2>/dev/null)
fi
[[ -n $ref ]] || return
printf ' %s(%s)%s' "$Yellow" "$ref" "$Color_Off"
}
__prompt_context() {
local context=
if [[ -n ${VIRTUAL_ENV-} ]]; then
context=${context:+$context,}venv:$(basename "$VIRTUAL_ENV")
fi
if [[ -n ${SSH_CONNECTION-} ]]; then
context=${context:+$context,}ssh
fi
[[ -n $context ]] || return
printf ' %s[%s]%s' "$Cyan" "$context" "$Color_Off"
}
__prompt_jobs() {
local jobs_count=0 _
while read -r _; do
((jobs_count++))
done < <(jobs -p 2>/dev/null)
((jobs_count > 0)) || return
printf ' %s{%s job%s}%s' "$Yellow" "$jobs_count" "$([[ $jobs_count -eq 1 ]] && printf '' || printf 's')" "$Color_Off"
}
__update_prompt() {
local status=$?
local status_mark context jobs
history -a
if (( status != 0 )); then
status_mark="${Red}!${status}${Color_Off} "
fi
context=$(__prompt_context)
jobs=$(__prompt_jobs)
PS1="${status_mark}${Green}[\u@\h]${Color_Off}${jobs}${context}$(__prompt_git_ref)\n${Cyan}\w${Color_Off} \$ "
}
if [[ -e "$HOME/.localrc" ]]; then
# shellcheck disable=SC1090
source "$HOME/.localrc"
fi
PROMPT_COMMAND='__update_prompt'