chore(zsh): various tweaks to zsh env setup and helpers

This commit is contained in:
2024-01-06 15:10:15 +00:00
parent a304b0bb26
commit 9526b57d38
6 changed files with 46 additions and 16 deletions

View File

@@ -17,7 +17,7 @@
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin</string>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin</string>
</dict>
<key>StartCalendarInterval</key>
<dict>

View File

@@ -1,3 +1,3 @@
export POW_DST_PORT=88
export HOME=~
export PATH="$HOME/.rbenv/shims:$HOME/.rbenv/bin:/usr/local/bin:$PATH"
export PATH="$HOME/.rbenv/shims:$HOME/.rbenv/bin:/usr/local/bin:/opt/homebrew/bin:$PATH"

View File

@@ -2,10 +2,6 @@
# Google Cloud SDK setup.
#
if [ -f '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc' ]; then
source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc'
fi
# Lazy load gcloud shell completion on first use.
if command-exists gcloud; then
_python_argcomplete() {
@@ -17,8 +13,8 @@ if command-exists gcloud; then
load-gcloud-completion() {
unset -f load-gcloud-completion _python_argcomplete
if [ -f '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc' ]; then
source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc'
if [ -n "$HOMEBREW_PREFIX" ]; then
source-if-exists "${HOMEBREW_PREFIX}/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc"
fi
}
fi

View File

@@ -23,11 +23,13 @@ if command-exists kubectl; then
}
_setup-kubectl-completion
if command-exists brew-prefix; then
switch() {
unset -f switch
source "$(brew --prefix switch)/switch.sh"
source "$(brew-prefix switch)/switch.sh"
switch "$@"
}
fi
export KREW_ROOT="$HOME/.krew"
path_append "${KREW_ROOT}/bin"

33
zshenv
View File

@@ -68,6 +68,12 @@ command-exists() {
return $?
}
source-if-exists() {
if [ -f "$1" ]; then
source "$1"
fi
}
# ==============================================================================
# System Environment Setup
# ==============================================================================
@@ -126,6 +132,26 @@ if [ -f "/opt/homebrew/bin/brew" ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
if command-exists brew; then
typeset -A _brew_prefix_cache
brew-prefix() {
local package="$1"
if [[ -z "$package" ]]; then
package="__none__"
fi
if [[ -n "${_brew_prefix_cache[$package]}" ]]; then
echo "${_brew_prefix_cache[$package]}"
else
local result=$(brew --prefix "$package")
_brew_prefix_cache[$package]=$result
echo $result
fi
}
fi
# Linuxbrew
if [ -f "/home/linuxbrew/.linuxbrew/bin/brew" ]; then
# Inline linux-brew setup to improve shell startup speed by around 200ms.
@@ -209,11 +235,12 @@ path_prepend "$HOME/.local/share/rtx/bin"
path_prepend "$HOME/.local/share/rtx/shims"
# orbstack setup
if [ -f "$HOME/.orbstack/shell/init.zsh" ]; then
source "$HOME/.orbstack/shell/init.zsh"
fi
source-if-exists "$HOME/.orbstack/shell/init.zsh"
path_prepend "$HOME/.orbstack/bin"
# Google Cloud SDK setup
source-if-exists "${HOMEBREW_PREFIX}/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc"
# ==============================================================================
# Path setup for select binaries installed with zinit
# ==============================================================================

5
zshrc
View File

@@ -116,6 +116,11 @@ fi
# Prompt
# ==============================================================================
if ! command-exists starship; then
read -q 'REPLY?starship is not installed, install with `rtx install starship`? [y/N]:' &&
echo && rtx install starship
fi
if command-exists starship; then
eval "$(starship init zsh --print-full-init)"