Skip to content

Commit c1daaae

Browse files
committed
Check if program exists before configuring
Check if program is present before configuring it (make configuration portable)
1 parent 282a2e7 commit c1daaae

File tree

2 files changed

+69
-41
lines changed

2 files changed

+69
-41
lines changed

zsh/.zshenv

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
# https://zsh.sourceforge.io/Contrib/startup/users/debbiep/dot.zshenv
22
# Function to remove non-existent directories from array.
33
rationalize-path () {
4-
local element
5-
local build
6-
build=()
7-
# Evil quoting to survive an eval and to make sure that
8-
# this works even with variables containing IFS characters, if I'm
9-
# crazy enough to setopt shwordsplit.
10-
eval '
11-
foreach element in "$'"$1"'[@]"
12-
do
13-
if [[ -d "$element" ]]
14-
then
15-
build=("$build[@]" "$element")
16-
fi
17-
done
18-
'"$1"'=( "$build[@]" )
19-
'
4+
local element
5+
local build
6+
build=()
7+
# Evil quoting to survive an eval and to make sure that
8+
# this works even with variables containing IFS characters, if I'm
9+
# crazy enough to setopt shwordsplit.
10+
eval '
11+
foreach element in "$'"$1"'[@]"
12+
do
13+
if [[ -d "$element" ]]
14+
then
15+
build=("$build[@]" "$element")
16+
fi
17+
done
18+
'"$1"'=( "$build[@]" )
19+
'
2020
}
2121

2222
# Set up additional paths
2323
path+=(
24-
~/.npm-global/bin
2524
~/.local/bin
26-
~/.linuxbrew/bin
27-
~/.linuxbrew/sbin
2825
)
2926

3027
rationalize-path path
@@ -33,11 +30,6 @@ typeset -U path
3330

3431
# Set INFOPATH
3532
typeset -T INFOPATH infopath
36-
infopath+=(
37-
~/.linuxbrew/share/info
38-
)
39-
rationalize-path infopath
40-
typeset -U infopath
4133

4234
# Set MANPATH
4335
typeset -T MANPATH manpath
@@ -47,20 +39,47 @@ manpath+=(
4739
rationalize-path manpath
4840
typeset -U manpath
4941

50-
source "$HOME/.cargo/env"
42+
if [ ! -f $HOME/.cargo/env ]
43+
then
44+
source "$HOME/.cargo/env"
45+
fi
46+
47+
# Set up pyenv
48+
if (( $+commands[pyenv] ))
49+
then
50+
export PYENV_ROOT="$HOME/.pyenv"
51+
path=($PYENV_ROOT/bin "$path[@]")
52+
eval "$(pyenv init --path)"
53+
eval "$(pyenv init -)"
54+
eval "$(pyenv virtualenv-init -)"
55+
fi
56+
57+
# Set up linuxbrew
58+
if (( $+commands[brew] ))
59+
then
60+
export HOMEBREW_PREFIX=~/.linuxbrew
61+
export HOMEBREW_CELLAR=~/.linuxbrew/Cellar
62+
export HOMEBREW_REPOSITORY=~/.linuxbrew/Homebrew
63+
export HOMEBREW_SHELLENV_PREFIX=~/.linuxbrew
5164

52-
# Set up Brew
53-
export HOMEBREW_PREFIX=~/.linuxbrew
54-
export HOMEBREW_CELLAR=~/.linuxbrew/Cellar
55-
export HOMEBREW_REPOSITORY=~/.linuxbrew/Homebrew
56-
export HOMEBREW_SHELLENV_PREFIX=~/.linuxbrew
65+
path+=(
66+
~/.linuxbrew/bin
67+
~/.linuxbrew/sbin
68+
)
69+
rationalize-path path
70+
typeset -U path
71+
72+
infopath+=(
73+
~/.linuxbrew/share/info
74+
)
75+
rationalize-path infopath
76+
typeset -U infopath
77+
fi
78+
79+
# Set up cuda
80+
path=(/usr/local/cuda-11.6/bin "$path[@]")
81+
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
5782

5883
# Source aliases
5984
source $HOME/.aliases.zsh
6085

61-
# Set up pyenv
62-
export PYENV_ROOT="$HOME/.pyenv"
63-
path=($PYENV_ROOT/bin "$path[@]")
64-
eval "$(pyenv init --path)"
65-
eval "$(pyenv init -)"
66-
eval "$(pyenv virtualenv-init -)"

zsh/.zshrc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
git clone --depth 1 -- \
55
https://github.com/marlonrichert/zsh-snap.git ~/.znap/zsh-snap
66

7+
# Load znap
78
source ~/.znap/zsh-snap/znap.zsh
89

910
# Enable menu-driven completion
@@ -31,13 +32,21 @@ znap eval trapd00r/LS_COLORS "$( whence -a dircolors gdircolors ) -b LS_COLORS"
3132
znap source zsh-users/zsh-autosuggestions
3233
znap source zsh-users/zsh-completions
3334
znap source esc/conda-zsh-completion
34-
znap source DarrinTisdale/zsh-aliases-exa
35+
36+
# Install exa aliases only if exa is installed
37+
if (( $+commands[exa] ))
38+
then
39+
znap source DarrinTisdale/zsh-aliases-exa
40+
fi
3541
### End install plugins
3642

3743
### Configure completions
3844
#
39-
znap fpath _rustup 'rustup completions zsh'
40-
znap fpath _cargo 'rustup completions zsh cargo'
45+
if (( $+commands[rustup] ))
46+
then
47+
znap fpath _rustup 'rustup completions zsh'
48+
znap fpath _cargo 'rustup completions zsh cargo'
49+
fi
4150
### End configure completions
4251

4352
### Functions
@@ -92,15 +101,15 @@ unset __conda_setup
92101
### End configure conda
93102

94103
### Configure junegunn/fzf
95-
104+
# https://github.com/junegunn/fzf
105+
#
96106
export FZF_DEFAULT_COMMAND="fd . $HOME"
97107
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
98108
export FZF_ALT_C_COMMAND="fd -t d . $HOME"
99109

100110
# Press CTRL-Y to copy the line to clipboard and aborts fzf
101111
export FZF_DEFAULT_OPTS="--bind 'ctrl-w:execute-silent(echo {} | xclip -i -sel clip)+abort'"
102112

103-
#
104113
# Source key binding and completion
105114
source /usr/share/doc/fzf/examples/key-bindings.zsh
106115
source /usr/share/doc/fzf/examples/completion.zsh

0 commit comments

Comments
 (0)