-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc.local.example
More file actions
201 lines (157 loc) · 5.95 KB
/
Copy pathbashrc.local.example
File metadata and controls
201 lines (157 loc) · 5.95 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# vi: set ts=4 sw=4 et ft=sh:
################################################################################
### Git Stuff
################################################################################
# Enable Git auto completion
if [ -s "$HOME/.git-completion.bash" ]; then
. "$HOME/.git-completion.bash"
fi
# Enable Git prompt
# This may cause slowdown on filesystems with slow IO
# {<branch> [dirty][stash][untracked][upstream]}
# <branch>: name of checked out branch
# [dirty]: '*' for unstaged changes, '+' for staged changes, or both
# [stash]: '$' if anything is stashed
# [untracked]: '%' is there are untracked files
# [upstream]: status of local relative to upstream; '=' local matches,
# '<' local is behind, '>' local is ahead, '<>' local has diverged
if [ -f "$HOME/.git-prompt.sh" ]; then
GIT_PS1_SHOWDIRTYSTATE=yes # medium performance hit
GIT_PS1_SHOWSTASHSTATE=yes # very small performance hit
GIT_PS1_SHOWUNTRACKEDFILES=yes # large performance hit
GIT_PS1_SHOWUPSTREAM='auto' # very small performance hit
GIT_PS1_SHOWCOLORHINTS=yes
. "$HOME/.git-prompt.sh"
fi
################################################################################
### Dev Tools
################################################################################
# Prevent UV install and self-upgrade from modifying shell profile
export UV_NO_MODIFY_PATH=1
# Add UV and UVX to PATH
# Usually unnecessary because the install path is added to PATH in ~/.profile
#if [ -s "$HOME/.local/bin/env" ]; then
# . "$HOME/.local/bin/env"
#fi
# Load UV and UVX Bash completion if they exist
if [ -s "$HOME/.uv-completion.bash" ]; then
. "$HOME/.uv-completion.bash"
fi
if [ -s "$HOME/.uvx-completion.bash" ]; then
. "$HOME/.uvx-completion.bash"
fi
# Move GOPATH to ~/.local/go instead of the default ~/go
export GOPATH="$HOME/.local/go"
# Add GO to PATH
if [ -d "/usr/local/go/bin" ] && [[ ! ":$PATH:" =~ ":/usr/local/go/bin:" ]]; then
export PATH="/usr/local/go/bin:$PATH"
fi
if [ -d "$GOPATH/bin" ] && [[ ! ":$PATH:" =~ ":$GOPATH/bin:" ]]; then
export PATH="$GOPATH/bin:$PATH"
fi
# Set NVM_DIR if .nvm directory exists
if [ -d "$HOME/.nvm" ]; then
export NVM_DIR="$HOME/.nvm"
fi
# Load NVM if it exists
if [ -s "$NVM_DIR/nvm.sh" ]; then
. "$NVM_DIR/nvm.sh"
fi
# Load NVM Bash completion if it exists
if [ -s "$NVM_DIR/bash_completion" ]; then
. "$NVM_DIR/bash_completion"
fi
################################################################################
### Python Virtual Environment Stuff
################################################################################
# Command to activate virtual environment if one exists
alias _activate='echo "activate(): Activate Python virtual environment in current working directory"'
activate () {
if [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
cat <<- EOF
Usage: activate [-h|--help]
Activates a Python virtual environment in .venv or venv subdirectory of working
directory if one exists
EOF
return 0
fi
if [ -f .venv/bin/activate ]; then
. .venv/bin/activate
elif [ -f venv/bin/activate ]; then
. venv/bin/activate
fi
}
# Format virtual environment name for inserting into the shell prompt
add_venv_info () {
local venv_color="\[\033[35m\]" # purple
local reset_color="\[\033[0m\]"
if [ -n "$VIRTUAL_ENV" ] && [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ]; then
# Strip trailing space from prompt
local prompt="${VIRTUAL_ENV_PROMPT%[[:space:]]}"
# Strip leading and trailing parentheses from prompt
prompt="${prompt#(}"
prompt="${prompt%)}"
# If prompt is default value, change it to the name of the virtual
# environment's parent directory
if ([ "$prompt" = ".venv" ] && [ "$(basename "$VIRTUAL_ENV")" = ".venv" ]) \
|| ([ "$prompt" = "venv" ] && [ "$(basename "$VIRTUAL_ENV")" = "venv" ])
then
prompt="$venv_color($(basename $(dirname "$VIRTUAL_ENV")))$reset_color"
fi
if [ -n "$prompt" ]; then
echo "$prompt"
fi
fi
}
################################################################################
### Finalize the prompt
################################################################################
# Build the beginning of the prompt
__ps1_pre () {
local reset_color="\[\033[0m\]"
local pwd_color="\[\033[34m\]" # blue
local screen_color="\[\033[01;33m\]" # gold
local host_txt="\u@\h"
# Make pwd red for root user
if [ "$(id -u)" -eq 0 ]; then
pwd_color="\[\033[31m\]" #red
fi
local pwd_txt="$pwd_color[\w]$reset_color"
# Return just the PWD prompt if in tutorial mode
if [ -n "$TUTORIAL_MODE" ]; then
echo "$pwd_txt"
return 0
fi
# Add screen name to prompt if this is a screen session
if [ -n "$STY" ]; then
screen_txt="$screen_color(${STY#[0-9]*\.}:$WINDOW)$reset_color "
fi
# Add chroot name to prompt if in chroot
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
local chroot_txt="${debian_chroot:+($debian_chroot) }"
echo "$chroot_txt$screen_txt$host_txt:$pwd_txt"
}
# Build the end of the prompt
__ps1_post () {
local ps1_post=" \\$ "
# Return just the $|# prompt if in tutorial mode
if [ -n "$TUTORIAL_MODE" ]; then
echo "$ps1_post"
return 0
fi
# Only add Python virtual environment name to prompt if function exists
if [ "$(type -t add_venv_info)" = 'function' ]; then
ps1_post=" $(add_venv_info) \\$ "
# Replace ' ' with '' in case add_venv_info returns nothing
ps1_post="${ps1_post/# / }"
fi
echo "$ps1_post"
}
# Use __git_ps1 to construct the prompt if it exists
if [ "$(type -t __git_ps1)" = 'function' ] && [ -z "$TUTORIAL_MODE" ]; then
PROMPT_COMMAND='__git_ps1 "$(__ps1_pre)" "$(__ps1_post)" " {%s}"'
else
PS1="$(__ps1_pre)$(__ps1_post)"
fi