-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsourcing.sh
147 lines (117 loc) · 3.43 KB
/
sourcing.sh
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
# shellcheck shell=bash
# shellcheck source=/dev/null
# ----------------------------
# functions and shell-agnostic
# ----------------------------
function virtual_env_activate() {
if [[ -n "$VIRTUAL_ENV" ]]; then
# check the current folder belong to earlier VIRTUAL_ENV folder
parentdir="$(dirname "$VIRTUAL_ENV")"
if [[ "$PWD"/ != "$parentdir"/* ]]; then
deactivate
fi
fi
if [ -f .python-version ] && [ ! -d ./.venv ]; then
uv venv
fi
if [[ -z "$VIRTUAL_ENV" ]]; then
# if .venv folder is found then activate the vitualenv
if [ -d ./.venv ] && [ -f ./.venv/bin/activate ]; then
source ./.venv/bin/activate
# if pyproject.toml is found then sync the virtualenv
if [[ -f pyproject.toml ]]; then
uv sync --all-groups
fi
fi
fi
}
function node_version_manager() {
if [[ -z "$NVMRC_PATH" ]]; then
if [ -f .nvmrc ]; then
nvm use
export NVMRC_PATH=$PWD/.nvmrc
fi
else
parent_nvmdir="$(dirname "$NVMRC_PATH")"
if [[ "$PWD"/ != "$parent_nvmdir"/* ]]; then
nvm deactivate
export NVMRC_PATH=""
fi
fi
}
function zsh_completion() {
if [ -n "$brew_prefix" ]; then
export FPATH=$brew_prefix/share/zsh/site-functions:$FPATH
source "$brew_prefix/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
source "$brew_prefix/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
fi
if [ -f "$brew_prefix/share/google-cloud-sdk" ]; then
source "$brew_prefix/share/google-cloud-sdk/path.zsh.inc"
source "$brew_prefix/share/google-cloud-sdk/completion.zsh.inc"
fi
if [[ -f ~/.orbstack/bin/docker ]]; then
source ~/.orbstack/shell/init.zsh 2>/dev/null || :
fi
export FPATH=$DOTFILES/work/zsh/site-functions:$FPATH
# Makefile completion
zstyle ':completion:*:*:make:*' tag-order 'targets'
zstyle ':completion:*:make:*:targets' call-command true
autoload -Uz compinit
compinit
}
function bash_completion() {
if [ -f "$brew_prefix/share/google-cloud-sdk" ]; then
source "$brew_prefix/share/google-cloud-sdk/path.bash.inc"
source "$brew_prefix/share/google-cloud-sdk/completion.bash.inc"
fi
}
# ----------------------------
# globals
# ----------------------------
brew_prefix="$DOTFILES_BREW_PREFIX"
shell="$DOTFILES_SHELL"
# ----------------------------
# shell-agnostic configuration
# ----------------------------
if [ -f ~/.cargo/env ]; then
source "$HOME/.cargo/env"
fi
if [ -n "$brew_prefix" ]; then
# TODO: evaluate whether pkgx can replace nvm
# source "$brew_prefix/opt/nvm/nvm.sh"
eval "$(atuin init $shell --disable-up-arrow)"
eval "$(direnv hook $shell)"
eval "$(zoxide init $shell)"
eval "$(starship init $shell)"
fi
# ----------------------------
# shell-specific configuration
# ----------------------------
if [[ $shell == "zsh" ]]; then
zsh_completion
if [ -n "$brew_prefix" ]; then
source <(fzf --zsh)
source <(pkgx dev --shellcode)
fi
elif [[ $shell == "bash" ]]; then
bash_completion
if [ -n "$brew_prefix" ]; then
eval "$(fzf --bash)"
eval "$(pkgx dev --shellcode)"
fi
fi
# ----------------------------------
# overrides
# ----------------------------------
function cd() {
builtin cd "$@" || return
virtual_env_activate
# node_version_manager # TODO: with pkgx, maybe nvm is no longer needed?
}
cd . # trigger cd overrides when shell starts
function z() {
__zoxide_z "$@" && cd . || return
}
function zi() {
__zoxide_zi "$@" && cd . || return
}