Skip to content

Commit 76506b8

Browse files
committed
Speed up on Windows: avoid cygpath calls etc.
1 parent 8a3862b commit 76506b8

File tree

1 file changed

+60
-27
lines changed

1 file changed

+60
-27
lines changed

.bashrc

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,43 @@ umask 2
121121
# Uncomment for setpath debugging
122122
# SETPATH_VERBOSE=1
123123

124+
# This is for speed, since we check for cygpath repeatedly
125+
CYGPATH_AVAILABLE=
126+
function has_cygpath {
127+
[[ -n "$CYGPATH_AVAILABLE" ]] && return 0
128+
if has_command cygpath; then
129+
CYGPATH_AVAILABLE=1
130+
return 0
131+
fi
132+
return 1
133+
}
134+
135+
# Global cache (should be defined once)
136+
typeset -gA CYGPATH_CACHE
137+
138+
# Usage: cached_cygpath "/some/path" resultvar
139+
cached_cygpath() {
140+
local key=$1
141+
local __retvar=$2
142+
local val
143+
144+
# Fast path: if no backslash or colon, assume it's already Unix-style
145+
if [[ $key != *[:\\]* ]]; then
146+
eval "$__retvar=\"\$key\""
147+
return
148+
fi
149+
150+
if [[ -n ${CYGPATH_CACHE[$key]} ]]; then
151+
val=${CYGPATH_CACHE[$key]}
152+
else
153+
val=$(cygpath "$key")
154+
CYGPATH_CACHE[$key]=$val
155+
echo "cached_cygpath($key) = ${CYGPATH_CACHE[$key]}"
156+
fi
157+
158+
eval "$__retvar=\"\$val\""
159+
}
160+
124161
# Check if given path $1 exists
125162
# Assume it's present if $2 is "always"
126163
path_check () {
@@ -132,12 +169,21 @@ path_check () {
132169
return 0
133170
}
134171

172+
# Check if $PATH contains dir (case sensitive, so beware on Windows)
173+
path_contains_dir() {
174+
case ":$PATH:" in
175+
*":$1:"*) return 0 ;;
176+
*) return 1 ;;
177+
esac
178+
}
179+
135180
# Append $1 to path; move to back if already in path.
136181
# If $2 is "always", append to path even if it doesn't exist.
137182
# Use cygpath on Windows to preprocess into cygwin/Unix style
138183
path_append () {
139-
if has_command cygpath; then
140-
P=$(cygpath "$1")
184+
local P
185+
if has_cygpath; then
186+
cached_cygpath "$1" P
141187
else
142188
P="$1"
143189
fi
@@ -157,11 +203,14 @@ path_prepend () {
157203
}
158204
path_remove () {
159205
[[ -n $SETPATH_VERBOSE ]] && echo "PATH: removing $1"
160-
if has_command cygpath; then
161-
P=$(cygpath "$1")
206+
local P
207+
if has_cygpath; then
208+
cached_cygpath "$1" P
162209
else
163210
P="$1"
164211
fi
212+
path_contains_dir "$1" || return 0 # Already absent, nothing to do
213+
165214
if [[ -n "$ZSH_VERSION" ]]; then
166215
path_remove_zsh "$P"
167216
else
@@ -185,16 +234,6 @@ path_remove_zsh () {
185234
path=(${path:|to_remove})
186235
}
187236

188-
# Check if $PATH contains dir (case sensitive, so beware on Windows)
189-
function path_contains_dir {
190-
local dir_path=$1
191-
if [[ ":$PATH:" =~ ":$dir_path:" ]]; then
192-
return 0
193-
else
194-
return 1
195-
fi
196-
}
197-
198237
setpath_simplex_msys_emacs() {
199238
# This is just for building emacs with msys
200239
PATH=/FOR_MSYS:/bin:/usr/bin:/sbin:/mingw/bin:/c/Users/garyo/bin
@@ -218,19 +257,8 @@ setpath_windows() {
218257
path_prepend /c/bin always # ffmpeg etc.
219258
path_append /c/Windows
220259
path_append /c/Windows/system32
221-
path_prepend "/c/Program Files/GnuGlobal/bin"
222260
path_append "/c/Program Files/Cppcheck" # cppcheck, useful utility
223-
# dumpbin.exe:
224-
path_append "/c/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx64/x64"
225-
path_append "/c/Program Files (x86)/PuTTY" # for plink (ssh)
226261
path_prepend "/c/bin" always # local programs e.g. git-lfs
227-
path_append "/c/Program Files/GnuGlobal/bin"
228-
path_append "/swig"
229-
# Common locations for Emacs:
230-
path_prepend "/c/emacs/emacs/bin"
231-
path_prepend "/c/emacs/bin"
232-
path_prepend "/d/emacs/emacs/bin"
233-
path_prepend "/d/emacs/bin"
234262
path_append "$HOME/bin/_Dependencies" # list dll dependencies, exe is "Dependencies"
235263
path_append /c/ProgramData/chocolatey/bin # runemacs/emacs, putty etc.
236264
}
@@ -842,7 +870,7 @@ mname_prompt() {
842870

843871
if [[ $TERM == dumb ]]; then
844872
PROMPT="> "
845-
elif has_command cygpath && [[ $TERM == emacs ]] ; then
873+
elif has_cygpath && [[ $TERM == emacs ]] ; then
846874
# use cygpath so Emacs dirtrack mode can track it
847875
PROMPT='%U$(mname_prompt) (%F{yellow}%{$(cygpath -m "`pwd`")%}%f $(vcs_info_wrapper)) %@ %B%!=>%b%u
848876
%# %B'
@@ -965,7 +993,12 @@ if [[ -n $ZSH_VERSION && -f ~/.zplug/init.zsh ]]; then
965993
fi
966994

967995
if [[ -n "$ZSH_VERSION" ]]; then
968-
autoload -Uz compinit && compinit
996+
DISABLE_COMPAUDIT=true
997+
mkdir -p ~/.zsh/cache
998+
zstyle ':completion:*' use-cache on
999+
zstyle ':completion:*' cache-path ~/.zsh/cache
1000+
autoload -Uz compinit
1001+
compinit -u -C -d ~/.zsh/cache/zcompdump
9691002
fi
9701003

9711004
########################################################################

0 commit comments

Comments
 (0)