5

How can I get a $PS1 containing box-drawing characters?

I am running bash, if it makes a difference.

slhck
  • 223,558
  • 70
  • 607
  • 592
Wuffers
  • 19,020
  • 17
  • 95
  • 126
  • ...Archer being the machine name, I suppose? – Arjan Dec 05 '10 at 17:10
  • Could be, but I'm not too interested in that part. I'm mostly interested in the characters towards the left: the strange bars and square-like character. – Wuffers Dec 05 '10 at 17:12
  • The screenshot is gone. The title of the post should be changed and mention bex-drawing characters or geometric shapes. Anyway the word "screenshot" in a title is a bad idea. – Ludovic Kuty Oct 01 '14 at 11:05

2 Answers2

11

If you've got an editor with UTF-8 support, you can input the Unicode box-drawing characters and geometric shapes directly. Something like:

PS1='┌─[blah][blah]
└─▪ '

Write this to a file using your editor, then source the file into your bash session with source ./myfile. When you're ready to keep it, add it to your .bashrc file.

The other, older way to do it is to use VT100 escape codes to switch to the terminal's line-drawing character set. In this case, your PS1 line looks like this:

PS1='\[\e(0\]lq\[\e(B\][blah][blah]
\[\e[0\]mq~\[\e(B\] '

The \[ and \] tell bash that these portions of the prompt are non-printing, which helps it know where the cursor is when doing command-line editing. The \e(0 switches to the line-drawing character set, and the \e(B switches back. While in line-drawing mode:

  • l is ┌
  • q is ─
  • m is └
  • ~ is ▪

You can build a complete list by running things like printf '\e(0 qwertyuiop \e(B \n' at the bash prompt.

Jander
  • 874
  • 6
  • 8
0

Here's a very nice sampling of different PS1:

The one you want is this:

You will have to change it a bit, but the elements are there. I suggest you take a look here for more info:

icyrock.com
  • 5,247
  • 2
  • 31
  • 30
  • For some reason, I can't get the clock3 PS1 to work. I tried copying and pasting the code exactly and it didn't work, at all. I am using Terminal.app on Mac OS X with a UTF-8 encoding. – Wuffers Dec 05 '10 at 17:48
  • @Mr. Man: Did you source the file or run it? You need to source it. – Dennis Williamson Dec 05 '10 at 21:10
  • I sourced the file. When I did it, it gave me a bunch of garbage. – Wuffers Dec 05 '10 at 21:21
  • The reason this didn't work is because it uses the IBM BIOS extended character set from the DOS days, which is supported by the text-mode console in Linux, but not by xterm or Terminal or most other terminal emulators. – Jander Dec 06 '10 at 00:32