Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Conflict with hstr application when set sdkman_auto_env=true #1087

Closed
speedlog opened this issue Apr 16, 2022 · 9 comments
Closed

Bug: Conflict with hstr application when set sdkman_auto_env=true #1087

speedlog opened this issue Apr 16, 2022 · 9 comments

Comments

@speedlog
Copy link
Contributor

speedlog commented Apr 16, 2022

Bug report
When i have installed hstr (https://github.com/dvorka/hstr) and sdkman with sdkman_auto_env=true

Every command i get message "bash: PROMPT_COMMAND: line X: `history -a; history -n; ;sdkman_auto_env'"

hstr version "2.3.0" (2020-11-19T07:41:00)

bash: PROMPT_COMMAND: line 0: syntax error near unexpected token `;'
bash: PROMPT_COMMAND: line 0: `history -a; history -n; ;sdkman_auto_env'

user:~/Downloads/test-sdk-env/car-app$ java -version
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
bash: PROMPT_COMMAND: line 1: syntax error near unexpected token `;'
bash: PROMPT_COMMAND: line 1: `history -a; history -n; ;sdkman_auto_env'

user:~/Downloads/test-sdk-env/car-app$ cd ..
bash: PROMPT_COMMAND: line 2: syntax error near unexpected token `;'
bash: PROMPT_COMMAND: line 2: `history -a; history -n; ;sdkman_auto_env'

There is a resolution.
Despite of warning comment ("THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!") i need to set hstr fragment in .bashrc after sdkman fragment.
Something like that:

#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="/home/user/.sdkman"
[[ -s "/home/user/.sdkman/bin/sdkman-init.sh" ]] && source "/home/user/.sdkman/bin/sdkman-init.sh"

# HSTR configuration - add this to ~/.bashrc
alias hh=hstr                    # hh to be alias for hstr
export HSTR_CONFIG=hicolor       # get more colors
shopt -s histappend              # append new history items to .bash_history
export HISTCONTROL=ignorespace   # leading space hides commands from history
export HISTFILESIZE=10000        # increase history file size (default is 500)
export HISTSIZE=${HISTFILESIZE}  # increase history size (default is 500)
# ensure synchronization between bash memory and history file
export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}"
# if this is interactive shell, then bind hstr to Ctrl-r (for Vi mode check doc)
if [[ $- =~ .*i.* ]]; then bind '"\C-r": "\C-a hstr -- \C-j"'; fi
# if this is interactive shell, then bind 'kill last command' to Ctrl-x k
if [[ $- =~ .*i.* ]]; then bind '"\C-xk": "\C-a hstr -k \C-j"'; fi

To reproduce

  1. Install https://github.com/dvorka/hstr
  2. Add config for hstr hstr --show-configuration >> ~/.bashrc
  3. Install sdkman
  4. Set sdkman_auto_env=true

System info

Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal

GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)

SDKMAN 5.15.0

hstr version "2.3.0" (2020-11-19T07:41:00)

@speedlog speedlog added the bug label Apr 16, 2022
@marc0der
Copy link
Member

Hi @speedlog, I don't think this is a bug but rather an incompatibility between the two tools. Not sure if there is much we can do about this.

@marc0der marc0der removed the bug label Apr 16, 2022
@speedlog
Copy link
Contributor Author

I agree, but maybe warning comment "THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!" is unnecessary?
When i changed order in .bashrc sdkman still works :)

@marc0der
Copy link
Member

marc0der commented Apr 16, 2022

For the vast majority of our users, this statement/comment is valid. SDKMAN rewrites the PATH variable, and it should be done at the very latest point possible in the shell initialisation process. I don't think I want to change it any time soon.

@speedlog
Copy link
Contributor Author

Thanks for explanation. I tried to figure out why SDKMAN should be in the end of file.

I dig a little and found cause of this problem.
It's more general than conflict with hstr.
When i would have an environment variable PROMPT_COMMAND that ends with ";" the problem will occur.

hstr add export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}"
it effectivly means export PROMPT_COMMAND="history -a; history -n; ", because my env PROMPT_COMMAND is empty.

I will try to propose a change to SDKMAN in a while.

speedlog added a commit to speedlog/sdkman-cli that referenced this issue Apr 16, 2022
Remove double semicolon problem
Without this fix there may be a message with double semicolon:
bash: PROMPT_COMMAND: line 0: `history -a; history -n; ;sdkman_auto_env'
@helpermethod
Copy link
Member

helpermethod commented Apr 17, 2022

Hi@speedlog!

Why do you add a space before ${PROMPT_COMMAND}?

export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}"

SDKMAN! assumes that the existing PROMPT_COMMAND ends on a ;, in which case it's stripped away, or a command (w/o space).

I guess SDKMAN! could also strip trailing whitespace before, but I'd rather not add too much special casing for handling PROMPT_COMMAND, which is a hack anyway (zsh doesn't have all those problems).

speedlog added a commit to speedlog/sdkman-cli that referenced this issue Apr 18, 2022
Trim PROMPT_COMMAND
Without this fix there may be a message with double semicolon:
bash: PROMPT_COMMAND: line 0: `history -a; history -n; ;sdkman_auto_env'
@speedlog
Copy link
Contributor Author

@helpermethod
This fragment with space after semicolon is from hstr application.

I have not noticed there is solution removing double semicolon. So the problem is just space at the end.
I've changed my commit and trim PROMPT_COMMAND

speedlog added a commit to speedlog/sdkman-cli that referenced this issue Apr 19, 2022
Trim PROMPT_COMMAND
Without this fix there may be a message with double semicolon:
bash: PROMPT_COMMAND: line 0: `history -a; history -n; ;sdkman_auto_env'
helpermethod pushed a commit that referenced this issue Apr 21, 2022
Trim PROMPT_COMMAND
Without this fix there may be a message with double semicolon:
bash: PROMPT_COMMAND: line 0: `history -a; history -n; ;sdkman_auto_env'
@marc0der marc0der removed the wontfix label Apr 21, 2022
@marc0der
Copy link
Member

@speedlog That is now available for testing in the beta channel. Could you please confirm that it works for you?

@speedlog
Copy link
Contributor Author

@marc0der SDKMAN latest+0906561 works perfectly :-)
I've also tried manual change in sdkman-init.sh before my commit.

@helpermethod
Copy link
Member

@speedlog Thanks for bringing the issue up and providing a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants