-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_bashrc
137 lines (113 loc) · 4.02 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
# If not running interactively, don't do anything
[[ -z $PS1 ]] && return
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
#HISTCONTROL=ignoreboth
HISTCONTROL=ignoreboth:erasedups
# append to the history file, don't overwrite it
shopt -s histappend
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
#############################################################################
# GIT prompt in PS1
#############################################################################
function git_prompt_get_git_branch () {
# On branches, this will return the branch name
# On non-branches, (no branch)
ref="$(git symbolic-ref HEAD 2> /dev/null | sed -e 's/refs\/heads\///')"
if [[ "$ref" != "" ]]; then
echo "$ref"
else
echo "(no branch)"
fi
}
function git_prompt_get_git_info () {
# Grab the branch
branch="$(git_prompt_get_git_branch)"
# If there are any branches
if [[ "$branch" != "" ]]; then
echo "$branch"
fi
}
#############################################################################
# history
#############################################################################
function dedup_bash_history () {
rm -f ~./.unduped_bash_history && \
nl ~/.bash_history | sort -k 2 -k 1,1nr| uniq -f 1 | sort -n | cut -f 2 > ~/.unduped_bash_history && \
cp ~/.unduped_bash_history ~/.bash_history
}
#############################################################################
# PS1 prompt
#############################################################################
PROMPT_COMMAND='history -a && dedup_bash_history'
PS1='\[\033[01;31m\]\w\[\033[00m\] $(git_prompt_get_git_info)\n${debian_chroot:+($debian_chroot)}\[\033[01;34m\]\u\[\033[01;32m\]@\[\033[01;34m\]\h\[\033[00m\]\$ '
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# ----------- End of previous section ----------------
# function to an npm bin to $PATH
function addNpmBinToPath() {
if [[ -d $(npm bin) ]]; then
export PATH=$(npm bin):$PATH
fi
}
#function to use go tip
function useGoTip() {
if [[ -d $HOME/gotip ]]; then
export GOROOT=$HOME/gotip
export PATH=$GOROOT/bin:$PATH
fi
}
function pyclean() {
find . -type d -name "__pycache__" | xargs rm -rf
}
# Default installation path for GOLANG
[[ -d /usr/local/go/bin/ ]] && PATH+=":/usr/local/go/bin/"
# Add env variable to work with GO easier
if [[ -d $HOME/gopath ]]; then
export GOPATH=$HOME/gopath
PATH+=":$GOPATH/bin"
fi
# Starting with go 1.11 GOPATH is not needed anymore
[[ -d $HOME/go/bin ]] && PATH+=":$HOME/go/bin"
# Interative node js version manager
[[ -d $HOME/n/bin ]] && PATH+=":$HOME/n/bin"
[[ -d $HOME/.local/bin ]] && PATH+=":$HOME/.local/bin"
[[ -d $HOME/neovim/bin ]] && PATH+=":$HOME/neovim/bin"
# if ag is available use it by default for FZF
[[ -x $(command -v ag) ]] && export FZF_DEFAULT_COMMAND='ag --hidden --smart-case --ignore=".git" --ignore="__pycache__" -g ""'
if [[ -x $(command -v nvim) ]]; then
# nvim
export EDITOR=nvim
export VISUAL=nvim
export XDG_CONFIG_HOME=~/.config
export GIT_EDITOR=nvim
else
# vim
export EDITOR=vim
export VISUAL=vim
fi
# remap caps lock to escape
# [[ -x $(command -v setxkbmap) ]] && setxkbmap -option "caps:swapescape"
# Set my GPG key
export GPGKEY=2F74DA04
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [[ -f /etc/bash_completion ]] && ! shopt -oq posix; then
source /etc/bash_completion
fi
[[ -f ~/.fzf.bash ]] && source ~/.fzf.bash
# Alias definitions.
[[ -f ~/.bash_aliases ]] && source ~/.bash_aliases
# Local override
[[ -f ~/.bash_local ]] && source ~/.bash_local