Discussion:
GNUbash v. 4.4.23-5 – Bash identifier location is non-correct in terminal
Ricky Tigg
2018-10-29 10:40:54 UTC
Permalink
Component: bash.x86_64 4.4.23-5.fc29 @fedora

To reproduce,: execute 'curl https://www.startpage.com'.

Actual result:

$ curl https://www.startpage.com
(...) [***@localhost ~]$

Expected result:

$ curl https://www.startpage.com
(...)
[***@localhost ~]$
Davide Brini
2018-10-29 10:45:58 UTC
Permalink
Post by Ricky Tigg
To reproduce,: execute 'curl https://www.startpage.com'.
$ curl https://www.startpage.com
$ curl https://www.startpage.com
(...)
That is most likely because the output of curl does not end with a newline.
Simpler reproducer:

$ printf '%s' hello
hello$

It's not a bash issue IMHO.
--
D.
Ilkka Virta
2018-10-29 12:35:17 UTC
Permalink
Post by Ricky Tigg
$ curl https://www.startpage.com
The shell just prints the prompt where ever the cursor was left. That's
quite common, the only exception I know is zsh, which moves the cursor
to the start of line if the previous command didn't leave it in the left
edge.

A simple workaround would be to add '\n' at the start of the prompt, but
it would then print an empty line above the prompt for every command
that does properly finish the output with a newline. Some might find
that ugly.

It might be possible to check for that manually in PROMPT_COMMAND.
Something like this seems to mostly work for me in interactive use,
though it's rather stupid and will probably break down at some point.

prompt_to_bol() { local pos; printf '\e[6n'; read -sdR pos;
[[ ${pos#*;} != 1 ]] && printf '\e[30;47m%%\n\e[0m'; }
PROMPT_COMMAND=prompt_to_bol

(I stole the main parts from the answers in
https://unix.stackexchange.com/q/88296/170373 )
--
Ilkka Virta / ***@iki.fi
Ricky Tigg
2018-10-29 21:11:57 UTC
Permalink
Awesome, thanks!
Post by Ilkka Virta
Post by Ricky Tigg
$ curl https://www.startpage.com
The shell just prints the prompt where ever the cursor was left. That's
quite common, the only exception I know is zsh, which moves the cursor
to the start of line if the previous command didn't leave it in the left
edge.
A simple workaround would be to add '\n' at the start of the prompt, but
it would then print an empty line above the prompt for every command
that does properly finish the output with a newline. Some might find
that ugly.
It might be possible to check for that manually in PROMPT_COMMAND.
Something like this seems to mostly work for me in interactive use,
though it's rather stupid and will probably break down at some point.
prompt_to_bol() { local pos; printf '\e[6n'; read -sdR pos;
[[ ${pos#*;} != 1 ]] && printf '\e[30;47m%%\n\e[0m'; }
PROMPT_COMMAND=prompt_to_bol
(I stole the main parts from the answers in
https://unix.stackexchange.com/q/88296/170373 )
--
Jaren Stangret
2018-10-30 15:43:18 UTC
Permalink
Post by Ilkka Virta
prompt_to_bol() { local pos; printf '\e[6n'; read -sdR pos;
[[ ${pos#*;} != 1 ]] && printf '\e[30;47m%%\n\e[0m'; }
PROMPT_COMMAND=prompt_to_bol
(I stole the main parts from the answers in
https://unix.stackexchange.com/q/88296/170373 )
Another solution I use is to emulate ZSH's behavior, which places a
'%' in reverse video if the previous command ended in a newline,

# Can return $ps1 by printing our using this function in
# PROMPT_COMMAND, or some other means.
_zsh_prompt_nl()
{
local line_pos col_pos
IFS=';[' read -s -t1 -d'R' -p $'\033[6n' _ line_pos col_pos

if (( col_pos != 1 )); then
(( LINES != line_pos ))
ps1="${reset/\[0/[7}%${reset}\n${ps1}\n"
else
ps1="${ps1}\n"
fi
}

Updating LINES and COLUMN non-interactively can be difficult,
so obtaining these values manually may be required:

IFS='[;' \
read -rsu2 -d'R' -p $'\033[s\033[9999;9999H\033[6n\033[u' \
_ LINES COLUMNS

Loading...