-
Notifications
You must be signed in to change notification settings - Fork 0
/
.setup_base_env
282 lines (242 loc) · 11.8 KB
/
.setup_base_env
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
##!/bin/bash
# ~/.setup_basic_env
# Basic environment setup, including PATH
##############################################################
#-------------------------------------------------------------
# Custom shell variables and early exports
#-------------------------------------------------------------
##############################################################
# For filename expansion, ignore filename matches that match any of the colon-separated globs in 'GLOBIGNORE'. Honors the setting of the extglob shell options
#-------------------------------------------------------------
#export GLOBIGNORE=".:.." #How often do you REALLY want a glob to match "." or ".."?
# Don't auto-complete files with the following file extensions
#-------------------------------------------------------------
export FIGNORE=".dll:.DLL:.ax" #:.DS_Store:.pyc:.pyd:
# Treat files (with executable-bit set) matching these globs as not being on the PATH.
# Does not affect commands already in the hash, or bash's `[` `[[` and `test` commands.
#-------------------------------------------------------------
#export EXECIGNORE=""
# Must press ctrl+D 1+$IGNOREEOF times to exit shell...
# because I've accidentally'd my shell a few times too many when trying to send ctrl+D while suffering input delay
#-------------------------------------------------------------
export IGNOREEOF="1"
# Set arguments to automatically pass to the less pager; git pager needs to include -R and -F for git commands to behave nicely, but including -F in LESS affects man, so the -F should be handled in the gitconfig and/or aliases for less/man/git.
LESS="-R -PM ?f%f .?n?m(%T %i of %m) ..?ltlines %lt-%lb?L/%L. :byte %bB?s/%s. .?e(END) ?x- Next\: %x.:?pB%pB\%.. ?f(Press v to open with default editor).%t"
# --show-preproc-errors --modelines 2?
less_ver_compat(){
# Add various flags to LESS if the installed version is new enough to understand them (rather than complain and immediately exit with return code 0).
# Unfortunately, there seems to be no good way of removing both a suffix and a prefix in the same assignment,
# but assigning multiple times in the same command works.
ver="$(less -V)" ver="${ver#less }" ver="${ver%% \(*}"; # The parenthesis in the 3rd assignment needs to be escaped for Zsh compat.
[ "0${ver}" -ge 549 ] && LESS="--no-histdups --wheel-lines=3 ${LESS}"
[ "0${ver}" -ge 621 ] && LESS="--wordwrap ${LESS}"
[ "0${ver}" -ge 624 ] && LESS="--proc-backspace ${LESS}"
}; less_ver_compat; unset -f less_ver_compat; unset ver;
export LESS
# Colored man pages: http://linuxtidbits.wordpress.com/2009/03/23/less-colors-for-man-pages/
# Less Colors for Man Pages
# Coloration seems to behave strangely at times, but oh well.
#export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
#export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
#export LESS_TERMCAP_me=$'\E[0m' # end mode
#export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
#export LESS_TERMCAP_so=$'\E[7;33;40m' # begin standout-mode - info box
#export LESS_TERMCAP_ue=$'\E[0m' # end underline
#export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
export LESSCHARSET='utf-8'
# Wait 4000 ms without receiving input before displaying the status message to tell the user it's still waiting.
export LESS_DATA_DELAY=4000
# Allow different preferred editors for local and remote sessions
if [ -n "$SSH_CONNECTION" ]; then
export EDITOR="/usr/bin/nano"
# export VISUAL="/usr/bin/nano"
else
export EDITOR="/usr/bin/nano"
# Example of dynamically selecting VISUAL according to availability of a graphic environment:
# "$(if [ -n $DISPLAY ]; then echo GRAPHICAL_TEXT_EDITOR; else echo '/usr/bin/nano'; fi)"
# export VISUAL="/usr/bin/nano"
fi
command -v sudo >/dev/null 2>&1 && export SUDO_EDITOR="$EDITOR"
export TIME_STYLE="+%b %_2d, %_Y %_2I:%02M %p"
# export LANG='en_US.UTF-8'
export GCC_COLORS=1
export CARGO_HOME="${HOME}/.cargo"
export RUSTUP_HOME="${HOME}/.cargo"
export DOTNET_CLI_TELEMETRY_OPTOUT=1
# Proposed common opt-out: https://consoledonottrack.com
export DO_NOT_TRACK=1
# Enable accessibility for Qt; not sure what this will actually do in the absence of an X11 session
# This is commonly set by one of the startup scripts in /etc/X11/Xsession.d/
QT_ACCESSIBILITY="${QT_ACCESSIBILITY:-1}"
# Eventually, I'd like to move this to a dedicated "compat" file for sourcing
# On some DE/WM, this package and variable will help maintain a uniform theme for Qt5 applications
command -v qt5ct >/dev/null 2>&1 && export QT_QPA_PLATFORMTHEME=qt5ct
# Make Python use UTF-8 encoding for output to stdin/stdout/stderr.
#-------------------------------------------------------------
export PYTHONIOENCODING="UTF-8"
# Disallow pip from installing packages outside of a virtualenv
#-------------------------------------------------------------
#export PIP_REQUIRE_VIRTUALENV=true
# Config file path variables
#-------------------------------------------------------------
export BAT_CONFIG_PATH="${HOME}/.config/bat/config"
export RIPGREP_CONFIG_PATH="${HOME}/.config/ripgrep/.ripgreprc"
export HTML_TIDY="${HOME}/.config/html_tidy/.tidyrc"
##############################################################
#-------------------------------------------------------------
# Helper Functions
#-------------------------------------------------------------
##############################################################
# Adds to the $PATH variable, if path not already present
# Default is to prepend to $PATH
# Add "after" to append to $PATH
# function pathmunge () {
# if ! echo "$PATH" | $(/bin/grep -Eq "(^|:)$1($|:)") ; then # try calling grep in subshell for potential slight performance boost
# if [ "$2" = "after" ] ; then
# PATH="$PATH:$1"
# else
# PATH="$1:$PATH"
# fi
# fi
# }
# Does the same thing as pathmunge, but for MANPATH
# function manpathmunge () {
# if ! echo "$MANPATH" | $(/bin/grep -Eq "(^|:)$1($|:)") ; then
# if [ "$2" = "after" ] ; then
# MANPATH="$MANPATH:$1"
# else
# MANPATH="$1:$MANPATH"
# fi
# fi
# }
# Hopefully faster alternative to pathmunge; appends by default
function pathadd() {
# Prepend/append to path, without duplicates
# NOTE: be careful of path strings which are still valid if a variable in it is null or unset.
case "$1" in
"--prepend")
shift # Clearly we don't want PATH to be "--prepend:$PATH"
[ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]] && \
export PATH="$1${PATH:+:${PATH}}"
;;
"--append")
shift
;& # Intentionally fall through to default case
*)
[ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]] && \
export PATH="${PATH:+${PATH}:}$1"
;;
esac
}
# Hopefully faster alternative to manpathmunge; appends by default
function manpathadd() {
# Prepend/append to manpath, without duplicates
# NOTE: be careful of path strings which are still valid if a variable in it is null or unset.
case "$1" in
"--prepend")
shift # Clearly we don't want MANPATH to be "--prepend:$MANPATH"
[ -d "$1" ] && [[ ":$MANPATH:" != *":$1:"* ]] && \
export MANPATH="$1${MANPATH:+:${MANPATH}}"
;;
"--append")
shift
;& # Intentionally fall through to default case
*)
[ -d "$1" ] && [[ ":$MANPATH:" != *":$1:"* ]] && \
export MANPATH="${MANPATH:+${MANPATH}:}$1"
;;
esac
}
#Check if a particular directory is on the PATH
function checkpath(){
case ":$PATH:" in
*:"$1":*) echo "'$1' is on the PATH";;
*) echo "'$1' is not on the PATH";;
esac
}
seemsLikeWSL(){ # May want to add an OS check here too, just to be safe.
# Return 0 if the system appears to be WSL; return 1 otherwise
# [ -n $(command -v wsl) -o -n $(command -v wsl.exe) ] && \
# return 0 || \
# return 1
grep -q Microsoft /proc/version
}
##############################################################
#-------------------------------------------------------------
# Additions to PATH
#-------------------------------------------------------------
##############################################################
# Try to use /env/environment for the default system path; Fully reconstruct PATH to prevent pollution by calls to `source`
# This is most likely a very less-than-ideal method of doing so, but it's worked for several months, and I lack better ideas.
# NOTE: this might have been a typo for /etc/environment, and should be verified
if [ -r "/env/environment" ]; then
# FIXME: Honestly, this probably isn't the greatest idea, so I should probably do away with it...
PATH=$(/usr/bin/cat /env/environment)
PATH="${PATH:6:-1}"
else
# shellcheck disable=SC3028
if [ "$OSTYPE" = 'msys' ]; then
# Best guess at a default path for msys (or cygwin, but I don't use that personally)
PATH="/usr/local/bin:/usr/bin:/bin:/opt/bin"
else
# Best guess at a default system path on a unix/linux system
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
fi
fi
if [ -n "$MINGW_PREFIX" ]; then
# If using MINGW, specifically NOT the MSYS2 compat layer,
# this MUST be before other standard system paths,
# but should still come AFTER paths used for personal scripts,
# such that a wrapper script can "shadow" a binary from the relevant MINGW environment.
PATH="${MINGW_PREFIX}/bin:$PATH"
elif [ -n "$MSYSTEM" ]; then
# If using MSYS2, specifically NOT MINGW, it may still be good to have MINGW binaries in the PATH.
# Of course, since I'll primarily be using things for MSYS2 in that case, the MINGW binaries
# should be AFTER the MSYS2 binaries on the PATH, such that only binaries installed for a MINGW
# environment will be callable without explicit prefixing.
if [ -r '/mingw64/bin' ]; then
PATH="$PATH:/mingw64/bin"
elif [ -r '/mingw32/bin' ]; then
# If ever I want to use anything MINGW, I'll use MINGW64 when possible.
PATH="$PATH:/mingw32/bin"
else
# shellcheck disable=SC2016
printf 'WARNING: $MSYSTEM has been assigned to an unrecognized value of "%s". There may be unexpected or missing PATH entries.\n' "$MSYSTEM"
fi
fi
[ -v CARGO_HOME ] && PATH="$CARGO_HOME/bin:$PATH" # Insert before system binary locations, but not before user binary locations.
[ -d "${HOME}/.local/bin" ] && PATH="${HOME}/.local/bin:$PATH"
[ -d "${HOME}/bin" ] && PATH="${HOME}/bin:$PATH"
# Don't add this clutter to the path if aliases have already been generated through generateAll.sh;
# the aliases will be sourced in .bashrc if they exist in the user's home directory
if [ ! -r ~/.winAliases ] || [ ! -r ~/.sys32Aliases ]; then
# !!TODO: Script that creates aliases for things in /c/Windows/System32/Wbem
# shellcheck disable=SC3028
if [ "$OSTYPE" = 'msys' ]; then
PATH="$PATH:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/"
elif seemsLikeWSL; then
# System is most likely WSL
PATH="$PATH:/mnt/c/Windows/System32:/mnt/c/Windows:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/"
fi
fi
# shellcheck disable=SC3028
[ "$OSTYPE" = 'msys' ] && PATH="$PATH:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl"
##############################################################
#-------------------------------------------------------------
# Additions to MANPATH
#-------------------------------------------------------------
##############################################################
# In general, try to avoid using this if possible. Man tends to do a better job at this than we users do,
# and packages installed through the system package manager especially tend to put their manpages somewhere
# that man has no trouble finding them.
#
# I don't currently install anything that would have me adding to MANPATH with both msys and unix/linux systems
##############################################################
#-------------------------------------------------------------
# Load sensitive and machine-specific environment settings
#-------------------------------------------------------------
##############################################################
if [ -r "${HOME}/.setup_machine_env" ]; then
. "${HOME}/.setup_machine_env"
fi
export PATH #MANPATH