#! /bin/bash
VERSION=0.7 ##by Jason Pline 2008-04-26
##find a suitable version of gtkdialog (needs 0.7.20 or greater) currently (as of puppy 4 and maybe before)
##the executable is named gtkdialog3. Exit with a warning incase gtkdialog isn't found.
GTKDIALOG=""
if [ "`which gtkdialog3`" != "" ]; then
GTKDIALOG=gtkdialog3
elif [ "`which gtkdialog`" != "" ]; then
GTKDIALOG=gtkdialog
elif [ "$GTKDIALOG" = "" ]; then
echo "you need to install gtkdialog"
exit 0
fi
if ! [ -d $HOME/.config ]; then
mkdir $HOME/.config
fi
if ! [ -d $HOME/.config/tmp ]; then
mkdir $HOME/.config/tmp
fi
if ! [ -d $HOME/.config/tmp/prename ]; then
mkdir $HOME/.config/tmp/prename
fi
if ! [ -f $HOME/.config/tmp/prename/dir ]; then
touch $HOME/.config/tmp/prename/dir
fi
if ! [ -f $HOME/.config/tmp/prename/old ]; then
touch $HOME/.config/tmp/prename/old
fi
if ! [ -f $HOME/.config/tmp/prename/new ]; then
touch $HOME/.config/tmp/prename/new
fi
if ! [ -f $HOME/.config/tmp/prename/new1 ]; then
touch $HOME/.config/tmp/prename/new1
fi
if ! [ -f $HOME/.config/tmp/prename/c1 ]; then
echo true > $HOME/.config/tmp/prename/c1
fi
if ! [ -f $HOME/.config/tmp/prename/c2 ]; then
echo false > $HOME/.config/tmp/prename/c2
fi
if ! [ -f $HOME/.config/tmp/prename/c3 ]; then
echo false > $HOME/.config/tmp/prename/c3
fi
if ! [ -f $HOME/.config/tmp/prename/c4 ]; then
echo false > $HOME/.config/tmp/prename/c4
fi
if ! [ -f $HOME/.config/tmp/prename/c5 ]; then
echo false > $HOME/.config/tmp/prename/c5
fi
if ! [ -f $HOME/.config/tmp/prename/r1 ]; then
echo true > $HOME/.config/tmp/prename/r1
fi
if ! [ -f $HOME/.config/tmp/prename/r2 ]; then
echo false > $HOME/.config/tmp/prename/r2
fi
if ! [ -f $HOME/.config/tmp/prename/r3 ]; then
echo true > $HOME/.config/tmp/prename/r3
fi
if ! [ -f $HOME/.config/tmp/prename/r4 ]; then
echo false > $HOME/.config/tmp/prename/r4
fi
if ! [ -f $HOME/.config/tmp/prename/r5 ]; then
echo true > $HOME/.config/tmp/prename/r5
fi
if ! [ -f $HOME/.config/tmp/prename/r6 ]; then
echo false > $HOME/.config/tmp/prename/r6
fi
if ! [ -f $HOME/.config/tmp/prename/r7 ]; then
echo false > $HOME/.config/tmp/prename/r7
fi
if ! [ -f $HOME/.config/tmp/prename/r8 ]; then
echo true > $HOME/.config/tmp/prename/r8
fi
if ! [ -f $HOME/.config/tmp/prename/r9 ]; then
echo false > $HOME/.config/tmp/prename/r9
fi
if [ "`cat $HOME/.config/tmp/prename/c1`" = true ]; then
echo enabled > $HOME/.config/tmp/prename/c1v
else
echo disabled > $HOME/.config/tmp/prename/c1v
fi
if [ "`cat $HOME/.config/tmp/prename/c2`" = true ]; then
echo enabled > $HOME/.config/tmp/prename/c2v
else
echo disabled > $HOME/.config/tmp/prename/c2v
fi
if [ "`cat $HOME/.config/tmp/prename/c3`" = true ]; then
echo enabled > $HOME/.config/tmp/prename/c3v
else
echo disabled > $HOME/.config/tmp/prename/c3v
fi
if [ "`cat $HOME/.config/tmp/prename/c4`" = true ]; then
echo enabled > $HOME/.config/tmp/prename/c4v
else
echo disabled > $HOME/.config/tmp/prename/c4v
fi
if [ "`cat $HOME/.config/tmp/prename/c5`" = true ]; then
echo enabled > $HOME/.config/tmp/prename/c5v
else
echo disabled > $HOME/.config/tmp/prename/c5v
fi
NEWDIR="`pwd`"
if ! [ -f $HOME/.config/tmp/prename/directory2 ]; then
echo "$NEWDIR" > $HOME/.config/tmp/prename/directory2
fi
if ! [ -d "`cat $HOME/.config/tmp/prename/directory2`" ]; then
echo "$NEWDIR" > $HOME/.config/tmp/prename/directory2
fi
if ! [ -f $HOME/.config/tmp/prename/dir ]; then
echo / > $HOME/.config/tmp/prename/dir
fi
OLDDIR="`cat $HOME/.config/tmp/prename/dir`"
if [ -d "$OLDDIR" ]; then
cd "$OLDDIR" 2>/dev/null
else
echo "$NEWDIR" > $HOME/.config/tmp/prename/dir
fi
export MAIN_DIALOG="
INFO
$HOME/.config/tmp/prename/directory2
300160DIR
cat \$HOME/.config/tmp/prename/dir
echo cd \$DIR | tee \$HOME/.config/tmp/prename/directoryecho ls -F -A | tee -a \$HOME/.config/tmp/prename/directorychmod a+x \$HOME/.config/tmp/prename/directoryls -F -A \"\$DIR\" | tee \$HOME/.config/tmp/prename/directory2refresh:INFOCHECKBOX1`cat \$HOME/.config/tmp/prename/c1`if false disable:NEWif false disable:OLDif true enable:NEWif true enable:OLDOLD
cat \$HOME/.config/tmp/prename/old
`cat \$HOME/.config/tmp/prename/c1v`NEW
cat \$HOME/.config/tmp/prename/new
`cat \$HOME/.config/tmp/prename/c1v`CHECKBOX5`cat \$HOME/.config/tmp/prename/c5`if false disable:NEW1if true enable:NEW1NEW1
cat \$HOME/.config/tmp/prename/new1
`cat \$HOME/.config/tmp/prename/c5v`CHECKBOX2`cat \$HOME/.config/tmp/prename/c2`if false disable:RADIOBUTTON1if false disable:RADIOBUTTON2if true enable:RADIOBUTTON1if true enable:RADIOBUTTON2RADIOBUTTON1`cat \$HOME/.config/tmp/prename/r1``cat \$HOME/.config/tmp/prename/c2v`RADIOBUTTON2`cat \$HOME/.config/tmp/prename/r2``cat \$HOME/.config/tmp/prename/c2v`CHECKBOX3`cat \$HOME/.config/tmp/prename/c3`if false disable:RADIOBUTTON3if false disable:RADIOBUTTON4if true enable:RADIOBUTTON3if true enable:RADIOBUTTON4RADIOBUTTON3`cat \$HOME/.config/tmp/prename/r3``cat \$HOME/.config/tmp/prename/c3v`RADIOBUTTON4`cat \$HOME/.config/tmp/prename/r4``cat \$HOME/.config/tmp/prename/c3v`CHECKBOX4`cat \$HOME/.config/tmp/prename/c4`if false disable:RADIOBUTTON5if false disable:RADIOBUTTON6if false disable:RADIOBUTTON7if true enable:RADIOBUTTON5if true enable:RADIOBUTTON6if true enable:RADIOBUTTON7RADIOBUTTON5`cat \$HOME/.config/tmp/prename/r5``cat \$HOME/.config/tmp/prename/c4v`RADIOBUTTON6`cat \$HOME/.config/tmp/prename/r6``cat \$HOME/.config/tmp/prename/c4v`RADIOBUTTON7`cat \$HOME/.config/tmp/prename/r7``cat \$HOME/.config/tmp/prename/c4v`RADIOBUTTON8`cat \$HOME/.config/tmp/prename/r8`RADIOBUTTON9`cat \$HOME/.config/tmp/prename/r9`
"
RESULTS="`$GTKDIALOG --program=MAIN_DIALOG --center`"
###exit the program if the X button is pushed
if [ "`echo $RESULTS | grep abort`" != "" ]; then
exit 0
fi
##incase quit was selected, let's exit the program
if [ "`echo $RESULTS | grep EXIT_NOW`" != "" ]; then
exit 0
fi
RENAME="sed \"s/ / /g\""
if [ "`cat $HOME/.config/tmp/prename/c1`" = true ]; then
OLD=`cat $HOME/.config/tmp/prename/old`
NEW=`cat $HOME/.config/tmp/prename/new`
if [ "$OLD" = "" ]; then
OLD="$NEW"
fi
RENAME="sed \"s/$OLD/$NEW/g\""
fi
APPEND="sed 's/^//'"
if [ "`cat $HOME/.config/tmp/prename/c5`" = true ]; then
APPEND="sed 's/^/`cat $HOME/.config/tmp/prename/new1`/'"
fi
CASE="sed \"s/ / /g\""
if [ "`cat $HOME/.config/tmp/prename/c2`" = true ]; then
if [ "`cat $HOME/.config/tmp/prename/r1`" = true ]; then
CASE="sed \"y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/\""
else
CASE="sed \"y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/\""
fi
fi
LIST="-F | sed 's/*//g' | sed 's/@//g'"
if [ "`cat $HOME/.config/tmp/prename/c3`" = true ]; then
if [ "`cat $HOME/.config/tmp/prename/r3`" = true ]; then
LIST="-F | sed 's/*//g' | grep -v \"@\" | grep -v \"/\""
else
LIST='-d */'
fi
fi
SPACE="sed \"s/ / /g\""
if [ "`cat $HOME/.config/tmp/prename/c4`" = true ]; then
if [ "`cat $HOME/.config/tmp/prename/r5`" = true ]; then
SPACE="sed \"s/ /-/g\""
fi
if [ "`cat $HOME/.config/tmp/prename/r6`" = true ]; then
SPACE="sed \"s/ /_/g\""
fi
if [ "`cat $HOME/.config/tmp/prename/r7`" = true ]; then
SPACE="sed \"s/ //g\""
fi
fi
if [ "`cat $HOME/.config/tmp/prename/r8`" = true ]; then
HIDDEN="-1"
else
HIDDEN="-A"
fi
echo ls "$HIDDEN" "$LIST" > $HOME/.config/tmp/prename/prenamelist
chmod a+x $HOME/.config/tmp/prename/prenamelist
cd "`cat $HOME/.config/tmp/prename/dir`"
rm -f $HOME/.config/tmp/prename/prenametemp2
$HOME/.config/tmp/prename/prenamelist > $HOME/.config/tmp/prename/prenamelist2
NUM=`cat $HOME/.config/tmp/prename/prenamelist2 | wc -l | sed 's/ //g'`
a=1
b=`expr "$NUM" + 1`
export MAIN_DIALOG2="
"
RESULTS=`$GTKDIALOG --program=MAIN_DIALOG2 --center`
if [ "`echo "$RESULTS" | grep GO_BACK`" != "" ]; then
/usr/local/bin/prename &
exit 0
fi
###exit the program if the X button is pushed
if [ "`echo $RESULTS | grep abort`" != "" ]; then
exit 0
fi
##incase quit was selected, let's exit the program
if [ "`echo $RESULTS | grep EXIT_NOW`" != "" ]; then
exit 0
fi
FILES=""
$HOME/.config/tmp/prename/prenamelist | while read FILES
do
if [ "`echo "$FILES" | grep '/'`" != "" ]; then
FILES="`echo "$FILES" | sed 's/\///g'`"
fi
echo "echo \""$FILES"\" | "$APPEND" | "$RENAME" | "$CASE" | "$SPACE"" > $HOME/.config/tmp/prename/newname
chmod a+x $HOME/.config/tmp/prename/newname
NEWFILE=`$HOME/.config/tmp/prename/newname`
if [ "$FILES" != "$NEWFILE" ]; then
if [ "`echo "$NEWFILE" | grep '/'`" != "" ]; then
NEWFILE="`echo "$NEWFILE" | sed 's/\///g'`"
fi
mv "$FILES" "$NEWFILE"
fi
done
/usr/local/bin/prename &
exit 0