Battery level in Bash prompt

by Kevin on October 17, 2008
in Journal

If you are like me and want to run mainly in command line while using a laptop, you might have trouble finding out how much charge is left in your laptop battery. GUIs always have some sort of widget that reports battery info but the command line is sorely lacking. It would suck to be typing away then your screen going dead in the middle of something important.

I have been looking for a simple solution for a while and came up with one. The idea is to print the output of the acpi command in your bash prompt. It is a pretty simple thing to do.

[ `acpi` ] is the fragment of text you need to put into the PS1 variable in your .bashrc file. My prompt looks like PS1=’[ `acpi` ]\n${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ‘

Looks complicated but the bulk of it is colour making the prompt look better. My prompt looks as such:

Hope this helps someone.

I love bash

by Kevin on April 16, 2008
in Journal

I really do love the Bash shell, particularly the ability to do scripting. I wanted to make all the files in a directory have lowercase filenames. It gets tedious when doing it by hand and there is no native way to do i in Nautilus (file browser in Gnome). Thunar (Xfce window manager file manager) does have this facility but I’m not gonna install it and all its dependancies. So with a quick google search I found a wee snippet of bash script to do the job for me. Presenting dir2lowercase:

#!/bin/bash
# Script to convert all the files in the current directory to lowercase
# Code taken from http://webxadmin.free.fr/article/shell-rename-all-files-in-subdirectories-to-lowe-135.php

for f in *; do
g=`expr “xxx$f” : ‘xxx\(.*\)’ | tr ‘[A-Z]‘ ‘[a-z]‘`
mv “$f” “$g”
done