Compare commits

...

10 Commits

27 changed files with 1051 additions and 217 deletions

View File

@@ -1,3 +1,5 @@
[core]
excludesfile = $HOME/.gitignore_global
[alias] [alias]
br = branch br = branch
brr = branch -r brr = branch -r
@@ -12,18 +14,14 @@
cop = "!f() { git checkout ${1-main}; git pull; }; f" cop = "!f() { git checkout ${1-main}; git pull; }; f"
lazy = commit -C HEAD@{1} lazy = commit -C HEAD@{1}
cp = cherry-pick cp = cherry-pick
anne = commit --amend --no-edit cane = commit --amend --no-edit
[init] [init]
defaultBranch = main defaultBranch = main
[pull] [pull]
ff = only ff = only
[user] [color "status"]
name = Tom Hicks added = brightgreen
email = headhunter3@gmail.com untracked = brightred
[http]
lowSpeedLimit = 1000
lowSpeedTime = 60
postBuffer = 524288000
[filter "lfs"] [filter "lfs"]
clean = git-lfs clean -- %f clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f smudge = git-lfs smudge -- %f

2
.gitignore vendored
View File

@@ -1,2 +1,4 @@
/*
!/.*
/history /history
/.vscode/extensions /.vscode/extensions

View File

@@ -1,2 +1,3 @@
*~ *~
.DS_Store .DS_Store
._*

View File

@@ -1,28 +1,4 @@
# ~/.profile: executed by the command interpreter for login shells. . "$HOME/.cargo/env"
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask # Hermes Agent — ensure ~/.local/bin is on PATH
# for ssh logins, install and configure the libpam-umask package. export PATH="$HOME/.local/bin:$PATH"
#umask 022
# TODO: Do this for zsh and exec $HOME/.zshrc?
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi

View File

@@ -1,49 +1,108 @@
# Android sdk # Setup Android SDK environment and tools
# ~/Library/Android/sdk/ _setup_android() {
if [ -d "${HOME}/Library/Android/sdk" ]; then [ -n "$ZSH_VERSION" ] && setopt localoptions nonomatch nullglob
export ANDROID_HOME="${HOME}/Library/Android/sdk"
fi
if [ -d "${HOME}/Applications/Android/cmdline-tools" ]; then _add_to_path() {
export ANDROID_HOME="${HOME}/Applications/Android/cmdline-tools" [ -d "$1" ] || return 0
fi case ":$PATH:" in
*":$1:"*) ;;
*) PATH="$1:$PATH"; export PATH ;;
esac
}
if [ -n "${ANDROID_HOME}" ]; then # Retrieve the latest versioned subdirectory using version sorting
path=(${ANDROID_HOME}/cmdline-tools/latest/bin $path) _get_latest_subdir() {
# TODO: Find a way to get these versions as the latest versions in the directories. [ -d "$1" ] || return 1
path=(${ANDROID_HOME}/build-tools/34.0.0 $path) _latest=$(
path=(${ANDROID_HOME}/ndk/26.1.0909125 $path) for _d in "$1"/*; do
path=(${ANDROID_HOME}/platform-tools $path) [ -d "$_d" ] && basename "$_d"
path=(${ANDROID_HOME}/tools $path) done | { sort -V 2>/dev/null || sort -n 2>/dev/null || sort; } | tail -n 1
path=(${ANDROID_HOME}/tools:/bin $path) )
fi if [ -n "$_latest" ] && [ -d "$1/$_latest" ]; then
echo "$1/$_latest"
return 0
fi
return 1
}
# "extras;google;simulators" "ndk;27.0.11718014" "platform-tools" "platforms;android-34" "system-images;android-34;default;arm64-v8a" # Common SDK search locations in priority order (macOS, Linux, WSL)
# The first directory found will be selected and configured.
_sdk_candidates=(
"${ANDROID_HOME:-}"
"${ANDROID_SDK_ROOT:-}"
"$HOME/Library/Android/sdk" # macOS Android Studio default
"$HOME/Android/Sdk" # Linux / WSL Android Studio default
"$HOME/android-sdk" # Common user manual install
"$HOME/.android/sdk"
"$HOME/Applications/Android/sdk"
"$HOME/Applications/Android/cmdline-tools"
"/usr/lib/android-sdk" # Linux distribution package (e.g. apt)
"/opt/android-sdk" # Linux system manual install
"/opt/android/sdk"
"/var/lib/android-sdk"
"/opt/homebrew/share/android-commandlinetools" # macOS Apple Silicon Homebrew
"/opt/homebrew/share/android-sdk"
"/usr/local/share/android-commandlinetools" # macOS Intel Homebrew
"/usr/local/share/android-sdk"
"/Library/Android/sdk" # macOS system-wide install
)
function anon() { _found_sdk=""
local android_studio_sdk_home_on_mac="$HOME/Library/Android/sdk" for _dir in "${_sdk_candidates[@]}"; do
local android_home= if [ -n "$_dir" ] && [ -d "$_dir" ]; then
if [ -d "$android_studio_sdk_home_on_mac" ]; then _found_sdk="$_dir"
android_home="$android_studio_sdk_home_on_mac" break
elif [ -d "$android_cmdline_tools_on_mac" ]; then fi
android_home="$android_cmdline_tools_on_mac" done
if [ -z "$_found_sdk" ]; then
return 0
fi fi
if [ -n "$android_home" ]; then # Set SDK environment variables
export ANDROID_HOME="$android_home" export ANDROID_HOME="$_found_sdk"
if [ -d "$android_home/cmdline-tools/latest/bin" ]; then export ANDROID_SDK_ROOT="$_found_sdk"
path=("$android_home/cmdline-tools/latest/bin" $path)
fi # Find the most recent build-tools
# TODO: Get the appropriate directories based on what is available. _build_tools_dir=""
path=(${ANDROID_HOME}/build-tools/34.0.0 $path) if [ -d "$_found_sdk/build-tools" ]; then
path=(${ANDROID_HOME}/ndk/26.1.0909125 $path) _build_tools_dir=$(_get_latest_subdir "$_found_sdk/build-tools")
path=(${ANDROID_HOME}/platform-tools $path)
path=(${ANDROID_HOME}/tools $path)
path=(${ANDROID_HOME}/tools:/bin $path)
fi fi
# "extras;google;simulators" "ndk;27.0.11718014" "platform-tools" "platforms;android-34" "system-images;android-34;default;arm64-v8a" # Find the most recent NDK
_ndk_dir=""
if [ -d "$_found_sdk/ndk" ]; then
_ndk_dir=$(_get_latest_subdir "$_found_sdk/ndk")
elif [ -d "$_found_sdk/ndk-bundle" ]; then
_ndk_dir="$_found_sdk/ndk-bundle"
fi
unset -f anon if [ -n "$_ndk_dir" ] && [ -d "$_ndk_dir" ]; then
export NDK_HOME="$_ndk_dir"
export ANDROID_NDK_HOME="$_ndk_dir"
fi
# Find cmdline-tools (prefer 'latest', then highest version, then root bin)
_cmdline_tools_bin=""
if [ -d "$_found_sdk/cmdline-tools/latest/bin" ]; then
_cmdline_tools_bin="$_found_sdk/cmdline-tools/latest/bin"
elif [ -d "$_found_sdk/cmdline-tools" ]; then
_latest_cmdline=$(_get_latest_subdir "$_found_sdk/cmdline-tools")
if [ -n "$_latest_cmdline" ] && [ -d "$_latest_cmdline/bin" ]; then
_cmdline_tools_bin="$_latest_cmdline/bin"
fi
elif [ -d "$_found_sdk/bin" ]; then
_cmdline_tools_bin="$_found_sdk/bin"
fi
# Prepend tools to PATH in reverse priority so most critical are at front
_add_to_path "$_found_sdk/tools"
_add_to_path "$_found_sdk/tools/bin"
[ -n "$_ndk_dir" ] && _add_to_path "$_ndk_dir"
[ -n "$_build_tools_dir" ] && _add_to_path "$_build_tools_dir"
_add_to_path "$_found_sdk/emulator"
_add_to_path "$_found_sdk/platform-tools"
[ -n "$_cmdline_tools_bin" ] && _add_to_path "$_cmdline_tools_bin"
} }
anon _setup_android
unset -f _setup_android _add_to_path _get_latest_subdir

View File

@@ -1,9 +1,105 @@
if [ -f "$HOME/Applications/KickAssembler/KickAss.jar" ]; then # Setup Commodore 64 development environment (KickAssembler & VICE)
# TODO: typeset may fail if CLASSPATH is already tied by another script. Handle this. _setup_c64() {
typeset -T CLASSPATH classpath [ -n "$ZSH_VERSION" ] && setopt localoptions nonomatch nullglob
classpath+="$HOME/Applications/KickAssembler/KickAss.jar"
export CLASSPATH _add_to_path() {
fi [ -d "$1" ] || return 0
if [ -d "/Applications/VICE/bin" ]; then case ":$PATH:" in
path=(/Applications/VICE/bin $path) *":$1:"*) ;;
fi *) PATH="$1:$PATH"; export PATH ;;
esac
}
_add_to_classpath() {
[ -f "$1" ] || return 0
case ":$CLASSPATH:" in
*":$1:"*) ;;
*) CLASSPATH="${CLASSPATH:+$CLASSPATH:}$1"; export CLASSPATH ;;
esac
}
# 1. KickAssembler search locations (macOS and Linux)
_kickass_candidates=(
"${KICKASS_JAR:-}"
"${KICKASS_HOME:-}/KickAss.jar"
"${KICKASSEMBLER_HOME:-}/KickAss.jar"
"$HOME/Applications/KickAssembler/KickAss.jar"
"$HOME/Applications/KickAssembler/kickass.jar"
"/Applications/KickAssembler/KickAss.jar"
"/Applications/KickAssembler/kickass.jar"
"$HOME/Applications/KickAss/KickAss.jar"
"/Applications/KickAss/KickAss.jar"
"/opt/homebrew/share/kickassembler/KickAss.jar"
"/usr/local/share/kickassembler/KickAss.jar"
"/opt/kickassembler/KickAss.jar"
"/usr/share/kickassembler/KickAss.jar"
"$HOME/.local/share/kickassembler/KickAss.jar"
"$HOME/kickassembler/KickAss.jar"
"$HOME/KickAssembler/KickAss.jar"
)
_found_kickass_jar=""
for _jar in "${_kickass_candidates[@]}"; do
if [ -n "$_jar" ] && [ -f "$_jar" ]; then
_found_kickass_jar="$_jar"
break
fi
done
if [ -n "$_found_kickass_jar" ]; then
_add_to_classpath "$_found_kickass_jar"
_kickass_dir="$(dirname "$_found_kickass_jar")"
_add_to_path "$_kickass_dir"
export KICKASS_HOME="$_kickass_dir"
export KICKASS_JAR="$_found_kickass_jar"
if ! command -v kickass >/dev/null 2>&1; then
kickass() {
java -jar "$KICKASS_JAR" "$@"
}
fi
fi
# 2. VICE search locations (macOS and Linux)
_vice_candidates=(
"${VICE_HOME:-}/bin"
"${VICE_HOME:-}"
"$HOME/Applications/VICE/bin"
"/Applications/VICE/bin"
"$HOME/Applications/VICE.app/Contents/Resources/bin"
"/Applications/VICE.app/Contents/Resources/bin"
"$HOME/Applications/VICE.app/Contents/MacOS"
"/Applications/VICE.app/Contents/MacOS"
"/opt/homebrew/opt/vice/bin"
"/opt/homebrew/bin"
"/usr/local/opt/vice/bin"
"/usr/local/bin"
"/opt/vice/bin"
"/usr/bin"
)
_found_vice_bin=""
for _vdir in "${_vice_candidates[@]}"; do
if [ -n "$_vdir" ] && [ -d "$_vdir" ]; then
if [ -x "$_vdir/x64sc" ] || [ -x "$_vdir/x64" ] || [ -x "$_vdir/c1541" ] || [ -x "$_vdir/vice" ]; then
_found_vice_bin="$_vdir"
break
elif case "$_vdir" in *VICE*bin*|*vice*bin*) true ;; *) false ;; esac; then
_found_vice_bin="$_vdir"
break
fi
fi
done
if [ -n "$_found_vice_bin" ]; then
_add_to_path "$_found_vice_bin"
if [ -z "$VICE_HOME" ]; then
case "$_found_vice_bin" in
*/bin) export VICE_HOME="$(dirname "$_found_vice_bin")" ;;
*) export VICE_HOME="$_found_vice_bin" ;;
esac
fi
fi
}
_setup_c64
unset -f _setup_c64 _add_to_path _add_to_classpath

