Twittable scripts
April 13, 2008
There are a lot of folkes having fun with the shell, here are some that can be twitted and some tips.
Master script for dir2slideshow
April 2, 2008
I finally managed to make a script to autogenerate dir2slideshow files for all the picture directories I have. It is not entirely general but the only thing that needs to be changed is the input to the loop, which should be a list of directories. Besides the previous post included a bug which has been fixed, so please use this version -the name changed to path2name since now also dirs are allowed.
#!/bin/bash
# control script for dir2slideshow
# List of directories containing pictures. I guess that this could go into a variable right away...
function mydirs {
ls -d /home/asger/Pictures/*/ | egrep '200[[:digit:]]-([[:alnum:] _-])*';
}
# Extract file or dir names from full paths, note without any slashes.
function path2name {
echo $1 | egrep -o '/([[:alnum:] _-])*/?$' | sed 's/\///g';
}
# Interface to dir2slideshow, make it easy to change settings globally.
function d2s {
dir2slideshow -n $(path2name $1) $1;
}
# Loop through the list to generate all files.
for i in $(mydirs) ; do
d2s $i
done
path2file – get filenames from full paths
April 1, 2008
Still working on the dvd-slideshow thing I have found that it would b nice to globally control the generation of control files for it, and in that process I have found that it is an advantage to extract file names from full paths. This can be achieved with the following simple function:
function path2file {
echo $1 | egrep -o '/([[:alnum:] _-])*$' | sed 's/\///' ;
}
which takes a path as argument and gives back the file eg:
path2file ~/Documents/Programming/dvd-slideshow/dvd-burn
returns:
dvd-burn
This of course does not work for windows paths, but you can always exchange slash for backslash (only the escaped ones) to make it windows oriented
Edit: well of course there is already a tool for this in bash namely the history command with all its nice options. See for instance this tutorial.