Thursday, December 23, 2010

Creating a Custom Bash Prompt for each GNOME Terminal Profile

This website does a particularly good and simple job of explaining how to set up your own custom bash prompt style in Linux. One issue that I had been having, however, is that I could not find any way to have more than one co-existing prompt style. That is, to set up each terminal profile to have its own bash prompt design. I managed to find a number of people online looking to set up multiple bash prompt styles for each of their GNOME terminal profiles, but with no answers. Thankfully, I was ultimately able to figure it out by my own trial and error.


First of all, read the instructions on http://www.linuxhelp.net/guides/bashprompt/bashprompt-print.php to learn how to set up a "PS1=..." line for your ~/.bashrc file. As you may already know, if you wish to make changes for all bash sessions, you can add such a line to the bottom of that file, or you may simply type it into a bash prompt to enable the configuration temporarily.



I will use as an example the following format, generated with the help of the website provided above:

PS1="\[\033[0;31m\]Linux\[\033[1;37m\]Box \\w"

Rather than adding this to your ~/.bashrc file and therefore modifying the prompt style of all your terminals, you can simply make a copy of your .bashrc file and make the changes to that file; call it whatever you would like (I call mine .bashrcalt).

cd 
cp .bashrc .bashrcalt

Then, in the GNOME Terminal profile settings for the specific profile you would like to work with, go to the "Title and Command" tab, check the box that says "Run a custom command instead of my shell," choose "Exit the terminal when command exits" and, for the command to run, set the following:

 bash --rcfile .bashrcalt

Now, load a GNOME Terminal session with your custom profile enabled. e.g.:

gnome-terminal --profile=the_name_of_your_profile_here

You should be viewing the bash prompt with the custom set up you configured.

Wednesday, June 2, 2010

Creating a fixed RAM disk in Ubuntu

Ciao lume.

A couple weeks ago I began tinkering with an operating system called Icaros, a desktop distribution of AROS, which is in turn a modern operating system designed to imitate and build upon the classic AmigaOS 3.1 environment. AROS comes with a "RAM Disk"--a fixed or dynamic partition of a computer's memory set asside to function as though it were a disk drive--loaded on the machine by default.

A RAM disk offers the benefit of storing and retrieving data more quickly than on an actual hard disk, as well as some security features thanks in part to the fact that any data stored on the disk will be removed on reboot. A RAM disk can be beneficial for numerous purposes, most commonly today to set as the location for browser cache to make visited webpages load faster (ideally on larger RAM disks with proper size limitations noted in one's browser cache settings). The use and benefit of RAM disks (which as far as I know have been around longer than permanent disk drives) will whither away with the replacement of spinning disk drives with static-state drives. For the moment, however, I found it an interesting enough concept that, despite the fact I have little to no apparent use for one, I decided to create a RAM disk that boots at each startup in Ubuntu 10.04 (Lucid).

There are a few easier ways to do this which you can easily google and bing yourself. I have found, however, that what most people consider today a RAM disk are actually disks that use both physical as well as virtual memory, the latter being stored on the hard drive and thus eliminating the purpose of having a RAM disk to begin with. I also made the decision that I wanted a RAM disk of fixed size, not a dynamic one (e.g. mounting /dev/shm) which can take over up to half the system memory--I only have two gigabytes of RAM on my machine).

To do this, run:

sudo mkfs -t ext3 -q /dev/ram1 65536
sudo mkdir -p /media/ramdisk
sudo mount /dev/ram1 /media/ramdisk -o defaults,rw

(Where 65536 is the size in kilobytes, translating to an example size of 64 megabytes.)

The RAM disk should then be mounted on the desktop. To make this happen at system startup (for all users), run:

gksudo gedit /etc/rc.local

(Replace gedit with your preferred editor, replacing gksudo with the ordinary sudo command for terminal-based, non-graphical editors.)

Making sure not to add anything after the line reading exit 0, add the following to the file:

mkfs -t ext3 -q /dev/ram1 65536
mount /dev/ram1 /media/ramdisk -o defaults,rw
chmod 777 -R /media/ramdisk

A few additional tweaks: Setting the RAM disk up as an ext3 partition, a folder lost+found is created every time the RAM disk is loaded at boot-up. I personally found this annoying. As you may know, to hide a file or folder (without having to rename it) in Gnome, you must create a file named .hidden whose contents list the names of the file(s) you wish to hide and which must be stored in the same directory. To make this happen each time you log in, you can create a text file containing nothing but lost+found, name it whatever you would like, and then store it somewhere obscure. Then create a basic script which copies that file to /media/ramdisk/.hidden - The contents of the script can be as simple as:

#!/bin/bash

cp /home/user/example/hide_thing /media/ramdisk/.hidden &

Set the script to load when you log in by (System - Preferences - Startup Applications) setting the command to: /the/location/of/your/script/./the_name_of_your_script.sh


The RAM disk I set up is viewable by all users of my system including my guest account. Any files that are stored to the RAM disk can be viewed by others users by logging out and switching sessions (as long as the machine is not rebooted). I decided to create a folder called private on the RAM disk (which is automatically created every time I log in, which is only viewable only by me. To do this, add the following line to the script just shown:

mkdir /media/ramdisk/private && sleep 1s && chown YOU_USER_NAME -R /media/ramdisk/private && sleep 1s && chmod 700 -R /media/ramdisk/private &

Now all I have to do is find a use for this thing. This article will be grossly obsolete in a few months if it isn't already.