Sunday, October 21, 2012

Seeing GTK mouse cursor in KDE?

If you have upgraded to Kubuntu 12.10, you’d notice that KDM has been replaced with LightDM.  LightDM looks pretty, but somehow doesn’t play well with KDE.  One annoying issue I have noticed is that GTK applications run in KDE use GTK mouse cursor under certain circumstances.  When Chrome shows a menu, the mouse cursor changes to a GTK one and it looks jarring.  Turns out, there’s a fix for that.

1. Install LightDM KDE greeter
sudo apt-get install lightdm-kde-greeter
2. Make LightDM use KDE greeter, and all will be well again. To do that, edit the file /etc/lightdm/lightdm.conf and change the value of greeter-session.  The file will look something like this after the change.  (Boldface text is the change you’d have to make.)
3. Save the file and test your changes by running LightDM in test mode:
lightdm --test-mode
If LightDM doesn’t open correctly, check if you have made any typing errors in the config file.  If you cannot fix the issue, just restore the file as it was before you edited; you’ll still have the ugly mouse cursor issue, but at least your computer will continue to work.

Sunday, October 7, 2012

Map Windows (aka Super) key to Escape

Did you know I have mapped Caps Lock on my computer to open a new browser tab?  Only today I figured my Vim sessions can be a lot better if I mapped ‘Windows’ key (aka Super key) to Escape.  It can be done by adding a single line to your ~/.Xmodmap file:
! Map left Windows key to Escape.
keysym Super_L = Escape
(Okay, that was two lines, but a little comment in obscure configuration files can be very helpful.)

Also, if you don’t feel like logging out and logging back in after these changes (or if you want to try the change before touching your config file), you can run this on a terminal to have the keybinding take effect immediately:
xmodmap -e 'keysym Super_L = Escape'

Tuesday, September 11, 2012

Prettier fonts in KDE

If you’re a KDE user and have always envied Gnome for its font rendering (especially with fonts like Ubuntu and Ubuntu Mono), read on.

All you need to do is select ‘Enabled’ for System Settings > Application Appearance > Fonts > Use anti-aliasing.  Click on the Configure button and set Hinting style to ‘Slight’.  If you like ClearType style font rendering, enable subpixel rendering too.

Any program that’s opened after this change will use the new font rendering settings.  So you may want to restart your open apps or logout and log back in.

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" ]]

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.

Sunday, April 29, 2012

Auto-deleting files from Trash and trash-cli package

Two tips about using Trash (aka Recycle Bin) folder efficiently on KDE:
  1. You can configure Dolphin to automatically delete files from Trash that are older than a certain number of days.  Use Dolphin menu > Configure Dolphin... > Trash > Delete files older than setting.
  2. You can access your Trash from command line if you have trash-cli package installed.  (Install it by running sudo apt-get install trash-cli command.)  Once installed, trash-list command shows the contents of your Trash, trash-put command moves files to Trash, and trash-empty command permanently deletes everything in Trash.
Source: A comment on Stefaan Lippens’ webface.

Saturday, February 25, 2012

Making git commands clear screen when they exit

One thing I don’t like about git is that commands like git diff don’t clear screen when they exit.  If I view a file using less, e.g. by running less ~/.zshrc, less would clear the file content from the screen when it exits.  But git diff, git log, etc. don’t.  With some Googling around, I found that:
  • git uses the default pager the user has configured.  On Ubuntu machines it’s less when $PAGER is not defined.
  • You can configure less by defining $LESS variable with the flags you want to pass by default.
  • Nigel McNie has posted a set of flags that are a good default flags for less.
  • -X option to less tells it to not clear the screen when it exits.  From a related question on Super User I found that passing the flag -+X would force less to always clear the screen when it exits.
Combining all these together, I have added this to my ~/.zshrc, and everything is just the way I want.
export LESS="-+X -FR"
While adding this line made git work fine, it resulted in less behaving erratically.  Now I have the following config in my ~/.gitconfig, and things seem to be good.
  pager = less -+X -+F

Wednesday, January 18, 2012

Inserting single quote character inside a single-quoted string

