akermu / emacs-libvterm

Emacs libvterm integration
GNU General Public License v3.0
1.69k stars 135 forks source link

Hostname issue in bash #703

Open Ergus opened 7 months ago

Ergus commented 7 months ago

Hi:

The hostname command is not part of bash by default. It seems like some distros deliver the variable $HOSTNAME instead. For those distros (like mine Arch Linux) it may be better to change

vterm_prompt_end(){
    vterm_printf "51;A$(whoami)@${HOSTNAME}:$(pwd)"
}

Or a more elaborated alternative that attempts to use the right version like:

[[ -n $HOSTNAMEE ]] && echo $HOSTNAME || (command -v hostname > /dev/null && hostname)

or similar (I am sure it may be a much better alternative)

Sbozzolo commented 7 months ago

Interesting, I always assumed that hostname was available everywhere. It is not a bash-builtin, but a binary. I guess we could change it to uname -n, which should be POSIX.

I personally find $HOSTNAME not very robust. It is a variable and as such users/admins could change it.

Ergus commented 7 months ago

Also a nice solution!

Sbozzolo commented 6 months ago

If you open a PR, I'll merge it :)

Thanks in advance!

Ergus commented 2 months ago

Hi @Sbozzolo :

I made the modification for this issue a long time ago, but I never merged it. The change is very simple, and I can open a merge request. However, There is a detail that still worries me. And it is the line:

PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }"'echo -ne "\033]0;${HOSTNAME}:${PWD}\007"'

It still uses HOSTNAME the variable. And I am not sure if you want to change it as well because you said.

I personally find $HOSTNAME not very robust. It is a variable and as such users/admins could change it.

I'll open a pull request when this detail will ve solved.

Sbozzolo commented 2 months ago

Could you use uname -n instead?