Category Archives: linux

How to add a second taskbar to your other monitor in twinview in ubuntu

I have an Ubuntu workstation at work with a nvidia graphics card and dual monitors in Twinview mode (meaning, they act like one large desktop, except that the full screen apps take only one monitor, if I got it right).

Anyway, I wanted to add a taskbar to my other monitor – mainly because I wanted a second taskbar with the window list. My main problem was that I had no apparent way to add any panels to the second monitor – they all ended up on the primary.

Well, here is how one can do it:

1.) Right click on anywhere on the old panels and  click “New Panel”

2.) hold down ALT + Drag the new panel to any monitor/location.

3.) Right click on the new panel and click “Add to Panel”

4.) Now you can add the window list (Right-click -> Add -> Window List) or anything you need here.

5) Click Close.

A smallish bitbucket trick: handling more then one account

Today I had to think on how to handle two separate bitbucket.org git accounts without conflicts.

I have my private bitbucket account: zladuric. There I have some play-code – thing to play with.  I also have a company bitbucket account: zduric. There’s the company central-sort-of code repository.

Now, I can checkout something from my company account:

git@bitbucket.org:zduric/myoffice.git

I need to enter my details, username, email, password and all. But now I also have a private account.

git@bitbucket.org:zladuric/jam.git

How to handle that?

Well, that’s where SSH comes in. I already use SSH’s config file to handle authentication. I have a ssh key and config section in my .ssh/config, and I use it like this:

Host bitbucket.org
        User git
        HostName bitbucket.org
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_rsa

Now, I just added another section, to ssh config file, with my git-specific key:

Host bitbuck
        User git
        HostName bitbucket.org
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/git_id_rsa

There is one last detail:

When checking out private files, I use

git@bitbucket.org:zladuric/jam.git

And for company repo, I can safely use:

git@bitbuck:zduric/myoffice.git

SSH can handle the rest. Pretty nifty, huh?

Bash history Tab completition

Well, I just upgraded my Ubuntu box and I’ve lost some of my bash features. One of them is that I’ve set up bash history tab completition, long time ago. But I forgot how I did it. Then I remembered that I had my old home and found it.

So in order to have bash history tab completition, you should just create a file in your home directory, called .inputrc, and put these two lines in it:

"\e[5~": history-search-backward
"\e[6~": history-search-forward

That’s it. Now you can type out a few letters and with Ctrl-PgUp and Ctrl-PgDn browse your bash history for the commands beginning with those letters.

I’m putting it up here because I’m likely to upgrade my linux boxes again some time and I need a place to remember it at.

Linux Shell Mass Rename

I’m slowly uploading my digital photo archives to Picasa albums. I bought the extra space recently, I want to make sure my pictures are ok for a longer time.

I’m using google command line for this. It’s going slowly, so I mostly start the upload process remotely when I’m at a work (because google-cl kills bandwidth, so I can’t reliably use net when I’m home and when google-cl is working).

Well, to get to the point. One of the albums had file names in the form of ‘more1 1.jpg’, ‘more1 2.jpg’… and I wanted to change this. Being a linux geek that I am, I knew the shell was the fastest way to go. But I didn’t know how.

It’s easy, of course, I googled it in few seconds. I’m posting it here for my future referrence.

So here is the resulting line:

ls * | sed ‘s/more1\ \(.*\)/mv “&” “\1″/’ | sh

Now step-by-step explanation:

1. ls *  - this is clear (there were only files in the folder). This could have been something like find . -type f, or find /somewhere -name ‘<name pattern>’.

2. sed ‘s/more1\ \(.*\)/mv “&” “\1″/’

This is the fun part. sed can filter text, do regex searches, matches, transformations, whatever.

Regex term s/<ORIGINAL>/<NEW>/ means that I want to change the ORIGINAL for NEW.

3. ORIGINAL

In my case, orignal was more1\ \(.*\) : more1 is the first part of the name. Then there is this space (escaped with a backslash). Then there is a “match whatever, zero or more characters: (.*) – of course the () had to be escaped too.

This could also have been something like file123.jpeg –  I can match it with /file\(.*\)\.jpeg/ – translated it means match anything that begins with file and ends with .jpeg. So, now we have ORIGINAL.

4. NEW

What I wanted is lose the “more1\ ” part. I had to move (hence mv) the file (“&” – the quotes are because of the spaces in the filename) to just the first group (\1).

5. What is first group?

In regexes, when you match something, it’s called a group. When you match two things, you have two groups. Ie file.extension is matched by /(.+)\.(.+)/ (1 or more anything, dot, 1 or more anything – the dot if not escaped means “any character”).

So my matched group was \1 (the number and extension). In my example where I matched file<NUM>.jpeg, I could move this to holliday\1.JPG – to capitalize the ending or whatever.

6. The last part, sh.

What did sed produce? It took a string like ‘more1 120.jpg’ and turned it into a string like ‘mv “more1 120.jpg” “120.jpg”‘. But this is a string, it is not a command.

So we piped that string to the ‘sh’ command. It would be the same as I’ve written:

sh mv “more1 120.jpg” “120.jpg” – which is what I wanted in the first place.

Hope I remember this post when I need a mass-rename next time :)