5

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

I am running bash, if it makes a difference.

3
  • ...Archer being the machine name, I suppose?
    – Arjan
    Dec 5, 2010 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 5, 2010 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. Oct 1, 2014 at 11:05

2 Answers 2

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.

0
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:

4
  • 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 5, 2010 at 17:48
  • @Mr. Man: Did you source the file or run it? You need to source it. Dec 5, 2010 at 21:10
  • I sourced the file. When I did it, it gave me a bunch of garbage.
    – Wuffers
    Dec 5, 2010 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 6, 2010 at 0:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .