Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I am running bash, if it makes a difference.

share|improve this question
    
...Archer being the machine name, I suppose? –  Arjan Dec 5 '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 5 '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 1 at 11:05

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
    
Perfect! I just copy-pasted the characters and it works like a charm! Thanks! –  Wuffers Dec 5 '10 at 21:13

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:

share|improve this answer
    
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 '10 at 17:48
    
@Mr. Man: Did you source the file or run it? You need to source it. –  Dennis Williamson Dec 5 '10 at 21:10
    
I sourced the file. When I did it, it gave me a bunch of garbage. –  Wuffers Dec 5 '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 6 '10 at 0:32
    
@Jander Thanks for the clarification and obviously for the answer to Mr. Man! –  icyrock.com Dec 6 '10 at 1:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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