-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_bashrc.tmpl
102 lines (84 loc) · 2.52 KB
/
dot_bashrc.tmpl
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
###
### ~/.bashrc
###
# Make sure we're in an interactive shell
[[ $- != *i* ]] && return
### aliases
source $HOME/.aliasrc
### history
export HISTCONTROL=ignoredups
shopt -s histappend
export HISTFILESIZE=
export HISTSIZE=
export HISTFILE=$HOME/.shell_history
### exports / functions
set -o emacs
bind '"\C-k": "\C-atime \C-m"'
# ideas for more of these: |less
bind '"\C-j;": "\C-m"'
shopt -s autocd
stty -ixon # diable XON/XOFF
### prompt
# Initialize colors. OpenBSD takes extra, seemingly useless, parameters to tput
# https://marc.info/?l=openbsd-bugs&m=160951076227330&w=2
reset="$(tput sgr0)"
case "$OSTYPE" in
openbsd*)
redf="$(tput setaf 1 0 0)"
greenf="$(tput setaf 2 0 0)"
bluef="$(tput setaf 4 0 0)"
magentaf="$(tput setaf 5 0 0)"
cyanf="$(tput setaf 6 0 0)"
;;
*)
redf="$(tput setaf 1)"
greenf="$(tput setaf 2)"
bluef="$(tput setaf 4)"
magentaf="$(tput setaf 5)"
cyanf="$(tput setaf 6)"
;;
esac
_prompt_git() {
local branch=$(git branch --no-color 2>/dev/null | awk '/\*/{print $NF}' | tr -d '()')
local status="$(git status --porcelain --untracked-files=no 2>/dev/null)"
[ -n "$status" ] && local color="${redf}" || local color="${greenf}"
[ -n "$branch" ] && echo "[$color$branch${reset}]"
}
_prompt_svn() {
if ! svn st 2>&1 | grep -q 'not a working'; then
local message="$(svn st --ignore-externals | cut -f1 -d\ | sort | uniq | paste -s -d\ | tr -d ' ')"
[[ "$message" == *"M"* ]] || [[ "$message" == *"!"* ]] || [[ "$message" == *"C"* ]] && local color="${redf}" || local color="${greenf}"
echo "[$color$message$reset]"
fi
}
__prompt_command() {
local lastExit="$?"
cmd_exists git && local git="$(_prompt_git)" || local git=""
cmd_exists svn && local svn="$(_prompt_svn)" || local svn=""
# hostname HH:MM:SS ~
PS1="\[${magentaf}\]\h\[${reset}\] \[${cyanf}\]\D{%T}\[${reset}\] \w${git}${svn} "
if [ "$lastExit" -eq 0 ]; then
PS1+='$ '
else
PS1+="${redf}${lastExit}${reset} "
fi
}
PROMPT_COMMAND=__prompt_command
### spelling correction provided by delucks/multitool
if hash multitool 2>/dev/null; then
command_not_found_handle() {
corr=$(suggest-fc "$1")
test -z "$corr" || echo "Did you mean ${redf}${corr}${reset}?" >&2
return 127
}
fi
### completion
_ssh_complete() {
COMPREPLY=( $(compgen -W "$(awk '/^Host/{print $2}' "$HOME/.ssh/config"| paste -s)" -- ${COMP_WORDS[COMP_CWORD]}) )
return 0
}
complete -F _ssh_complete ssh
{{ if .uses_wal -}}
# Begin pywal shell integration
#(cat ~/.cache/wal/sequences &)
{{- end }}