-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
151 lines (114 loc) · 4.04 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
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
### CUSTOM BASH PROMPT - CBP
if [ -f '/usr/share/git/git-prompt.sh' ]; then . '/usr/share/git/git-prompt.sh'; fi
get_git_branch() {
# truncate the spaces from __git_ps1's output
local GIT_PS1=$(__git_ps1 "%s")
if [ $(__git_ps1) ]; then
echo -e "(\e[01;32m$(echo $GIT_PS1)\e[0m)"
else
echo ""
fi
}
get_python_env() {
if test -n "$VIRTUAL_ENV"; then
local PYTHON_VIRTUALENV="$(basename $VIRTUAL_ENV)"
# if [ -n "$TMUX" ]; then
# tmux set-environment VIRTUAL_ENV $VIRTUAL_ENV
# fi
else
unset PYTHON_VIRTUALENV
fi
if [ $PYTHON_VIRTUALENV ]; then
echo -e "(\e[1;36m$(echo $PYTHON_VIRTUALENV)\e[0m)"
else
unset PYTHON_VIRTUALENV
echo ""
fi
}
function set_bash_prompt() {
PS1=''
# Show python env
local PYTHON_ENV=$(get_python_env)
if [ -n "$PYTHON_ENV" ]; then
PS1="${PYTHON_ENV}\n"
fi
# Default prompt
PS1="${PS1}\e[01;31m\u\e[0m at \e[01;33m\h\e[0m in \e[01;34m\w\e[0m"
# Show git branch
local GIT_BRANCH=$(get_git_branch)
if [ -n "$GIT_BRANCH" ]; then
PS1="${PS1} ${GIT_BRANCH}"
fi
# Add a new line and $ sign at the end
PS1="${PS1}\n$ "
}
PROMPT_COMMAND=set_bash_prompt
# If inside tmux session and .environment file exists, source it
# If environment file exists (this includes additional environent details that is specific
# to each workspace or project that I am working on)
if [ -f .environment ]; then
source .environment
fi
if [ -n "$NODEJS" ]; then
source $XDG_CONFIG_HOME/scripts/node-setup
fi
# If VIRTUAL_ENV is set
if [ -n "$VIRTUAL_ENV" ]; then
# If inside tmux, set tmux environment variable
if [ -n "$TMUX" ]; then
tmux set-environment VIRTUAL_ENV "$VIRTUAL_ENV"
fi
# Activate the virtual environment
source $VIRTUAL_ENV/bin/activate
fi
### END CBP
[[ -z "$FUNCNEST" ]] && export FUNCNEST=100 # limits recursive functions, see 'man bash'
# vi mode
set -o vi
bind -m vi-command 'Control-l: clear-screen'
bind -m vi-insert 'Control-l: clear-screen'
################################################################################
## Some generally useful functions.
## Consider uncommenting aliases below to start using these functions.
##
## October 2021: removed many obsolete functions. If you still need them, please look at
## https://github.com/EndeavourOS-archive/EndeavourOS-archiso/raw/master/airootfs/etc/skel/.bashrc
#------------------------------------------------------------
## Aliases for the functions above.
## Uncomment an alias if you want to use it.
##
# alias ef='_open_files_for_editing' # 'ef' opens given file(s) for editing
# alias pacdiff=eos-pacdiff
################################################################################
[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion
# Git completion setup for aliases
if [ -f '/usr/share/bash-completion/completions/git' ]; then . '/usr/share/bash-completion/completions/git'; fi
# Bash
source ~/.bash_aliases
# Eval github cli completion only if gh is installed, and the command to eval is eval "$(gh completion -s bash)"
if [ -f '/usr/bin/gh' ]; then eval "$(gh completion -s bash)"; fi
# Auto "cd" when enter just a path
shopt -s autocd
# If a command is typed and it is available as a package
# that package will be recommended
if [ -f '/usr/share/doc/pkgfile/command-not-found.bash' ]; then . '/usr/share/doc/pkgfile/command-not-found.bash'; fi
# Prevent overwrite of files refer [ArchWiki](https://wiki.archlinux.org/title/Bash#Prevent_overwrite_of_files)
set -o noclobber
## Environment variables
export EDITOR="vim"
export TERMINAL="alacritty"
## Use the up and down arrow keys for finding a command in history
## (you can write some initial letters of the command first).
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
# Zsh like autocomplete
bind 'set show-all-if-ambiguous on'
bind 'TAB:menu-complete'
bind 'set completion-ignore-case on'
# tmux completion
if [ -f '/usr/share/bash-completion/completions/tmux' ]; then . '/usr/share/bash-completion/completions/tmux'; fi