wting / autojump

A cd command that learns - easily navigate directories from the command line
Other
16.06k stars 702 forks source link

-bash: PROMPT_COMMAND: readonly variable #687

Open SmallPineApp1e opened 9 months ago

SmallPineApp1e commented 9 months ago

When I installed autojump by git clone xxx && install.py, I added that code in my ~/.bashrc and source it

[[ -s /home/zengzhijie/.autojump/etc/profile.d/autojump.sh ]] && source /home/zengzhijie/.autojump/etc/profile.d/autojump.sh

but it reminded me "-bash: PROMPT_COMMAND: readonly variable", and autojump didn't work, can someone help me? :(

justsz commented 2 months ago

See what you get if you do echo $PROMPT_COMMAND. In my case it showed that USER_PROMPT_COMMAND is run at the end of PROMPT_COMMAND. I then edited ~/.autojump/share/autojump/autojum.bash (change as appropriate if your shell isn't bash) to replace the line

PROMPT_COMMAND="${PROMPT_COMMAND:+$(echo "${PROMPT_COMMAND}" | awk '{gsub(/; *$/,"")}1') ; }autojump_add_to_database"

with

USER_PROMPT_COMMAND="${USER_PROMPT_COMMAND:+$(echo "${USER_PROMPT_COMMAND}" | awk '{gsub(/; *$/,"")}1') ; }autojump_add_to_database"

. That got autojump working for me.