3

I know that terminal prompt can be changed using PS1="prefix" and I know how to set it permanently, that is not a problem. I am just wondering, how would I set it to look like in parrot OS?

Especially how would I make it multi-line and how would I create that nice arrow?

enter image description here

SouravGhosh
  • 553
  • 5
  • 12
ItsDrike
  • 123
  • 1
  • 2
  • 11

4 Answers4

4

Shell prompt recreation:

Shell using ParrotOS-like prompt

Create a file ~/.bash_prompt (or any name you like) and paste this code in it

# Define some basic colors using tput (8-bit color: 256 colors)
red="\[$(tput setaf 160)\]"
bright_red="\[$(tput setaf 196)\]"
light_purple="\[$(tput setaf 60)\]"
orange="\[$(tput setaf 172)\]"
blue="\[$(tput setaf 21)\]"
light_blue="\[$(tput setaf 80)\]"
bold="\[$(tput bold)\]"
reset="\[$(tput sgr0)\]"

# Define basic colors to be used in prompt
## The color for username (light_blue, for root user: bright_red)
username_color="${reset}${bold}${light_blue}\$([[ \${EUID} == 0 ]] && echo \"${bright_red}\")";
## Color of @ and ✗ symbols (orange)
at_color=$reset$bold$orange
## Color of host/pc-name (blue)
host_color=$reset$bold$blue
## Color of current working directory (light_purple)
directory_color=$reset$light_purple
## Color for other characters (like the arrow)
etc_color=$reset$red
# If last operation did not succeded, add [✗]- to the prompt
on_error="\$([[ \$? != 0 ]] && echo \"${etc_color}[${at_color}✗${etc_color}]─\")"
# The last symbol in prompt ($, for root user: #)
symbol="${reset}${bold}${bright_red}$(if [[ ${EUID} == 0 ]]; then echo '#'; else echo '$'; fi)"


# Setup the prompt/prefix for linux terminal
PS1="${etc_color}┌─${on_error}[";
PS1+="${username_color}\u"; # \u=Username
PS1+="${at_color}@";
PS1+="${host_color}\h" #\h=Host
PS1+="${etc_color}]-[";
PS1+="${directory_color}\w"; # \w=Working directory
PS1+="${etc_color}]\n└──╼ "; # \n=New Line
PS1+="${symbol}${reset}";

export PS1

The comments should describe the code functionality sufficiently.
If you want to use this prompt automatically, add following code to your ~/.bashrc file

# Use custom bash prompt (will execute .bash_prompt script)
if [ -f ~/.bash_prompt ]; then
  . ~/.bash_prompt
fi
ItsDrike
  • 123
  • 1
  • 2
  • 11
  • Why the `+x` in the mode. It is not needed, and won't help. Did you test this bit?. (-1 for the `+x`, and +1 for the rest.) – ctrl-alt-delor Dec 24 '19 at 10:52
  • Nicely done! Personally I'd echo `$?` instead of `✗`, though. Not exactly what the OP asked for, but it adds a little more information. – markgraf Jan 12 '20 at 08:46
2

Here is my code (not exactly the same).

  • To do the newline there is a \n
  • The funny arrow is unicode a character (paste from web-lookup)
  • The colour code have to be between \[ and \], to tell bash that they are zero width (so that it can do its stuff, like go to start of line. It is all done with dead reckoning.
  • Codes like \033[01;32m are colour codes.

    if [ "$color_prompt" = yes ]; then
      PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    else
        PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    fi
    _PS1="$PS1"
    PS1='$(echo $title|sed -r -e "s/^(\S+)\$/[\1]/")'"${_PS1}\n#↳ "
    
ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102
1

I might be a bit late to this post... but for anyone who finds it useful I've pasted the whole .bashrc file from ParrotOS here.

This is the bit you're interested in:

if [ "$color_prompt" = yes ]; then
    PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;39m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]\[\e[01;33m\]\\$\[\e[0m\]"
else
    PS1='┌──[\u@\h]─[\w]\n└──╼ \$ '
fi
mogli
  • 11
  • 1
  • Ironically, the actual ParrotOS code is inferior to the version in another answer where someone reverse engineered it from the screenshot. (-: – JdeBP Jan 12 '20 at 00:29
0

Get PS1 variable from Parrot OS via env, copy it to file and use on your other Linux.

So it could be like that:

echo "PS1=\"$PS1\"" > setPS1

and use this file as script in other Linux. You may need to export the variable. Setting it up in ~/.bashrc would be easy.

pbies
  • 424
  • 4
  • 15
  • Problem is that I don't have an instance of Parrot OS currently installed anywhere – ItsDrike Dec 24 '19 at 18:31
  • @Koumakpet that means you can't permanently setup this variable. Or you can run the script each time you need. – pbies Dec 24 '19 at 22:24