View File

@@ -1,4 +0,0 @@
if [ -f "$HOME/.cargo/env" ]; then
# For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env"
fi

View File

@@ -1,7 +1,44 @@
if [ -f "/opt/homebrew/bin/fortune" ]; then # Display fortune (with cowsay if available) in top-level interactive shells
if [ -f "/opt/homebrew/bin/cowsay" ]; then # (new iTerm2 tabs/windows, xterm, console, VS Code / IntelliJ terminals).
/opt/homebrew/bin/fortune | /opt/homebrew/bin/cowsay # Subshells (e.g. typing 'bash' or 'zsh' inside an existing terminal) are skipped.
else case $- in
/opt/homebrew/bin/fortune *i*) ;;
fi *) return 0 2>/dev/null || exit 0 ;;
esac
# Skip nested subshells (SHLVL > 1)
if [ "${SHLVL:-1}" -gt 1 ]; then
return 0 2>/dev/null || exit 0
fi fi
_fortune_cmd=""
if command -v fortune >/dev/null 2>&1; then
_fortune_cmd="fortune"
elif [ -x "/opt/homebrew/bin/fortune" ]; then
_fortune_cmd="/opt/homebrew/bin/fortune"
elif [ -x "/usr/games/fortune" ]; then
_fortune_cmd="/usr/games/fortune"
elif [ -x "/usr/local/bin/fortune" ]; then
_fortune_cmd="/usr/local/bin/fortune"
fi
if [ -n "$_fortune_cmd" ]; then
_cowsay_cmd=""
if command -v cowsay >/dev/null 2>&1; then
_cowsay_cmd="cowsay"
elif [ -x "/opt/homebrew/bin/cowsay" ]; then
_cowsay_cmd="/opt/homebrew/bin/cowsay"
elif [ -x "/usr/games/cowsay" ]; then
_cowsay_cmd="/usr/games/cowsay"
elif [ -x "/usr/local/bin/cowsay" ]; then
_cowsay_cmd="/usr/local/bin/cowsay"
fi
if [ -n "$_cowsay_cmd" ]; then
"$_fortune_cmd" | "$_cowsay_cmd"
else
"$_fortune_cmd"
fi
unset _cowsay_cmd
fi
unset _fortune_cmd

