Add class names to a css file

This script will prefix all style declarations in a css file with a given classname. So,

h1, h2, p, div{
    font:0.8em Arial;
}

Becomes:

.classname h1, .classname h2, .classname p, .classname div{
    font:0.8em Arial;
}

The script:

#!/bin/bash
# leona.gotroot.ca
# —————————-

classname=$2

sed ‘/{/ s/,/, .’$classname’ /g’ < $1 > test.txt

sed ‘s/.*{/.’$classname’ & /g’ < test.txt > $1.txt

rm test.txt

Invoke like so:

~$ sh css_replace.sh file_to_edit.css classname_to_add

This will give you a file called file_to_edit.css.txt. This script doesn’t account for one-liner declarations in the form of ‘p{font: Arial, Helvetica, sans-serif}’ so you’ll probably want to check over this file.

css_replace.sh

Including network files on a virtual desktop

If you’re running a Window’s virtual machine on a Mac, you might find at some time find the need to include a php file from your Mac while your working on the Window’s desktop.

C:> net use

Type this in the Window’s command line, should give you the computernamesharename address of your network drive.

Then the path to the file is as follows:

$sharepath = ‘\\.computernamesharename\TopDirectoryOnYourLocalHost\\1FirstSubDirectory\SecondSubDirectory\filename.php’;

include($sharepath);

The escaping for special characters makes this look a bit complex, but basically the address should start with two backslashes and have one backslash between directories where there are no escaped characters.

I had directories which started with the digit ’1′ in my path, so I had to escape those with an extra backslash.