-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexports.sh
More file actions
134 lines (111 loc) · 3.51 KB
/
Copy pathexports.sh
File metadata and controls
134 lines (111 loc) · 3.51 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
# shellcheck shell=bash
# ----------------------------
# functions and shell-agnostic
# ----------------------------
function add_to_path() {
# NOTE: zsh only
# usage:
# add_to_path prepend /path/to/prepend
# add_to_path append /path/to/append
if [ -d "$2" ]; then
# If the given path exist, proceed...
if [[ ":$PATH:" == *":$2:"* ]]; then
remove_from_path "$2"
fi
if [ "$1" = "prepend" ]; then
PATH="$2:$PATH"
export PATH
elif [ "$1" = "append" ]; then
PATH="$PATH:$2"
export PATH
else
echo "Unknown option. Use 'prepend' or 'append'."
fi
fi
}
function remove_from_path() {
# NOTE: zsh only
# usage:
# remove_from_path /path/to/remove
local path_to_remove="$1"
if [[ -n "$path_to_remove" && ":$PATH:" == *":$path_to_remove:"* ]]; then
while [[ ":$PATH:" == *":$path_to_remove:"* ]]; do
# Remove
PATH="${PATH/#$path_to_remove:/}" # If it's at the beginning
PATH="${PATH/%:$path_to_remove/}" # If it's at the end
PATH="${PATH//:$path_to_remove:/:}" # If it's in the middle
done
PATH="${PATH#:}" # Remove leading colon
PATH="${PATH%:}" # Remove trailing colon
export PATH
fi
}
# ----------------------------
# globals
# ----------------------------
if [ -n "${ZSH_VERSION}" ]; then
shell="zsh"
export DOTFILES_DEBUG_SHELL_ZSH="true"
elif [ -n "${BASH_VERSION}" ]; then
shell="bash"
export DOTFILES_DEBUG_SHELL_BASH="true"
else
shell=""
fi
# ----------------------------
# exports
# ----------------------------
# NOTE: brew shellenv exports several environment variables and extends $PATH
if [ -f /opt/homebrew/bin/brew ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
brew_prefix="$(brew --prefix)"
elif [ -f /home/linuxbrew/.linuxbrew/bin/brew ]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew_prefix="$(brew --prefix)"
else
brew_prefix=""
fi
export DOTFILES="$HOME/.dotfiles"
export DOTFILES_SHELL=$shell
export DOTFILES_BREW_PREFIX=$brew_prefix
export HOMEBREW_NO_ANALYTICS=1
export PIP_REQUIRE_VIRTUALENV=true # use pip --isolated to bypass
export GIT_EDITOR="nvim"
export EDITOR="nvim"
add_to_path append "$HOME/.docker/bin"
add_to_path append "$HOME/.cargo/bin"
add_to_path append "$HOME/go/bin"
add_to_path append "$DOTFILES_BREW_PREFIX/opt/mysql-client/bin"
add_to_path prepend "$DOTFILES_BREW_PREFIX/opt/gnu-sed/libexec/gnubin"
add_to_path append "$HOME/.lmstudio/bin" # Added by LM Studio CLI (lms)
add_to_path append "$HOME/.opencode/bin" # Added by OpenCode AI
# NOTE: the last prepend appears first in $PATH, so make sure the order is correct below
add_to_path prepend "$HOME/.local/bin" # user-installed binaries
# HACK: shell/bin is prepended in sourcing.sh after Nix daemon to ensure it comes first
# Source Home Manager session variables (includes sessionPath)
if [ -f "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then
# shellcheck source=/dev/null
source "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
fi
# load .env file if it exists
if [ -f "$HOME/.shell/.env" ]; then
set -a
# shellcheck source=/dev/null
source "$HOME/.shell/.env"
set +a
else
echo "Warning: $HOME/.shell/.env does not exist"
fi
# Per-platform settings
case $(uname) in
Darwin)
# commands for macOS go here
add_to_path append "/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
add_to_path append "/Applications/Obsidian.app/Contents/MacOS"
export SSH_AUTH_SOCK=$HOME/.ssh/proton-pass-ssh-agent.sock
;;
Linux)
# commands for Linux go here
;;
*) ;;
esac