View File

@@ -1,16 +1,64 @@
# To set up shell integration, add this to your shell configuration file: # Setup fzf shell integration (bash, zsh, and fallback paths)
# # bash _setup_fzf() {
# eval "$(fzf --bash)" # Ensure fzf binary is accessible if installed in common locations
if ! command -v fzf >/dev/null 2>&1; then
for _fzf_bin_dir in \
"/opt/homebrew/bin" \
"/usr/local/bin" \
"$HOME/.fzf/bin" \
"$HOME/.local/bin"
do
if [ -x "$_fzf_bin_dir/fzf" ]; then
case ":$PATH:" in
*":$_fzf_bin_dir:"*) ;;
*) PATH="$_fzf_bin_dir:$PATH"; export PATH ;;
esac
break
fi
done
fi
# # zsh command -v fzf >/dev/null 2>&1 || return 0
# source <(fzf --zsh)
# # fish if [ -n "$BASH_VERSION" ]; then
# fzf --fish | source if fzf --bash >/dev/null 2>&1; then
eval "$(fzf --bash)"
# To use fzf in Vim, add the following line to your .vimrc: else
# set rtp+=/opt/homebrew/opt/fzf # Fallback for older fzf versions
for _dir in \
if [ -x "$(which fzf)" ]; then "/opt/homebrew/opt/fzf/shell" \
source <(fzf --zsh) "/usr/local/opt/fzf/shell" \
fi "$HOME/.fzf/shell" \
"/usr/share/doc/fzf/examples" \
"/usr/share/fzf"
do
if [ -d "$_dir" ]; then
[ -r "$_dir/completion.bash" ] && \. "$_dir/completion.bash"
[ -r "$_dir/key-bindings.bash" ] && \. "$_dir/key-bindings.bash"
break
fi
done
fi
elif [ -n "$ZSH_VERSION" ]; then
if fzf --zsh >/dev/null 2>&1; then
eval "$(fzf --zsh)"
else
# Fallback for older fzf versions
for _dir in \
"/opt/homebrew/opt/fzf/shell" \
"/usr/local/opt/fzf/shell" \
"$HOME/.fzf/shell" \
"/usr/share/doc/fzf/examples" \
"/usr/share/fzf"
do
if [ -d "$_dir" ]; then
[ -r "$_dir/completion.zsh" ] && \. "$_dir/completion.zsh"
[ -r "$_dir/key-bindings.zsh" ] && \. "$_dir/key-bindings.zsh"
break
fi
done
fi
fi
}
_setup_fzf
unset -f _setup_fzf

View File

@@ -1,7 +1,60 @@
function anon() { # Setup iTerm2 shell integration on macOS
local script_path="$HOME/.iterm2_shell_integration.zsh" _setup_iterm2() {
if [ "$TERM_PROGRAM" = "iTerm.app" -a -e "$script_path" ]; then # Only run on macOS
source "$script_path" [ "$(uname -s 2>/dev/null)" = "Darwin" ] || return 0
# Only run if iTerm.app is available in /Applications or $HOME/Applications
_iterm_app=""
for _app_cand in \
"/Applications/iTerm.app" \
"$HOME/Applications/iTerm.app" \
"/Applications/ITerm.app" \
"$HOME/Applications/ITerm.app" \
"/Applications/iTerm2.app" \
"$HOME/Applications/iTerm2.app"
do
if [ -d "$_app_cand" ]; then
_iterm_app="$_app_cand"
break
fi
done
[ -n "$_iterm_app" ] || return 0
# Add iTerm2 utilities (imgcat, it2dl, etc.) to PATH if available
if [ -d "$_iterm_app/Contents/Resources/utilities" ]; then
case ":$PATH:" in
*":$_iterm_app/Contents/Resources/utilities:"*) ;;
*) PATH="$_iterm_app/Contents/Resources/utilities:$PATH"; export PATH ;;
esac
fi
# Only activate shell integration when running inside iTerm
if [ "$TERM_PROGRAM" = "iTerm.app" ] || [ -n "$ITERM_SESSION_ID" ] || [ "$LC_TERMINAL" = "iTerm2" ]; then
_shell_ext=""
if [ -n "$ZSH_VERSION" ]; then
_shell_ext="zsh"
elif [ -n "$BASH_VERSION" ]; then
_shell_ext="bash"
elif [ -n "$FISH_VERSION" ]; then
_shell_ext="fish"
elif [ -n "$tcsh" ]; then
_shell_ext="tcsh"
fi
if [ -n "$_shell_ext" ]; then
_script_path=""
if [ -r "$HOME/.iterm2_shell_integration.$_shell_ext" ]; then
_script_path="$HOME/.iterm2_shell_integration.$_shell_ext"
elif [ -r "$_iterm_app/Contents/Resources/iterm2_shell_integration.$_shell_ext" ]; then
_script_path="$_iterm_app/Contents/Resources/iterm2_shell_integration.$_shell_ext"
fi
if [ -n "$_script_path" ]; then
\. "$_script_path"
fi
fi
fi fi
} }
unset -f anon _setup_iterm2
unset -f _setup_iterm2

