Fixes zoxide and compoletions.
This commit is contained in:
@@ -1,9 +1,16 @@
|
|||||||
# Display fortune (with cowsay if available) in interactive shells
|
# Display fortune (with cowsay if available) in top-level interactive shells
|
||||||
|
# (new iTerm2 tabs/windows, xterm, console, VS Code / IntelliJ terminals).
|
||||||
|
# Subshells (e.g. typing 'bash' or 'zsh' inside an existing terminal) are skipped.
|
||||||
case $- in
|
case $- in
|
||||||
*i*) ;;
|
*i*) ;;
|
||||||
*) return 0 2>/dev/null || exit 0 ;;
|
*) return 0 2>/dev/null || exit 0 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Skip nested subshells (SHLVL > 1)
|
||||||
|
if [ "${SHLVL:-1}" -gt 1 ]; then
|
||||||
|
return 0 2>/dev/null || exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
_fortune_cmd=""
|
_fortune_cmd=""
|
||||||
if command -v fortune >/dev/null 2>&1; then
|
if command -v fortune >/dev/null 2>&1; then
|
||||||
_fortune_cmd="fortune"
|
_fortune_cmd="fortune"
|
||||||
|
|||||||
@@ -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
|
||||||
|
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
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
unset -f anon
|
_setup_zoxide
|
||||||
|
unset -f _setup_zoxide
|
||||||
|
|||||||
@@ -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
70
.rc.d/zz-completions.sh
Normal 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
|
||||||
|
|
||||||
Reference in New Issue
Block a user