Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
That is so interesting. Do you have a screenshot? What do you mean by the "right part of the line"?
I also use the return code of the previous command in my root prompt, but never thought of displaying the previous command that failed.
Is such a thing even possible under bash, I wonder?
As an image is worth thousand words and as my English is far from perfect here are two screenshots one with a short command line one with a long the right part of the line which echoes the current path is automagically wiped.
Not sure my files have been attached. Sorry. Ask Jean-Pierre <at> cabanie <dot> net for them Sorry
Last edited by FrenchGuy; 04-03-2021 at 12:38 PM.
Reason: Attachements not attached... user error
I desire knowing the return value (BASH VAR: $?) after executing a script/command.
I also desire a blank line after each executed script/command, separating prior stdout/output from each subsequent script/command.
For example, quite a few scripts/commands exit rather apparently normal or quietly when using a bad incantation of a script/command. Printing the $? return value readily reveals the accidental bad incantation/usage, or most other problems, of the script/command.
--- Snip ---
roger@4gentoo ~ $ dummy
bash: dummy: command not found
127 :-(
I like the two lines promt as I often have lengthy paths.
...
displays the return code of the last command when it's not zero
I also like to have these both features in my prompt.
Additionally, a two-line, colored prompt helps me to find the beginning of lengthy output when scrolling back. It's not just eyecandy (though I have nothing against that).
Code:
if [[ ${EUID} == 0 ]] ; then
# root = color=1 # red
if [ "$TERM" != "linux" ]; then
PS1="\[$(tput setaf 1)\]\[$(tput rev)\] \[$(tput sgr0)\]\[$(tput setaf 5)\]\${?#0}\[$(tput setaf 1)\] \u@\h \w\[$(tput sgr0)\]\n\[$(tput rev)\] \[$(tput sgr0)\] "
else
# adding \t = time to tty prompt
PS1="\[$(tput setaf 1)\]\[$(tput rev)\] \[$(tput sgr0)\]\[$(tput setaf 5)\]\${?#0}\[$(tput setaf 1)\] \t \u@\h \w\[$(tput sgr0)\]\n\[$(tput rev)\] \[$(tput sgr0)\] "
fi
else
# git stuff only for non-root users
# inspired by: joshtronic.com/2018/01/28/minimalist-git-prompt/
git_prompt() {
[ -d '.git' ] || return 0
declare -a info # to keep it localized
local dirty=""
mapfile -t info <<<"$(git --no-optional-locks status --porcelain -b)"
(( ${#info[@]} > 1 )) && dirty="\e[0;31m╳" # red X
printf " git:\e[0;33m${info[0]##*/}$dirty\e[0;0m" # branch in yellow, then dirty, then reset
}
if [ "$TERM" != "linux" ]; then
PS1="\[$(tput setaf 2)\]\[$(tput rev)\] \[$(tput sgr0)\]\[$(tput setaf 5)\]\${?#0}\[$(tput setaf 2)\] \u@\h \w\[$(tput sgr0)\]\$(git_prompt)\n\[$(tput rev)\] \[$(tput sgr0)\] "
else
PS1="\[$(tput setaf 2)\]\[$(tput rev)\] \[$(tput sgr0)\]\[$(tput setaf 5)\]\${?#0}\[$(tput setaf 2)\] \t \u@\h \w\[$(tput sgr0)\]\$(git_prompt)\n\[$(tput rev)\] \[$(tput sgr0)\] "
fi
fi
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,818
Rep:
Quote:
Originally Posted by DavidMcCann
PCLinuxOS defaults to
Code:
PS1="[\u@\h \W]\\$ "
Since I know my own name, don't care what the computer is called, don't know what the brackets are for, and can tell root use from things turning red, I prefer
Code:
PS1="\W \$ "
So you never ssh into a remote system as another user? Or "su - otheruser"?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.