View File

@@ -1,18 +1,159 @@
# TODO: Use find to get subdirs. Filter by vendor. Filter by version. Find the "best" version/vendor combo. # Setup Java environment (JAVA_HOME, JDK_HOME, and PATH)
# Highest microsoft version, if not fallback to highest non-ms version _setup_java() {
# Brew has graalvm (17,21), microsoft (11,17,21), oracle(17,21), sapmachine, semeru (8,11,17,21) [ -n "$ZSH_VERSION" ] && setopt localoptions nonomatch nullglob
if [ -z "${JAVA_HOME}" -a -d "/Library/Java/JavaVirtualMachines/microsoft-21.jdk/Contents/Home" ]; then
JAVA_HOME=/Library/Java/JavaVirtualMachines/microsoft-21.jdk/Contents/Home
elif [ -z "${JAVA_HOME}" -a -d "/Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home" ]; then
JAVA_HOME=/Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home
elif [ -z "${JAVA_HOME}" -a -d "/Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home" ]; then
JAVA_HOME=/Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home
elif [ -z "${JAVA_HOME}" -a -d "/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home" ]; then
JAVA_HOME=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home
fi
if [ -n "$JAVA_HOME" ]; then _is_valid_jre() {
path=("$JAVA_HOME/bin" $path) [ -n "$1" ] && [ -d "$1" ] && [ -x "$1/bin/java" ]
export JAVA_HOME }
export PATH
fi _is_valid_jdk() {
_is_valid_jre "$1" && [ -x "$1/bin/javac" ]
}
_add_to_path() {
[ -d "$1" ] || return 0
case ":$PATH:" in
*":$1:"*) ;;
*) PATH="$1:$PATH"; export PATH ;;
esac
}
# 1. If user already has a valid JAVA_HOME configured, respect it
_has_user_jre=0
if _is_valid_jre "${JAVA_HOME:-}"; then
_has_user_jre=1
_add_to_path "$JAVA_HOME/bin"
if _is_valid_jdk "$JAVA_HOME"; then
[ -z "$JDK_HOME" ] && export JDK_HOME="$JAVA_HOME"
fi
fi
# If both a valid JRE (JAVA_HOME) and JDK (JDK_HOME) are already configured, we are done
if [ "$_has_user_jre" -eq 1 ] && [ -n "$JDK_HOME" ] && _is_valid_jdk "$JDK_HOME"; then
return 0
fi
# 2. Gather candidates across macOS and Linux
_candidates=()
# macOS tool: /usr/libexec/java_home
if [ "$(uname -s 2>/dev/null)" = "Darwin" ] && [ -x "/usr/libexec/java_home" ]; then
_jh=$(/usr/libexec/java_home 2>/dev/null)
[ -n "$_jh" ] && _candidates+=("$_jh")
fi
# Linux tools: update-java-alternatives (Debian/Ubuntu) and readlink on java command
if command -v update-java-alternatives >/dev/null 2>&1; then
for _alt_path in $(update-java-alternatives -l 2>/dev/null | awk '{print $NF}'); do
[ -d "$_alt_path" ] && _candidates+=("$_alt_path")
done
fi
if command -v java >/dev/null 2>&1; then
_java_bin=$(command -v java 2>/dev/null)
if command -v readlink >/dev/null 2>&1; then
_real_java=$(readlink -f "$_java_bin" 2>/dev/null)
if [ -n "$_real_java" ] && [ -x "$_real_java" ]; then
_alt_home="$(dirname "$(dirname "$_real_java")")"
[ -n "$_alt_home" ] && _candidates+=("$_alt_home")
fi
fi
fi
# Cross-platform user managers (SDKMAN)
[ -d "$HOME/.sdkman/candidates/java/current" ] && _candidates+=("$HOME/.sdkman/candidates/java/current")
# macOS locations
if [ "$(uname -s 2>/dev/null)" = "Darwin" ]; then
# Homebrew OpenJDK
for _d in /opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home \
/opt/homebrew/opt/openjdk@*/libexec/openjdk.jdk/Contents/Home \
/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home; do
[ -d "$_d" ] && _candidates+=("$_d")
done
# Installed JVMs in /Library/Java/JavaVirtualMachines and ~/Library/...
# Version-sorted descending to prefer newer releases
for _d in $(
for _jvm in /Library/Java/JavaVirtualMachines/*/Contents/Home \
"$HOME/Library/Java/JavaVirtualMachines"/*/Contents/Home; do
[ -d "$_jvm" ] && echo "$_jvm"
done | sort -V -r 2>/dev/null
); do
_candidates+=("$_d")
done
# Android Studio bundled JBR/JDK
for _d in \
"/Applications/Android Studio.app/Contents/jbr/Contents/Home" \
"/Applications/Android Studio.app/Contents/jre/Contents/Home" \
"/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home" \
"$HOME/Applications/Android Studio.app/Contents/jbr/Contents/Home" \
"$HOME/Applications/Android Studio.app/Contents/jre/Contents/Home"
do
[ -d "$_d" ] && _candidates+=("$_d")
done
fi
# Linux / WSL locations
if [ "$(uname -s 2>/dev/null)" = "Linux" ]; then
# Default java symlink on Debian/Ubuntu
[ -d "/usr/lib/jvm/default-java" ] && _candidates+=("/usr/lib/jvm/default-java")
# Distribution JVMs in /usr/lib/jvm, version-sorted descending
for _d in $(
for _jvm in /usr/lib/jvm/*; do
[ -d "$_jvm" ] && echo "$_jvm"
done | sort -V -r 2>/dev/null
); do
_candidates+=("$_d")
done
for _d in \
"/usr/java/latest" \
"/usr/java/default" \
"/opt/android-studio/jbr" \
"/opt/android-studio/jre" \
"$HOME/android-studio/jbr" \
"$HOME/.local/share/JetBrains/Toolbox/apps/android-studio/jbr"
do
[ -d "$_d" ] && _candidates+=("$_d")
done
fi
# 3. Evaluate candidates: find best JRE (preferring SDK JREs) and best JDK
_best_jdk=""
_best_jre=""
for _cand in "${_candidates[@]}"; do
if [ -n "$_cand" ]; then
if _is_valid_jdk "$_cand"; then
[ -z "$_best_jdk" ] && _best_jdk="$_cand"
[ -z "$_best_jre" ] && _best_jre="$_cand"
elif _is_valid_jre "$_cand"; then
[ -z "$_best_jre" ] && _best_jre="$_cand"
fi
if [ -n "$_best_jdk" ] && [ -n "$_best_jre" ]; then
break
fi
fi
done
# 4. If no valid JAVA_HOME was set by user, configure it with best JRE (preferring SDK)
if [ "$_has_user_jre" -eq 0 ] && [ -n "$_best_jre" ]; then
export JAVA_HOME="$_best_jre"
_add_to_path "$JAVA_HOME/bin"
fi
# 5. If no SDK/JDK_HOME is set, configure it with best JDK
if [ -z "$JDK_HOME" ] || ! _is_valid_jdk "$JDK_HOME"; then
if _is_valid_jdk "${JAVA_HOME:-}"; then
export JDK_HOME="$JAVA_HOME"
elif [ -n "$_best_jdk" ]; then
export JDK_HOME="$_best_jdk"
_add_to_path "$_best_jdk/bin"
fi
fi
}
_setup_java
unset -f _setup_java _is_valid_jre _is_valid_jdk _add_to_path

View File

@@ -1,5 +1,6 @@
# zsh # See ls-color.md for an explanation of the formats.
export LSCOLORS=FxGxedGdCxxExFHBDBbcbd if [ -n "$BASH_VERSION" ]; then
export LS_COLORS="rs=0:di=95:ln=36:mh=00:pi=96;43:so=34;43:do=34;43:bd=104:cd=105:or=5;96;40:mi=5;30;46:su=97;101:sg=93;101:ca=00:tw=91;42:ow=91;43:st=42:ex=92:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.crdownload=00;90:*.dpkg-dist=00;90:*.dpkg-new=00;90:*.dpkg-old=00;90:*.dpkg-tmp=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:*.swp=00;90:*.tmp=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:"
# bash elif [ -n "$ZSH_VERSION" ]; then
export LS_COLORS="rs=0:di=95:ln=36:mh=00:pi=96;43:so=34;43:do=34;43:bd=104:cd=105:or=5;96;40:mi=5;30;46:su=97;101:sg=93;101:ca=00:tw=91;42:ow=91;43:st=42:ex=92:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.crdownload=00;90:*.dpkg-dist=00;90:*.dpkg-new=00;90:*.dpkg-old=00;90:*.dpkg-tmp=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:*.swp=00;90:*.tmp=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:" export LSCOLORS=FxGxedGdCxxExFHBDBbcbd
fi

92
.rc.d/node.sh Normal file
View File

@@ -0,0 +1,92 @@
# Setup Node.js environment: NVM (preferred), system/fallback Node, NPM global bin, and Yarn
_setup_node() {
_add_to_path() {
[ -d "$1" ] || return 0
case ":$PATH:" in
*":$1:"*) ;;
*) PATH="$1:$PATH"; export PATH ;;
esac
}
_nvm_active=0
# 1. Check for NVM and prefer NVM node version
if [ -z "$NVM_DIR" ]; then
if [ -d "$HOME/.nvm" ]; then
export NVM_DIR="$HOME/.nvm"
elif [ -d "${XDG_CONFIG_HOME:-$HOME/.config}/nvm" ]; then
export NVM_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/nvm"
elif [ -d "/opt/homebrew/opt/nvm" ]; then
export NVM_DIR="/opt/homebrew/opt/nvm"
fi
fi
if [ -n "$NVM_DIR" ] && [ -d "$NVM_DIR" ]; then
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
if command -v nvm >/dev/null 2>&1 || type nvm >/dev/null 2>&1; then
nvm use --silent 2>/dev/null || nvm use --silent default 2>/dev/null || nvm use --silent node 2>/dev/null
fi
if [ -n "$NVM_BIN" ] && [ -d "$NVM_BIN" ]; then
_nvm_active=1
fi
fi
# 2. If NVM is not available or has no active node, fallback to system/global node installs
if [ "$_nvm_active" -eq 0 ]; then
if ! command -v node >/dev/null 2>&1; then
for _node_dir in \
/opt/homebrew/opt/node/bin \
/opt/homebrew/bin \
/usr/local/bin \
/usr/bin \
/usr/local/nodejs/bin \
/usr/local/node/bin \
"$HOME/.local/bin"
do
if [ -x "$_node_dir/node" ]; then
_add_to_path "$_node_dir"
break
fi
done
fi
fi
# 3. Setup NPM global binaries (for system node or custom npm prefix)
if [ "$_nvm_active" -eq 0 ] && command -v npm >/dev/null 2>&1; then
_npm_prefix="$(npm config get prefix 2>/dev/null || npm prefix -g 2>/dev/null)"
if [ -n "$_npm_prefix" ] && [ -d "$_npm_prefix/bin" ]; then
_add_to_path "$_npm_prefix/bin"
fi
unset _npm_prefix
elif [ -d "$HOME/.npm-global/bin" ]; then
_add_to_path "$HOME/.npm-global/bin"
fi
# 4. Setup Yarn global bin if yarn is available
if command -v yarn >/dev/null 2>&1; then
_yarn_bin="$(yarn global bin 2>/dev/null)"
if [ -n "$_yarn_bin" ] && [ -d "$_yarn_bin" ]; then
_add_to_path "$_yarn_bin"
fi
unset _yarn_bin
fi
# 5. Guarantee NVM active node takes precedence over any global node in PATH
if [ "$_nvm_active" -eq 1 ] && [ -n "$NVM_BIN" ] && [ -d "$NVM_BIN" ]; then
_clean_path=":$PATH:"
_clean_path="${_clean_path//:$NVM_BIN:/:}"
_clean_path="${_clean_path#:}"
_clean_path="${_clean_path%:}"
PATH="$NVM_BIN:$_clean_path"
export PATH
unset _clean_path
fi
unset _nvm_active
}
_setup_node
unset -f _setup_node _add_to_path

View File

@@ -1,11 +0,0 @@
function anon() {
local nvm_dir="$HOME/.nvm"
if [ -d $nvm_dir ]; then
[ -s $nvm_dir/nvm.sh ] && \. $nvm_dir/nvm.sh # This loads nvm
[ -s $nvm_dir/bash_completion ] && \. $nvm_dir/bash_completion # This loads nvm bash_completion
export NVM_DIR=$nvm_dir
fi
unset -f anon
}
anon

48
.rc.d/pkgconfig.sh Normal file
View File

@@ -0,0 +1,48 @@
# Setup PKG_CONFIG_PATH for Apple Silicon Homebrew on macOS and LSB/standard paths on Linux
_setup_pkgconfig() {
[ -n "$ZSH_VERSION" ] && setopt localoptions nonomatch nullglob
_add_pkg_config_path() {
[ -d "$1" ] || return 0
case ":${PKG_CONFIG_PATH}:" in
*":$1:"*) ;;
*)
if [ -n "$PKG_CONFIG_PATH" ]; then
PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:$1"
else
PKG_CONFIG_PATH="$1"
fi
;;
esac
}
# macOS: Apple Silicon Homebrew
if [ -d "/opt/homebrew" ]; then
_add_pkg_config_path "/opt/homebrew/lib/pkgconfig"
_add_pkg_config_path "/opt/homebrew/share/pkgconfig"
for _dir in /opt/homebrew/opt/*/lib/pkgconfig \
/opt/homebrew/opt/*/share/pkgconfig; do
_add_pkg_config_path "$_dir"
done
fi
# Linux (apt / rpm / LSB / manual build & install paths) and user paths
for _dir in \
"$HOME/.local/lib/pkgconfig" \
"$HOME/.local/share/pkgconfig" \
/usr/local/lib/pkgconfig \
/usr/local/lib64/pkgconfig \
/usr/local/share/pkgconfig \
/usr/lib/pkgconfig \
/usr/lib64/pkgconfig \
/usr/share/pkgconfig \
/usr/lib/*-linux-gnu*/pkgconfig \
/usr/local/lib/*-linux-gnu*/pkgconfig
do
_add_pkg_config_path "$_dir"
done
export PKG_CONFIG_PATH
}
_setup_pkgconfig
unset -f _setup_pkgconfig _add_pkg_config_path

