Command Line

Random gnome-terminal profiles (themes) in Ubuntu

Introduction

Does it ever confuse you if you have too many terminals open at once that look alike? Perhaps you’re just looking to express your personality or tickle your brain. In any case, if you’re using the terminal in ubuntu a lot, you may be interested in having random profiles (colors / settings).

The concept of the method is pretty simple, define a hotkey that launches a script that picks a random profile you’ve created and then open the terminal with that profile as a parameter.

Prerequisites

- Compiz or other hotkey script that will allow you to link to a .sh file
- gnome-terminal
- bash

Getting Started

You can figure out what Profiles you have by going to Edit > Profiles in gnome-terminal. You likely only have one, “Default”, unless you’re already actively using terminal profiles. If you only have one, you should create a few, maybe 3 or 4 right now and play with the colors a bit. Important, don’t include spaces in the names of the profiles

The Script

Create a file in your scripts folder (or create a directory if you don’t have one):

mkdir ~/scripts
touch ~/scripts/gnome-terminal.sh && chmod +x ~/scripts/gnome-terminal.sh
gedit ~/scripts/gnome-terminal.sh

Paste the following replacing the Profile names with those of your own (delimited by spaces) and change the number 4 to that of the :

#!/bin/bash
p=( Default Delta Psi Sigma )
gnome-terminal --window-with-profile ${p[$((RANDOM%${#p[@]}))]}

That ugly looking bit right here is a calculation between a random number (echo RANDOM) and the size of the array (${#p[@]}), “random” % “length of array”. Where % means mod, or remainder of the division. (examples: 7%4 = 3; 6%4 = 2; 5%4 = 1; 4 % 4 = 0; 4 % 3 = 1; 321%321= 0).

To illustrate more, play with this code:

r=$RANDOM; echo $r; echo $((r % 4))

This is how we get a random index value for the array. This value is nested inside the array ${p[r]}, where r is the random, within bounds, array index. That array then corresponds with a name of our profile and we pass it as a paramater to gnome-terminal with “–window-with-profile”. So using my define array above, if the random index were “1″, “Delta” would be echoed. If the index were “0″, Default would be.

The Setup

Now, I use compiz with the commands plugin, setting my “command line 0″ to ~/scripts/./gnome-terminal.sh and my “run command 0″ under my key bindings tab to ctrl+alt+t, but you can associate this script with anything you’d like to kick it off. A shortcut icon for example.

May this inspire you to understand, extend and share.

Fastest way to install the media essentials in ubuntu

If you’re coming from Windows, or like me, find yourself living in a live CD while you figure out which step went wrong; you’ll be interested in the essential media codecs, flash, java, Microsoft fonts, etc.

I thought I’d share the way I did this as quickly as possible in in Ubuntu 10.04 using the command line.

Open up terminal, using ctrl+alt+t (Which I’m very happy about as this has been my default since 8.04). Alternativelty from the main menu -> Applications > Accessories > Terminal

Make a backup in case you’re scared, then remove the comments from repositories you need to unlock to access the restricted (proprietary) packages.

ubuntu@ubuntu:~$ sudo cp /etc/apt/sources.list .
ubuntu@ubuntu:~$ sudo sed -i 's/^# deb/deb/' /etc/apt/sources.list

We do this be matching the first 2 characters with ‘# ‘ and replacing them with ” (nothing). See the diff below (> indicate original lines, < are changed).


ubuntu@ubuntu:~$ diff sources.list /etc/apt/sources.list
18,23c18,23
< # deb http://archive.ubuntu.com/ubuntu lucid universe
< # deb-src http://archive.ubuntu.com/ubuntu lucid universe
< # deb http://archive.ubuntu.com/ubuntu lucid-updates universe
< # deb-src http://archive.ubuntu.com/ubuntu lucid-updates universe
< # deb http://security.ubuntu.com/ubuntu lucid-security universe
< # deb-src http://security.ubuntu.com/ubuntu lucid-security universe
---
> deb http://archive.ubuntu.com/ubuntu lucid universe
> deb-src http://archive.ubuntu.com/ubuntu lucid universe
> deb http://archive.ubuntu.com/ubuntu lucid-updates universe
> deb-src http://archive.ubuntu.com/ubuntu lucid-updates universe
> deb http://security.ubuntu.com/ubuntu lucid-security universe
> deb-src http://security.ubuntu.com/ubuntu lucid-security universe
30,35c30,35
< # deb http://archive.ubuntu.com/ubuntu lucid multiverse
< # deb-src http://archive.ubuntu.com/ubuntu lucid multiverse
< # deb http://archive.ubuntu.com/ubuntu lucid-updates multiverse
< # deb-src http://archive.ubuntu.com/ubuntu lucid-updates multiverse
< # deb http://security.ubuntu.com/ubuntu lucid-security multiverse
< # deb-src http://security.ubuntu.com/ubuntu lucid-security multiverse
---
> deb http://archive.ubuntu.com/ubuntu lucid multiverse
> deb-src http://archive.ubuntu.com/ubuntu lucid multiverse
> deb http://archive.ubuntu.com/ubuntu lucid-updates multiverse
> deb-src http://archive.ubuntu.com/ubuntu lucid-updates multiverse
> deb http://security.ubuntu.com/ubuntu lucid-security multiverse
> deb-src http://security.ubuntu.com/ubuntu lucid-security multiverse
>
<pre class="brush:bash">

Now that we uncommented these lines, they will be read next time we update, so lets go ahead and do that now. Once that is done, we can install the extras.

ubuntu@ubuntu:~$ sudo apt-get update
ubuntu@ubuntu:~$ sudo apt-get install ubuntu-restricted-extras

Rock and roll.

screenshot-about-shiretoko

Installing Firefox 3.5.2 (Shiretoko) on Ubuntu using the default repos and customizing the icon to be more recognizable

When Firefox 3.5 came out, I along with many others, was eager to try it. For a while I ran it out of the archive directly but this caused minor issues as it’s a messy solution. At some point I noticed firefox-3.5 in the repository:

tyler@quadjutsu:~$ apt-cache search firefox |grep 3.5
abrowser-3.1 - dummy upgrade package for firefox-3.1 -> firefox-3.5
abrowser-3.1-branding - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.1 - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.1-branding - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.1-dbg - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.1-dev - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.1-gnome-support - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.5 - safe and easy web browser from Mozilla
firefox-3.5-branding - Package that ships the firefox branding
firefox-3.5-dbg - firefox-3.5 debug symbols
firefox-3.5-dev - Development files for Mozilla Firefox
firefox-3.5-gnome-support - Support for Gnome in Mozilla Firefox

and proceeded to install it with the following command:

tyler@quadjutsu:~$ sudo apt-get install firefox-3.5

It runs along-side Firefox 3.0 without a hitch. I often use the two in tandem while testing web applications.

Something that bothered me about this was the default icon isn’t as recongnizable to me as I’d like it to be.

screenshot-about-shiretoko

As such I looked into a way to replace it.

First, I found a replacement icon I liked

hp-firefox-128x128

from the following website (where other nice replacements exist).

Then I went to find the logical location of the files to replace. First I updated my ‘locate’ database file because this software is new, so it’s not yet known. This is done automatically daily on a cron but you can update it any time you’d like as follows:

tyler@quadjutsu:~$ sudo updatedb

Then I probed for icons I might think would be responsible.

tyler@quadjutsu:~$ locate firefox |grep lib |grep icon |grep 3.5
/usr/lib/firefox-3.5.2/icons
/usr/lib/firefox-3.5.2/chrome/icons
/usr/lib/firefox-3.5.2/chrome/icons/default
/usr/lib/firefox-3.5.2/chrome/icons/default/default16.png
/usr/lib/firefox-3.5.2/chrome/icons/default/default32.png
/usr/lib/firefox-3.5.2/chrome/icons/default/default48.png
/usr/lib/firefox-3.5.2/icons/document.png
/usr/lib/firefox-3.5.2/icons/mozicon128.png
/usr/lib/firefox-3.5.2/icons/mozicon16.xpm
/usr/lib/firefox-3.5.2/icons/mozicon50.xpm

The first set in the ‘/usr/lib/firefox-3.5.2/chrome/icons/’ folder will replace the icons used by the application itself (i.e. the icon in the top of your window). The latter, ‘/usr/lib/firefox-3.5.2/icons/’ will replace the ones used by shortcut icons.

Here are all the files for the icons I resized if you’d like to use them.

firefox-3.5_replacement_chrome_icons.zip
firefox-3.5_replacement_shortcut_icons.zip

bash pro-style:

cd Desktop/ && mkdir firefox_replacement_icons && cd firefox_replacement_icons
wget http://www.doknowevil.net/files/firefox-3.5_replacement_chrome_icons.zip && wget http://www.doknowevil.net/files/firefox-3.5_replacement_shortcut_icons.zip
for file in *.zip; do unzip $file; done
sudo cp chrome/* /usr/lib/firefox-3.5.2/chrome/icons/default/
sudo cp shorcuts/* /usr/lib/firefox-3.5.2/icons/