“Strings” (not the same as strings in languages like C or Python) in shells (bash and zsh especially) can be enclosed within either single quotes (') or double quotes (").  Double quotes escape (i.e. remove special meaning from) characters like space and single quotes, but single quotes remove meaning from almost every special character including spaces, $, !, new lines, etc.  (Learn more)

You can use \ escape to insert a double quote character (") inside a double-quoted string, but you cannot do the same for inserting a single quote character (') inside a single-quoted string.  Because \ has no special meaning inside a single-quoted string.
% echo "abc \" def"
abc " def
% echo 'abc \' def'                   
quote> blah'
abc \ def
But I often find myself needing to insert apostrophes inside single-quoted strings.  I use the following syntax then:
% echo 'There'\''s always a way out'
There's always a way out
Shells usually let you concatenate strings by just writing them together without any space between them: "abc""def" is the same as "abcdef" which is the same as "abc"'def' which is the same as abcdef (without quotes).  We use the same technique here: we have two different single-quoted strings: 'There' and 's always a way out'.  In between them we have a single-quote character escaped with \ to mean that we want a literal apostrophe character inserted.

Saturday, January 14, 2012

Running Ubuntu on a Toshiba Z830

I bought a Toshiba Z830 recently.  This post is to document how I am running Kubuntu on it.  First, let me show you how fast it boots :)

  1. The machine has only 128GB storage, which cannot be upgraded yet, which means having both Windows and Linux on the machine may not be realistic.  But there’s a way to back up Windows!  Toshiba bundles a program with the computer that creates recovery USB drives for the Z830.  I bought a new 16GB USB drive and made it a recovery drive.  The plan is to use this for restoring Windows when I am giving this laptop away to somebody in future.
  2. I downloaded 64-bit Kubuntu 11.10 installer from  Since I have a backup copy of Windows, I removed all NTFS and recovery partitions from the disk and created new partitions for installing Kubuntu.
  3. After the installation, almost everything worked out of the box.  I had no issues with the laptop sleeping or waking up; 3D graphics worked fine; audio, bluetooth, webcam... everything worked.  Except the following one issue.
  4. Screen brightness controls sometimes worked, but sometimes they didn’t.  The technique that helped in 2008 helped me this time too, except I needed to make a minor modification to the program: the file that required changing was /sys/class/backlight/intel_backlight/brightness (i.e. intel_backlight instead of acpi_video0).  And the brightness value seem to be in the range of 100 through 4400.
  5. Battery life was bad.  More worrying than battery life was the heat generated by the laptop.  I found some tips to reduce power usage on Putokaz blog, and tried it (thank you, voloder!).  While it did reduce power consumption, it also resulted in some screen update issues.  After some trial and error, I found that frame buffer compression was causing issues, so I left that one out.
    Update: Kubuntu 12.04 provides a very good battery life out of the box.
  6. ZDNet recommends disabling “elevator” I/O scheduler by passing elevator=noop to kernel.  Based on tips from both sources, I have updated my /etc/default/grub to have this line:
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash elevator=noop"
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash pcie_aspm=force i915.i915_enable_rc6=1 i915.lvds_downclock=1 elevator=noop"
    (Power management flags may work on other computers with the same Core i5-2467M Sandy Bridge processor as well.)
  7. Based on the same ZDNet story mentioned before, I updated my /etc/fstab as well.  I added noatime flag to my ext4 partitions and mounted /tmp on RAM using tmpfs.  (I didn’t change the caching parameters as that sounds a bit scary.)
    UUID=dbccce1d-8e31-428e-a25a-227afc54651f /      ext4  noatime  0  1
    UUID=720c576c-2c1a-435f-ae90-9151acda2005 /home  ext4  noatime  0  2
    tmpfs /tmp tmpfs nodev,nosuid,noexec,size=1G 0 0
Update: Someone was asking about battery life, so here's a screenshot of expected battery life.  With Ubuntu 12.04, you'd get more than 5 hours of battery life on a full charge.

Saturday, January 7, 2012

Partitioning disk for installing Linux

Are you installing Ubuntu on a new machine and you’re not sure how much storage space the installation would need or how to partition your disk?  I have a few suggestions:
  • Create separate partitions for Linux installation (mounted at /) and data (mounted at /home).  This way, you can completely wipe and reinstall your OS or switch to a different distro without worrying about data in your home directory.
  • A typical Linux installation doesn’t need a lot of space.  I allocated 20GB for my root (/) partition purely based on some guess work, but I’m using only about 7.2GB in that partition.  If I’m starting over again, I’d go with a 12 or even a 10GB partition.  (You’re a lot more likely to eventually run out of space on your home partition than on the root partition.)
    % df -hl
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda1              19G  7.2G   11G  40% /
    udev                  2.9G  4.0K  2.9G   1% /dev
    tmpfs                 1.2G  996K  1.2G   1% /run
    none                  5.0M     0  5.0M   0% /run/lock
    none                  2.9G  2.8M  2.9G   1% /run/shm
    /dev/sda6              93G   78G   11G  89% /home