You are not logged in.
Hello,
I did colorize my prompt and am now having two weird issues.
1. When browsing in the bash history, sometimes the 4 first letter of a command stay stuck on the line but won't be parsed. For example, the following command entered after browsing bash history does work:
tan@bobby ~$ convsudo pacman -S kstars2. When typing a long line, the overflow once you reach the end of the screen (if no X running) / of the window starts on the same line, erasing the prompt. Ex:
mmandobby ~$ this is a vereeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrryyyyyyyyyyyyyyyy long coBoth those bugs happen only when using my PS1= line in .bashrc, and on both graphical and non X console.
Here is full my .bashrc:
#
# ~/.bashrc
#
# If not running interactively, don't do anything
#[[ $- != *i* ]] && return
shopt -s histappend
alias ls='ls --color=auto'
alias ll='ls -al --color=auto'
export VISUAL="nano"
export PATH=$PATH:/home/tan/bin
ESC=$(printf "\e")
PS1='$ESC[1m\[$(tput setaf 3)\]\u@\h\[$(tput sgr0)\] \[$(tput setaf 2)\]\w\[$(tput sgr0)\]\$ 'So there must be something wrong with that last line. It does colorize the prompt as intended, but is the origin of those bugs. Any ideas?
Last edited by eichan (2018-01-10 15:40:06)
Offline
The problem is your PS1. You need \[ \] around all non printable characters (e.g. color escape codes). You do seem to use these around the tput subshells which is correct, but not around the $ESC variable. I'm not sure though why you use a variable with a name longer than the content it holds. Also note, as currently written, every time your prompt is displayed several subshells will have to run tput to generate the color codes, you'd be better off either just using normal escape codes, or running tput once for each color and setting variables.
I'm pretty sure this is the equivalent of what your PS1 is doing, but much simpler (and correctly escaped):
PS1='\[\033[1;33m\]\u@\h \[\033[0;32m\]\w\[\033[0m\]\$ 'Last edited by Trilby (2018-01-10 15:37:50)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Yep, that works.
That was fast, thanks!
Offline
I don't think that using commands like tput that manipulate the terminal in the PS1 is supported. Basically, your PS1 should consist of characters that are interpreted as explained in PROMPTING section of "man bash". Any non-printable characters should be enclosed by \[ \]. If you use external commands; they should only print something on their stdout, not having a direct side effect on the terminal.
To colorize your output, use ANSI escape code. For example to ut your prompt in RED; use something like:
PS1='\[\e[91m\][\u@\h \w]\$\[\e[m\] 'Offline
I don't think that using commands like tput that manipulate the terminal in the PS1 is supported.
It certainly is. I think it's a bit silly and wasteful, but it will absolutely work. You can run any process you want. tput, when run with the right parameters, will return the requested escape code for the color.
The OP's PS1 actually works fine except for the very first $ESC variable not being enclosed in \[ \]. Technically, that would be all that was needed for it to no longer be broken. But getting rid of all those needless subshells is a worthwhile improvement too.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
The problem with using tput there is not that it is unsupported, because like Trilby said, it is certainly supported.
I would add, that the problem is using tput there when tput is a command that always returns the same output. Using a command with dynamic output can enhance your PS1 in highly specific ways, for example, by checking to see if cwd is a git repository and showing the current status of the git repository. You cannot do that with a variable, but you *can* do color codes with a variable!
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline