Shell Person Help me keep the shell people alive.


Notes on Preventing Screen Blanking

Here are a few notes I've made on keeping the the screen from blanking in linux. I generally am using Ratpoison (and sometimes just the console), so these are notes on how to disable screen blanking in X and console situations, not the higher-level GNOME or KDE screensaver. I've come up with a configuration that works to keep my screen from ever turning off, but I don't have an in-depth understanding of exactly what's being done. Some of this may be redundant.


BASH – Get Size of Directory in "ls -l" Output

flowring cabbage regular by abundantlyabove29 (C) via Flickr

(The above photo is "flowring cabbage regular", by abundantlyabove29 (C) via Flickr).

UPDATE: I've written a newer and much better version of this script. You can find it at:

I found a function like this a long time ago in some forum, but I remember it not working with filenames that include spaces. There's almost certainly a better and more-efficient way of doing this, but here's draft one.

This will output the same data as "ls -lh", in almost the exact same format, except directories will show the size of the sum of their contents (du -sh) instead of the 4.0K of space the directory "file" takes up. The only noticeable difference in format is that there is a slightly larger gap between the size and the date columns.

## mimic "ls -l" except display size of sum of directory's contents
for x in *; do echo -e "$(ls -lL | grep -w "$x" | cut -d ' ' -f 1-4) $(du -sh "$x" | cut -d '	' -f 1)" "\t" "$(ls -lL | grep -w "$x" | cut -d ' ' -f 5-20 | sed s/^\ *// | cut -d ' ' -f 2-20)"; done

It's hard to enter code in a presentable way in wordpress - and this code doesn't appear perfectly. Note that the multiple-space gap that delimits (-d) the second "cut" command is a tab. You can add a tab at the command line by using CTRL+v followed by TAB. The code does work if you use the copy-to-clipboard button on the code block.

I saved this as "lsd", made it executable, and put it in a directory in my $PATH (~/bin).


Easily Change Text Color with BASH


Here's a script to easily add color to other BASH scripts. The only trick to it is that it uses a character that I don't know how to put on the web.

NB - If you select the "view plain" link at the top of the container surrounding the script, it will open a new link with the plain text of the script. You should use this plain text. Not only does it preserve the special character the script uses to change colors, it also preserves other characters that WordPress changes (note line 5, between "cat" and "EOF"). If you don't use the "view plain" link and try to cut, but instead paste the script directly from this page, it won't work. Also, if you need to create the special character I use to make it display different colors, you can make it in gnome-terminal by pressing "ctrl+v" followed by "ctrl+[".

## Specify color to write in using arguments

function --help {
cat << EOF ERROR: $0 requires a color argument. USAGE: Changes the color of the text piped into it. These color arguments are availabe: ARGUMENT SHORTCUT white ------ w red ------ r green ------ g yellow ------ y blue ------ b purple ------ p teal ------ t bold ------ bb The "bold" argument will modify any color. Use a max of 2 arguments (one color and bold). EOF } function bold { # make the color bold BOLD=1\; } function white { COLOR=1 } function red { COLOR=31 } function green { COLOR=32 } function yellow { COLOR=33 } function blue { COLOR=34 } function purple { COLOR=35 } function teal { COLOR=36 } ## shortcuts function bb { bold } function w { white } function r { red } function g { green } function y { yellow } function b { blue } function p { purple } function t { teal } ## Execution if [ "$#" = 0 ] then --help fi while (($#)); do $1 shift done echo -n "["$BOLD""$COLOR"m" cat echo -n "" [/sourcecode] Here's a link to an example of what it looks like in action. Note that the input must be piped into the script.