Skip to content

possible configuration issue when using PROMPT_COMMAND as an array #987

Closed
@aarondill

Description

@aarondill

having recently updated zoxide, i receive a warning about a possible configuration issue.
Having seen the other issues, I assume this is due to the expansion of "$PROMPT_COMMAND" not including the zoxide hook.
In my case, this is not a misconfiguration. As I intentionally override PROMPT_COMMAND to be an array.
My initialization code (note that I've modularized my .bashrc:

# if `z` is installed, initiate it and set `cd` to `z`
if ! zoxide -V &>/dev/null; then return 0; fi

# HACK: Zoxide overwrites the PROMPT_COMMAND, so we must move it out of it's view, and restore it afterwards
OLD_PROMPT_COMMAND=("${PROMPT_COMMAND[@]}")
PROMPT_COMMAND="" # only overwrites PROMPT_COMMAND[0], but it doesn't matter

export _ZO_ECHO=0 # Fixes warning if set -u
eval "$(zoxide init bash)"

PROMPT_COMMAND=("$PROMPT_COMMAND" "${OLD_PROMPT_COMMAND[@]}") # prepend, since it's trying to prepend anyways
unset OLD_PROMPT_COMMAND

# Reuse cd completion if present (overwritten already), else default to directories
complete=$(complete -p cd 2>/dev/null || printf '%s ' complete -d cd)
# remove ' cd' and replace with ' z'. Lack of quotes is intentional!
if [ -n "$complete" ]; then
  eval "${complete% cd} z"
fi
alias cd='z'

I'd like to request that the _ZO_DOCTOR prompt checks that any element of ${PROMPT_COMMAND[@]} is the __zoxide_hook
Note:

> printf '%s\n' "${PROMPT_COMMAND[@]}"
__EXIT=$?
__zoxide_hook;
starship_precmd
history -a
(exit $__EXIT)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions