Archive for July, 2007

‘Compact’ bash prompt

Monday, July 30th, 2007

Especially when working with cakephp, the following line in your .bash_profile script might come in handy:

HOSTCOLOR="31m"
PS1="\u@\[\e[${HOSTCOLOR}\]\h\[\e[0m\]:\w\n\[\e[33m\]\!\[\e[0m\] \$ "

It will print out the current working directory on the first line and the actual bash prompt on the second line. Making it less likely that your command will wrap lines after the first few typed characters.
It changes the command prompt from:

command line long

….into:

command line 'short'

The login prompt now shows the following info:

  • username
  • hostname in red (in my bash script, it will print red for one group of servers and blue for other servers)
  • current working directory
  • command history number, ie: use !520 to execute the previous command

Extracting layers from a XCF (gimp) file

Saturday, July 21st, 2007

This is a script that extracts the layers of a XCF file to individual PNG files. It uses xcftools (debian/ubuntu package):

#!/bin/bash

xcffile=$1

layers=`xcfinfo $xcffile  | awk '{ print $NF }'`

destdir=`dirname $xcffile`/layers
mkdir $destdir

for layer in $layers
do
        echo saving $layer to $destdir/$layer.png
        xcf2png -o $destdir/$layer.png $xcffile $layer
done

exit 0

Convert ^M to newline character in text files

Monday, July 9th, 2007

Summary:
In vi use the following:

:%s/^M/\n/g

or, when just removing ^M characters:

:%s/^M//g

NOTE: Be sure to create the ^M by typing ctrl+V followed by ctrl+M.