View File

@@ -1,7 +0,0 @@
# TODO: Find a way to make this automatic so pkgconfig works for anything installed via homebrew.
# See java.sh for details, but we can enumerate folders under /opt/homebrew/Cellar/*/*/lib/pkgconfig and add them all.
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/homebrew/Cellar/libpng/1.6.40/lib/pkgconfig
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/homebrew/Cellar/zlib/1.3/lib/pkgconfig
# PKG_CONFIG_PATH=$PKG_CONFIG_PATH:
export PKG_CONFIG_PATH

View File

@@ -1,6 +1,100 @@
# Ruby # Setup Ruby environment: version managers (rbenv, chruby, rvm), Homebrew Ruby, and gem bin paths
if [[ $(command -v rbenv) ]]; then _setup_ruby() {
eval "$(rbenv init -)" [ -n "$ZSH_VERSION" ] && setopt localoptions nonomatch nullglob
export PATH="$HOME/.gem/ruby/3.0.0/bin:$PATH"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)" _add_to_path() {
fi [ -d "$1" ] || return 0
case ":$PATH:" in
*":$1:"*) ;;
*) PATH="$1:$PATH"; export PATH ;;
esac
}
_ruby_manager_active=0
# 1. Check for rbenv (prefer managed Ruby)
if [ -d "$HOME/.rbenv/bin" ]; then
_add_to_path "$HOME/.rbenv/bin"
fi
if command -v rbenv >/dev/null 2>&1; then
eval "$(rbenv init - 2>/dev/null)"
_ruby_manager_active=1
# Fast OpenSSL detection for ruby-build without calling slow `brew --prefix`
if [ -z "$RUBY_CONFIGURE_OPTS" ]; then
for _ssl_dir in \
"/opt/homebrew/opt/openssl@3" \
"/opt/homebrew/opt/openssl@1.1" \
"/usr/local/opt/openssl@3" \
"/usr/local/opt/openssl@1.1"
do
if [ -d "$_ssl_dir" ]; then
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$_ssl_dir"
break
fi
done
fi
fi
# 2. Check for chruby
if [ "$_ruby_manager_active" -eq 0 ]; then
for _chruby_sh in \
"/opt/homebrew/opt/chruby/share/chruby/chruby.sh" \
"/usr/local/share/chruby/chruby.sh" \
"/usr/share/chruby/chruby.sh"
do
if [ -r "$_chruby_sh" ]; then
\. "$_chruby_sh"
[ -r "${_chruby_sh%/*}/auto.sh" ] && \. "${_chruby_sh%/*}/auto.sh"
_ruby_manager_active=1
break
fi
done
fi
# 3. Check for RVM
if [ "$_ruby_manager_active" -eq 0 ]; then
if [ -s "$HOME/.rvm/scripts/rvm" ]; then
\. "$HOME/.rvm/scripts/rvm"
_ruby_manager_active=1
fi
fi
# 4. If no version manager is active, fallback to Homebrew keg-only Ruby or standard locations
# (Avoids Apple's deprecated /usr/bin/ruby on macOS when Homebrew Ruby is installed)
if [ "$_ruby_manager_active" -eq 0 ]; then
for _brew_ruby in $(
for _r in /opt/homebrew/opt/ruby/bin \
/opt/homebrew/opt/ruby@*/bin \
/usr/local/opt/ruby/bin \
/usr/local/opt/ruby@*/bin; do
[ -x "$_r/ruby" ] && echo "$_r"
done | sort -V -r 2>/dev/null
); do
_add_to_path "$_brew_ruby"
break
done
fi
# 5. Add user gem binaries to PATH (dynamically resolved, not hardcoded to a fixed version)
if command -v ruby >/dev/null 2>&1; then
_gem_user_bin="$(ruby -e 'puts Gem.user_dir' 2>/dev/null)/bin"
if [ -n "$_gem_user_bin" ] && [ -d "$_gem_user_bin" ]; then
_add_to_path "$_gem_user_bin"
fi
unset _gem_user_bin
for _gbin in $(
for _gd in "$HOME/.gem/ruby"/*/bin "$HOME/.local/share/gem/ruby"/*/bin; do
[ -d "$_gd" ] && echo "$_gd"
done | sort -V -r 2>/dev/null
); do
_add_to_path "$_gbin"
break
done
fi
unset _ruby_manager_active
}
_setup_ruby
unset -f _setup_ruby _add_to_path

