Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible to highlight (set a background colour) for the whole line of the prompt in zsh? In my emacs config I have the line on which the cursor sits a slightly different colour to the window background, which is a great visual aid. I'm wondering whether it's possible to do the same in my terminal/zsh prompt, so that it effectivly "draws a line" under everthing that's been run.

I've tried setting PROMPT='%{$bg[grey]%}# ' in my .zshrc but the highlight only extends as far as I type, not to the edge of the terminal.

Is what I'm trying to achieve possible?

share|improve this question

migrated from stackoverflow.com Apr 26 '11 at 12:12

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers

Try setting RPROMPT to spaces. The spaces count shall be the terminal width (minus the # and other characters.)

share|improve this answer
    
can you specify the exact command? –  kirill_igum May 28 '12 at 23:09
add comment

You can do anything you want with the prompt line* - the problematic aspect is getting it to undo it afterward. I assume you don't want every single line that has ever had a prompt on it displayed in your hilight colors.

It'd almost be easier to delete the line afterward, but then you don't have your command. Maybe delete the prompt then echo the command (with a pseudo-prompt like $). You could have the prompt begin with an ANSI cursor save sequence ESC [s, then in a precmd restore it ESC [u and clear everything after the cursor ESC [0J, then echo the command (I don't recall how to get the command from inside precmd).

*This is an incomplete answer, I don't know how to make it hilight the command in a different background color.

share|improve this answer
add comment

If I change grey to white, your example actually works for me.

What terminal are you using? Perhaps it handles background color erase differently?

Here are some alternatives to try:

Give the entire prompt line a gray background:

setopt promptsubst
preexec() {
    tput sgr0
}
PS1="$(tput setab 7)# "

(should be the same as your example, but a different way of writing it.)

Print a line before the prompt:

precmd() {
    tput smul
    for ((n=0; n<COLUMNS; n++)) { printf " "; }
    printf "\n"
}
preexec() {
    tput sgr0
}

(If you change "\n" to "\r", it should underline the current line, but that doesn't seem to work. I guess zsh erases the current line when printing the prompt, which is what lead me to the first solution.)

Make commands (i.e. everything you type) bold:

setopt promptsubst
preexec() {
    tput sgr0
}
PS1="# $(tput bold)"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.