Saturday, September 8, 2012

Disabling Ubuntu menu proxy when not using Unity

Does seeing messages like this on your terminal annoy you?
** (gvim:8016): WARNING **: Unable to create Ubuntu Menu Proxy: Timeout was reached
It sure does annoy me.  Turns out, it’s because the app you’re running is trying to connect its menus to Unity’s “global menu” (or whatever that’s called).  The way to fix this problem would be to disable Unity menu proxy when you’re not using Unity.  Add this to your shell’s startup script (.bashrc, .zshrc, etc):
if [[ $DESKTOP_SESSION != "ubuntu" && $DESKTOP_SESSION != "ubuntu-2d" ]]
then
  export UBUNTU_MENUPROXY=0
fi

Friday, August 31, 2012

My zsh prompt string PS1

Every Unix user with a blog has a post about it: how they have configured their PS1 so their command prompt is almost a mini dashboard that shows everything they’d need to know.  I am no exception.  Even if this post doesn’t really help others, bragging is gratifying, so I’d go on and show how awesome my PS1 is :)

I have been using zsh for a while now, and I am quite happy with it.  I’m a sucker for colours and I was annoyed that I couldn’t take full advantage of my 256 colour terminal because I just didn’t know how to.  So I searched the web and found two good pages.  Combined with some manual-reading I had done, I cooked up my shiny new PS1:
PS1='%(?.%F{245}.%F{124})%2m %F{130}%~ %F{215}%# %f'
Unfortunately, prompt strings are never intuitive, so I’ll do some explaining.
  • %F{colour_code} sets the foreground colour to the specified colour.  Colour code is simply a number in the range 0 to 255 (assuming your terminal supports 256 colours).
  • %f resets the foreground colour to default.
  • %(condn.true_string.false_string) is a conditional expression.  If condn evaluates to true, true_string is emitted; otherwise false_string is emitted.  Like you’d expect, you can have some special strings in condn to mean interesting things.
Deconstructing my PS1
I actually started with something more simple:
PS1='%F{245}%2m %F{130}%~ %F{215}%# %f'
The prompt string starts with the machine name printed in grey.  Then comes the current working directory in a yellow/orange colour, followed by zsh’s % prompt that’s a wee bit brighter than the directory name.  But I wanted to have the exit status of the previous command in my prompt somewhere.  It’s not some information I really need, but I thought it can be a nice-to-have.  But at the same time I didn’t want this information to clutter up my prompt.

I figured I could use make use of colours to differentiate between success and failure of the previous command.  So I changed %F{245}%2m to %(?.%F{245}.%F{124})%2m.  Now, the machine name is printed in grey if the previous command succeeded, and in red if it had failed.  Thus born the prompt string that exactly fits my needs... for now.

Friday, August 10, 2012

Only 8 colours on ssh-ed terminals?

Vim (i.e. console vim, but not gvim) on my primary workstation uses 256 colours and with syntax highlighting on, editing source code is a much pleasant experience (vs. being limited to 8 colours).

However, every time I ssh a different machine, Vim on the remote machine always used 8 colours.  I’m a big fan of seeing a lot of colours and hated the 8-colours environment of the remote machines.  After some digging, I found out the cause for this problem.  My primary machine has COLORFGBG environment variable set, but the remote machines don’t.  Check Skåne Sjælland Linux User Group to see how you can fix this issue.  (Essentially, you’ll have to configure ssh on your machine and the remote machine to pass COLORFGBG environment variable.)

Update: Actually, adding the line set background=dark to my ~/.vimrc seems like a much easier solution.  And also, “only 8 colours” is not the real problem.  Real problem is that vim is using a different set of colours (dark blue instead of light blue, for instance) on the new machine.

Wednesday, June 13, 2012

Renaming files using pattern matching

Let’s say you have a bunch of files in a directory with names like dog.jpeg, cat.jpeg, fountain.jpeg, etc.  Your OCD insists that you rename them all to more “regular” names like dog.jpg, cat.jpg, and fountain.jpg.  If you use zsh, pat yourself on the back for using a cool shell, and run these commands:
autoload zmv
zmv -W '*.jpeg' '*.jpg'
You probably know this already, but it’s worth mentioning.  Single quotes around the patterns is important because we want zmv to interpret the pattern; zsh should pass the pattern as such to zmv without expanding it.

Wednesday, May 23, 2012

Directly switch to the window that’s showing a popup

If a window that’s not currently active shows a dialogue box, KDE would highlight it in the taskbar.  Switching to that window is a lot easier than hunting it down by pressing Alt+Tab repeatedly.  Just press Ctrl+Alt+A, and voila, you’re looking at the window that’s asking for your attention.