6

The Mate terminal like any other terminal emulator in Ubuntu or any other OS has an input line like:

abc@xyz:~$

How to change the font style of this particular line? Other than this one inputs commands to the line above and then the command generates messages thereafter. I want to set this text to a different style. I can do that using by going to Edit>Profile preferences. But this changes the Font style of the input line to the same one. I want there to be a difference between the input line text and rest of the text in the terminal so that after a command has printed messages verbosely, I can trace-back the input line without hard-gazing.

Ubuntu 16.04 seems to come with a default color for the input line that remains unchanged by tweaking options in Profile preferences.

  • It is not possible to have different font size for the prompt than for the rest of the terminal's contents. You could instead use colors, bold and/or italic text etc. for your prompt. – egmont Aug 21 '16 at 21:17
  • @egmont I think that is what the OP wants - to change the style, as you mention, not the actual font – Zanna Aug 21 '16 at 21:19
  • @Zanna My bad, I guess I misread "font style" as "font size". – egmont Aug 21 '16 at 21:21
  • not bad at all @egmont I think your comment was helpful – Zanna Aug 21 '16 at 21:22
5

(Some of the screenshots below reveal use of a particular text editor. If this is problematic for the reader, they are hereby begged to consider the use of this editor by the post author an act of blameless naivety)

The terminal prompt is a part of your user environment called PS1. It is defined in your .bashrc file, which you can edit to change it. You can see what it is currently with echo $PS1. Here is mine:

$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;35m\]\w\$\[\033[00m\]

This makes my prompt look like this compared to some command...

Making a coloured prompt is achieved by uncommenting this line in your .bashrc

#force_color_prompt=yes

so it looks like this:

force_color_prompt=yes

This causes the prompt to be set by the line after if [ "$color_prompt" = yes ]; then

which by default is:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

The colours are set by these codes:

  • light green \[\033[01;32m\]
  • white \[\033[00m\]
  • light blue \[\033[01;34m\]

and then back to white. You can see they are the same apart from the number in the second set of brackets. Here's a few more escape codes to choose from:

Blue        0;34     Light Blue    1;34
Green       0;32     Light Green   1;32
Cyan        0;36     Light Cyan    1;36
Red         0;31     Light Red     1;31

Here are some other options to make your prompt stand out

---All tested in MATE terminal on Ubuntu MATE 16.04---

When applying these changes to a white prompt, I leave this line commented:

#force_color_prompt=yes

And edit the fourth line of this section of .bashrc:

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\$ '

If you want to apply underline, and highlight effects to a coloured prompt, then as explained before you need to uncomment force_color_prompt=yes, and edit the second line instead of the fourth. In the examples below, I am referring to the "fourth line" and "second line" from the snippet above.

Bold prompt:

Change the fourth line to include the escape sequences \[\e[1m\] (bold) and \[\e[0m\] (stop bold)

PS1='${debian_chroot:+($debian_chroot)}\[\e[1m\]\u@\h:\w\$ \[\e[0m\]'

Not a big difference - I include the line above for comparison.

In the colour escape sequences "light" colours (with 1 instead of 0 as shown in table above) are considered bold. I tried using the bold sequence on the coloured prompt, but it seems MATE terminal doesn't allow this to make it even more bold. I also tried it using setaf code but still no result. Maybe I'm getting something wrong. I also couldn't manage an italic prompt, and I didn't even try a blinking prompt - that's just not OK.

Underlined prompt:

Change the fourth line to include the escape sequences \[\e[4m\] and \[\e[24m\]

PS1='${debian_chroot:+($debian_chroot)}\[\e[4m\]\u@\h:\w\$ \[\e[24m\]'

For underlined coloured prompt, uncomment force_color_prompt=yes and add the \[\e[4m\] sequence to the second line twice. The existing reset codes will terminate the effect:

PS1='${debian_chroot:+($debian_chroot)}\[\e[4m\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\e[4m\]\[\033[01;34m\]\w\[\033[00m\]\$ '

Highlighted prompt:

Change the fourth line to include \[\e[7m\] and \[\e[27m\]

PS1='${debian_chroot:+($debian_chroot)}\[\e[7m\]\u@\h:\w\$ \[\e[27m\]'

For colour highlighting, uncomment the #force_color_prompt=yes and change the colour escape codes in the second line to have a 4 instead of a 3, for example:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;42m\]\u@\h\[\033[00m\]:\[\033[01;44m\]\w\[\033[00m\]\$ '

To get the highlighting all one colour, remove the first reset and the second colour sequence:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;42m\]\u@\h:\w\[\033[00m\]\$ '

For more exotic options, see my favourite AU question and this site for a detailed guide.

Obviously I recommend making backups as you play around , but if you ever FUBAR your .bashrc you can just copy a fresh one from /etc/skel:

cp /etc/skel/.bashrc ~/.bashrc
  • 1
    And if one wants to make the prompt font bold? – user_1_1_1 Aug 22 '16 at 4:04
  • 1
    Easy :) I'll update my answer later when I have time to get screenshots uploaded @user_1_1_1 :) – Zanna Aug 22 '16 at 8:17
  • 1
    @user_1_1_1 here's some more options for you – Zanna Aug 23 '16 at 13:37
  • @Zanna, how can I make font size of commands bigger than rest terminal output? – ganeshdeshmukh Aug 11 '18 at 4:45
  • 1
    @ganeshdeshmukh I am not aware of any way to do this. I believe the font size is a setting of the terminal emulator, or for virtual terminals of the kernel, and cannot be changed in the prompt code. You may want to ask a new question about this, to see if anyone knows better and help others find the information in future – Zanna Aug 11 '18 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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