75
.rc.d/rust.sh Executable file
View File

@@ -0,0 +1,75 @@
# Setup Rust / Cargo environment, tools, and shell completions
_setup_cargo() {
[ -n "$ZSH_VERSION" ] && setopt localoptions nonomatch nullglob
_add_to_path() {
[ -d "$1" ] || return 0
case ":$PATH:" in
*":$1:"*) ;;
*) PATH="$1:$PATH"; export PATH ;;
esac
}
# 1. Respect or detect CARGO_HOME and RUSTUP_HOME
if [ -z "$CARGO_HOME" ] && [ -d "$HOME/.cargo" ]; then
export CARGO_HOME="$HOME/.cargo"
fi
if [ -z "$RUSTUP_HOME" ] && [ -d "$HOME/.rustup" ]; then
export RUSTUP_HOME="$HOME/.rustup"
fi
_cargo_dir="${CARGO_HOME:-$HOME/.cargo}"
# 2. Source official env file if present, or add bin directory to PATH
if [ -f "$_cargo_dir/env" ]; then
\. "$_cargo_dir/env"
elif [ -d "$_cargo_dir/bin" ]; then
_add_to_path "$_cargo_dir/bin"
fi
# 3. Fallback search for system or alternative Cargo/Rust locations if not in PATH
if ! command -v cargo >/dev/null 2>&1; then
for _cand in \
"/usr/local/cargo/bin" \
"/opt/homebrew/opt/rust/bin" \
"/usr/local/opt/rust/bin" \
"/opt/homebrew/bin" \
"/usr/local/bin" \
"$HOME/.local/bin"
do
if [ -x "$_cand/cargo" ]; then
_add_to_path "$_cand"
break
fi
done
fi
# 4. Enable shell completions if available and files are present
if command -v cargo >/dev/null 2>&1; then
_rustup_dir="${RUSTUP_HOME:-$HOME/.rustup}"
if [ -n "$BASH_VERSION" ]; then
for _comp in \
"$_rustup_dir"/toolchains/*/etc/bash_completion.d/cargo \
"$_rustup_dir"/toolchains/*/etc/bash_completion.d/rustup \
"/opt/homebrew/etc/bash_completion.d/cargo" \
"/usr/share/bash-completion/completions/cargo"
do
if [ -r "$_comp" ]; then
\. "$_comp"
fi
done
elif [ -n "$ZSH_VERSION" ]; then
for _zsh_comp_dir in "$_rustup_dir"/toolchains/*/share/zsh/site-functions; do
if [ -d "$_zsh_comp_dir" ]; then
case " ${fpath[*]} " in
*" $_zsh_comp_dir "*) ;;
*) fpath=("$_zsh_comp_dir" "${fpath[@]}") ;;
esac
fi
done
fi
fi
}
_setup_cargo
unset -f _setup_cargo _add_to_path

55
.rc.d/yt-dlp.sh Normal file
View File

@@ -0,0 +1,55 @@
# Define yt-dlp functions with dynamic JavaScript runtime (Node.js) detection
yt-dlp() {
local _cmd="yt-dlp"
if ! command -v yt-dlp >/dev/null 2>&1; then
if [ -x "/opt/homebrew/bin/yt-dlp" ]; then
_cmd="/opt/homebrew/bin/yt-dlp"
elif [ -x "/usr/local/bin/yt-dlp" ]; then
_cmd="/usr/local/bin/yt-dlp"
elif [ -x "$HOME/.local/bin/yt-dlp" ]; then
_cmd="$HOME/.local/bin/yt-dlp"
else
echo "yt-dlp: command not found" >&2
return 127
fi
fi
if command -v node >/dev/null 2>&1; then
command $_cmd --js-runtimes "node:$(command -v node)" "$@"
else
command $_cmd "$@"
fi
}
yt-dlp-best() {
yt-dlp -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]" "$@"
}
yt-dlp-audio-meta() {
yt-dlp \
-f "ba[ext=m4a]/ba" \
-x --audio-format m4a \
--embed-metadata --embed-thumbnail \
"$@"
}
yt-dlp-formats() {
yt-dlp -F "$@"
}
yt-dlp-playlist-audio() {
yt-dlp \
--yes-playlist \
--embed-metadata --embed-thumbnail \
-f "ba[ext=m4a]/ba" \
-o "%(playlist_title,playlist_id)s/%(playlist_index)03d - %(title)s.%(ext)s" \
"$@"
}
yt-dlp-playlist() {
yt-dlp \
--yes-playlist \
--embed-metadata --embed-thumbnail \
-o "%(playlist_title,playlist_id)s/%(playlist_index)03d - %(title)s.%(ext)s" \
"$@"
}

View File

@@ -1,12 +1,36 @@
# TODO: Check if zoxide_path exists. # Setup zoxide (smarter cd command) for interactive shells (bash and zsh)
# TODO: Check shell better. _setup_zoxide() {
# -n $zoxide_path -a -n $zoxide_path # Only run in interactive shells
function anon() { case $- in
zoxide_path=$(which zoxide) *i*) ;;
if [ -n $zoxide_path -a $zoxide_path != "zoxide not found" ]; then *) return 0 ;;
if [ "$SHELL" = "/bin/zsh" ]; then esac
eval "$(zoxide init --cmd cd zsh)"
# Ensure zoxide binary is accessible if installed in common locations
if ! command -v zoxide >/dev/null 2>&1; then
for _zoxide_bin_dir in \
"/opt/homebrew/bin" \
"/usr/local/bin" \
"$HOME/.local/bin" \
"$HOME/bin"
do
if [ -x "$_zoxide_bin_dir/zoxide" ]; then
case ":$PATH:" in
*":$_zoxide_bin_dir:"*) ;;
*) PATH="$_zoxide_bin_dir:$PATH"; export PATH ;;
esac
break
fi fi
done
fi
command -v zoxide >/dev/null 2>&1 || return 0
if [ -n "$ZSH_VERSION" ]; then
eval "$(zoxide init --cmd cd zsh)"
elif [ -n "$BASH_VERSION" ]; then
eval "$(zoxide init --cmd cd bash)"
fi fi
} }
unset -f anon _setup_zoxide
unset -f _setup_zoxide

View File

@@ -1,10 +0,0 @@
if type brew &>/dev/null; then
fpath=( $(brew --prefix)/share/zsh-completions "${fpath[@]}" )
fi
# If you receive "zsh compinit: insecure directories" warnings when attempting
# to load these completions, you may need to run these commands:
# chmod go-w '/opt/homebrew/share'
# chmod -R go-w '/opt/homebrew/share/zsh'
# compinit will load and run after this in .zshrc

70
.rc.d/zz-completions.sh Normal file
View File

@@ -0,0 +1,70 @@
# Setup shell completions for Bash and Zsh
# Named with 'zz-' prefix to guarantee late execution after all PATH and tool
# additions in ~/.rc.d/*.sh have completed.
_setup_completions() {
# Only initialize completions for interactive shells
case $- in
*i*) ;;
*) return 0 ;;
esac
# -------------------------------------------------------------------------
# ZSH Autocompletion Setup
# -------------------------------------------------------------------------
if [ -n "$ZSH_VERSION" ]; then
# Candidate completion directories
for _dir in \
"/opt/homebrew/share/zsh-completions" \
"/usr/local/share/zsh-completions" \
"/usr/share/zsh-completions" \
"/opt/homebrew/share/zsh/site-functions" \
"/usr/local/share/zsh/site-functions" \
"$HOME/.zsh_functions"
do
if [ -d "$_dir" ]; then
case " ${fpath[*]} " in
*" $_dir "*) ;;
*) fpath=("$_dir" "${fpath[@]}") ;;
esac
fi
done
# If you receive "zsh compinit: insecure directories" warnings, run:
# chmod go-w '/opt/homebrew/share'
# chmod -R go-w '/opt/homebrew/share/zsh'
# Initialize compinit with 24-hour cache check for fast startup (~2ms)
autoload -Uz compinit
_zcompdump="${ZDOTDIR:-$HOME}/.zcompdump"
if [ -n "$(find "$_zcompdump" -mtime -1 2>/dev/null)" ]; then
compinit -C -d "$_zcompdump"
else
compinit -d "$_zcompdump"
fi
unset _zcompdump _dir
# -------------------------------------------------------------------------
# Bash Autocompletion Setup
# -------------------------------------------------------------------------
elif [ -n "$BASH_VERSION" ]; then
if ! shopt -oq posix; then
for _comp in \
"/opt/homebrew/etc/profile.d/bash_completion.sh" \
"/usr/local/etc/profile.d/bash_completion.sh" \
"/usr/share/bash-completion/bash_completion" \
"/etc/bash_completion" \
"$HOME/.local/share/bash-completion/bash_completion"
do
if [ -r "$_comp" ]; then
\. "$_comp"
break
fi
done
unset _comp
fi
fi
}
_setup_completions
unset -f _setup_completions

View File

@@ -2,4 +2,4 @@
# yarn lockfile v1 # yarn lockfile v1
lastUpdateCheck 1768790207834 lastUpdateCheck 1726638947230

View File

@@ -14,21 +14,5 @@
# ~/.zlogin # ~/.zlogin
##fi ##fi
# set PATH so it includes user's private bin if it exists # Hermes Agent — ensure ~/.local/bin is on PATH
if [ -d "$HOME/bin" ] ; then export PATH="$HOME/.local/bin:$PATH"
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
## ZSH version of this
# # if running bash
# if [ -n "$BASH_VERSION" ]; then
# # include .bashrc if it exists
# if [ -f "$HOME/.bashrc" ]; then
# . "$HOME/.bashrc"
# fi
# fi

48
.zshrc
View File

@@ -1,4 +1,30 @@
# Consider moving these to a script in .rc.d if they don't need to be before the other scripts in there. # Consider moving these to a script in .rc.d if they don't need to be before the other scripts in there.
# If Apple Silicon Homebrew is installed activate it.
if [ -x "/usr/local/homebrew/bin/brew" ]; then
eval "$(/usr/local/homebrew/bin/brew shellenv)"
# If x86_64 Homebrew is installed alias it to brew86.
if [ -x "/opt/homebrew/bin/brew" ]; then
alias brew86='arch -x86_64 /usr/local/homebrew/bin/brew'
fi
fi
# If x86_64 Homebrew is installed activate it.
if [ -x "/opt/homebrew/bin/brew" ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
# If Apple Silicon Homebrew is installed alias it to brewarm.
if [ -x "/usr/local/homebrew/bin/brew" ]; then
alias brewarm='arch -arm64 /opt/homebrew/bin/brew'
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
# Activate ZSH autocompletion. # Activate ZSH autocompletion.
autoload -Uz compinit autoload -Uz compinit
@@ -17,30 +43,16 @@ fpath=( ~/.zsh_functions "${fpath[@]}" )
setopt HIST_IGNORE_SPACE setopt HIST_IGNORE_SPACE
setopt HIST_IGNORE_DUPS setopt HIST_IGNORE_DUPS
setopt INC_APPEND_HISTORY setopt INC_APPEND_HISTORY
setopt histignorealldups sharehistory
HISTSIZE=1000 HISTSIZE=1000
SAVEHIST=10000 SAVEHIST=10000
# TODO: Look for an equivalent for `shopt -s checkwinsize` # TODO: Look for an equivalent for `shopt -s checkwinsize`
# I don't even remember what it does, but I think it's bash specific. # I don't even remember what it does, but I think it's bash specific.
# zstyle ':completion:*' auto-description 'specify: %d' # Added by cua-driver-rs installer — see https://github.com/trycua/cua
# zstyle ':completion:*' completer _expand _complete _correct _approximate export PATH="/Users/tom/.local/bin:$PATH"
# zstyle ':completion:*' format 'Completing %d'
# zstyle ':completion:*' group-name ''
# zstyle ':completion:*' menu select=2
# eval "$(dircolors -b)"
# zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
# zstyle ':completion:*' list-colors ''
# zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
# zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
# zstyle ':completion:*' menu select=long
# zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
# zstyle ':completion:*' use-compctl false
# zstyle ':completion:*' verbose true
# zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' # Added by cua-driver-rs installer — see https://github.com/trycua/cua
# zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' export PATH="/Users/tom/.local/bin:$PATH"
# Initialize profile environment
[ -f "$HOME/.init_profile" ] && . "$HOME/.init_profile" [ -f "$HOME/.init_profile" ] && . "$HOME/.init_profile"