LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 04-03-2021, 02:56 AM   #91
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Distribution: Devuan
Posts: 3,660
Blog Entries: 33

Rep: Reputation: 283Reputation: 283Reputation: 283

mine is simple... colour bash prompt, just different colours for user and root.

user glenn ... glenn@GamesBox ~ $

Code:
\[\033]0;\u@\h:\w\007\]\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]
root ... root@GamesBox:~# the colon and hash are white... on a dark transparent screen.
Code:
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;33m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
Happy holidays to you all.
 
Old 04-03-2021, 09:53 AM   #92
Fjor
LQ Newbie
 
Registered: Oct 2004
Location: Jalisco, Mexico
Distribution: Slackware
Posts: 24

Rep: Reputation: 5
Quote:
Originally Posted by apink View Post
look@theEmperorsNewClothe$
Interesting reminder...

Last edited by Fjor; 04-03-2021 at 09:58 AM.
 
Old 04-03-2021, 12:36 PM   #93
FrenchGuy
LQ Newbie
 
Registered: Oct 2008
Location: Toulouse, France
Distribution: Arch
Posts: 18

Rep: Reputation: 8
Quote:
Originally Posted by rhamel View Post
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
 
Old 04-05-2021, 08:44 AM   #94
bcramer
LQ Newbie
 
Registered: Apr 2007
Location: Brazil
Distribution: OpenSUSE
Posts: 20

Rep: Reputation: 0
username@computername $
 
Old 04-05-2021, 10:26 AM   #95
JKflip
LQ Newbie
 
Registered: Jul 2013
Posts: 1

Rep: Reputation: Disabled
A basic multiline prompt

code:
Code:
# ZSH ONLY - A Multiline Prompt; 
PROMPT="
%n@%m%d
∞ "
Looks like:
sys5@mbpr1/usr/local/sys/src
∞ cd ~/

sys5@mbpr1/Users/sys5
∞ ls
Applications Movies google-cloud-sdk
...
Library

sys5@mbpr1/Users/sys5

the blank line between commands improves readability in the terminal.
 
Old 04-05-2021, 12:45 PM   #96
rogerxx
Member
 
Registered: Feb 2021
Location: Ohio
Distribution: Gentoo & Slackware
Posts: 39

Rep: Reputation: Disabled
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 :-(

roger@4gentoo ~ $ echo


0 ;-)
roger@4gentoo ~ $
--- Snip ---

FILE: /home/user/.bashrc
export PS1='\[\033[01;32m\]\u@\h\[\033[01;36m\] \w$(__git_ps1 " (%s)") \$\[\033[00m\] '
export PS4='$0 line ${LINENO}: '

Last edited by rogerxx; 04-05-2021 at 12:53 PM.
 
Old 04-06-2021, 01:13 PM   #97
anutosho
Member
 
Registered: Nov 2007
Posts: 32

Rep: Reputation: 30
Two lines colored with last return code

I like the two lines promt as I often have lengthy paths.

PS1="\e[0;32m\u\e[0m@\e[1m\h\e[1;34m:\w\e[0m\n$ "

results in:

paul@bigfoot:~/lazarus/kunden/lib/x86_64-win64
$

adding a


PROMPT_COMMAND='LASTERROR="[$?]" ; echo ; test "$LASTERROR" == "[0]" || echo -ne "\e[97;33m${LASTERROR}\e[0m "'


displays the return code of the last command when it's not zero
Like so:

paul@bigfoot:~
$ ls not_existent
ls: cannot access 'not_existent': No such file or directory
[2]paul@bigfoot:~
$


 
Old 04-06-2021, 01:52 PM   #98
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by anutosho View Post
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
 
Old 04-06-2021, 02:14 PM   #99
WebDragon
LQ Newbie
 
Registered: Feb 2021
Location: Delaware
Distribution: Fedora
Posts: 1

Rep: Reputation: Disabled
my personal choice goes something like this

Code:
# use custom git prompt if exists.
export PS1="\s@\H:\w {\!}>\\$ "

if [ -f /usr/share/doc/git-1.8.*/contrib/completion/git-completion.bash ]; then
        source /usr/share/doc/git-1.8.*/contrib/completion/git-completion.bash
        source /usr/share/doc/git-1.8.*/contrib/completion/git-prompt.sh
        export PS1='\@ {\!} \[\033[01;32m\]\h: \w\[\033[00m\]\[\033[36m\]$(__git_ps1 " (%s)")\[\033[00m\]>\$ '
else
        echo "Git completion scripts not found. please update paths in .bashrc"
fi

Last edited by WebDragon; 04-06-2021 at 02:16 PM. Reason: add code tags
 
Old 04-06-2021, 06:00 PM   #100
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,818

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by hazel View Post
Why do you need the host? You know which computer you're working on.
Example: I could be working on multiple systems via my laptop. The visual cue can be important.
 
Old 04-06-2021, 06:05 PM   #101
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,818

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by DavidMcCann View Post
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"?
 
Old 04-07-2021, 02:23 AM   #102
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
Quote:
Originally Posted by rnturn View Post
So you never ssh into a remote system as another user? Or "su - otheruser"?
You can set terminal title to remote host name.
 
Old 04-07-2021, 08:48 AM   #103
woody weaver
LQ Newbie
 
Registered: Nov 2009
Location: Frederick, MD
Distribution: ubuntu
Posts: 4

Rep: Reputation: 0
I find the \u@\h:\w helpful (rather than title) since it allows cut and paste is scp commands.
 
Old 04-09-2021, 03:08 PM   #104
MeCrumbly429
LQ Newbie
 
Registered: Jul 2020
Location: East hill-meridian, Renton, WA
Distribution: Arch Linux, Slackware -current, CRUX Linux
Posts: 26

Rep: Reputation: Disabled
Anything involving a chevron prompt. Especially Fish.
the default bash prompt is good too.
 
Old 04-11-2021, 12:56 AM   #105
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
^ Please remove the forkbomb from your signature.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Poll: (Without the poll) - How is Linux used in your workplace? SlowCoder General 13 09-11-2007 11:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration