Skip to main content

Change the Colour of Emacs Shell Prompt and Font Highlighting


The project I'm currently working on is Linux based, and I just can’t get my head around vi no matter how hard I try. Fortunately I have root privileges, so Emacs to the rescue :)

We are using CentOS so installing is as easy as

 sudo yum install emacs   

One of the many reasons I really like Emacs is you can run a shell inside Emacs.
Press Alt – x
Type shell
Press enter
NB the Alt key in Emacs is often called the Meta key and the key combination above would be shortened to M – x

This allows me to split the Emacs window and have the shell in the bottom half and what I working on in the top half, see the image below. To switch between the shell and what I’m working on I press M – O (that’s Alt and the letter O and not the number zero, Alt zero will unsplit the screen)


If like me you’re running Emacs inside Putty the first thing you might notice is the shell prompt is in dark blue on a black background. Not only is this very difficult to read but it can cause eye strain making for an unpleasant work day.

To change the colour of the shell prompt, and any font highlighting in Emacs is actually very easy if you know how. However the settings are a bit hidden, here is how to change the colours of any text in Emacs.

First you need to find out the supported colours for your version of Emacs. I’m using an old version and it doesn't support many colours, see the image below. Newer versions of Emacs support many more colours. To list the colours do the following.
Press M – x
Type list-colors-display
Press enter


Make a note of the easy to read colours. Then to change the colour of the shell prompt inside Emacs
Press M – x
Type list-faces-display
Press enter
This will display all the Font Highlighting options you can change, see the image below. On the left you will see underlined text of the name of the setting. On the right you will see the current colour settings.


Find the text comint-highlight-prompt and move the cursor directly over the top of it and press the enter key (sometimes the comint-highlight-prompt option doesn't show up, I don’t know why). This will take you into another screen, see the image below.  



  1. If the square brackets on the left of “Foreground” don’t have an X inside them like circle 1 in the image above, move the cursor in between the square brackets and press enter. This will enable the Foreground option
  2. Now move the cursor directly on top of the current colour of the foreground, circle 2 in the image above
  3. Press enter
  4. Type in the new colour you would like for the shell prompt, circle 3 in the image above. I chose green so I could feel like I was using a 1980s terminal :)
  5. Press enter 
  6. Move the cursor to the “Save for future sessions”, circle 4 in the image above 
  7. Press enter 
  8. Press Ctrl – x k to close the current screen / buffer. 
And you’re done :) The shell prompt will be what every colour you set it to.
While you are at it I would recommend changing at least minibuffer-prompt as well, you will be reading the text displayed in the minibuffer-prompt a lot. If you are feeling up to it change all the other text colours you find hard to read using the process above.

If all else fails add the following to your .emacs file

 (custom-set-faces  
  '(comint-highlight-prompt ((t (:foreground "green"))))  
  '(minibuffer-prompt ((t (:foreground "green"))))  
 )  

finally no matter which method you use to change the colour of the shell prompt in enacs, don't forget to back up your .emacs file. Recreating it takes far to long

Reference: http://lists.gnu.org/archive/html/help-gnu-emacs/2004-11/msg00170.html

Comments

  1. This is really helpful. Thank you very much. I searched internet a lot and finally got it by this.

    ReplyDelete
    Replies
    1. I had to do a lot of searching to do this too hence the blog post. Glad it helped someone else too.

      Delete
    2. I had to do a lot of searching to do this too hence the blog post. Glad it helped someone else too.

      Delete

Post a Comment

Popular posts from this blog

How to Pretty Print JSON and XML from the Command Line

As developers we often need to take minified JSON and XML and pretty print it so it is human readable. A multitude of websites provide a free service where you can enter minified JSON or XML and it will format it the data so it is human readable. The problem is this can lead to leaking data causing security incidents. The solution is to write a couple of bash scripts to pretty print. A big thanks to Campovski 's answer on stackoverflow for the JSON and Ben Noland 's answer on stackoverflow and Anton I. Sipos ' comment for the XML I took these answers a little further and created a bash script that accepts arguments so you can pretty print A file The result returned form an API A string Data piped in Both scripts have the same usage Format a file with the -f flag JSON ./pretty_json.sh -f <name_of_file> XML ./pretty_xml.sh -f <name_of_file> Format the return value of an API with the -u flag JSON ./pretty_json.sh -u www.api.com XML ./pretty_xml.sh -u

Turning Off SSLv3 in Apache and IIS8, AKA Putting Down the Poodle That Bites

Poodle is a security vulnerability that has been found in SSLv3. Since SSL is over ten years old, and the only browsers that support it as the strongest version of encryption are IE6 and older, in my humble opinion it is safe to turn it off.  Let's start with the easy one, Linux, in particular CentOS. NB you will most likely need to be root or be part of the sudo group to make the following changes 1)     Open the ssl.config file with your favourite text editor. In Red Hat based distributions like CentOS you should find it in /etc/httpd/mods-available/ssl.conf 2)     Find the line starting with  SSLProtocol 3)     Change it to  SSLProtocol all -SSLv2 -SSLv3 This will allow all ciphers expect SSLv2 and SSLv3 4)     Save ssl.conf and exit your text editor 5)     Restart Apache by running the command service httpd restart 6)     Use a tool like sslscan to check all SSLv2 and SSLv3 ciphers are rejected or fail. An example of this would be ssl