Skip to Content.
Sympa Menu

baslinux - [BL] Simplistic File Manager - Script

baslinux AT lists.ibiblio.org

Subject: Baslinux mailing list

List archive

Chronological Thread  
  • From: Lee Forrest <lforrestster AT gmail.com>
  • To: baslinux AT lists.ibiblio.org
  • Subject: [BL] Simplistic File Manager - Script
  • Date: Wed, 7 Feb 2007 04:18:09 +0000

#!/bin/sh

#sfm.sh version 0.1

# must be sourced: '. swm.sh' (alias to a single letter)
# so the script runs in the same shell, not a subshell
# and the cd will actually work and your aliases will be available

# change default pager if desired

pager="/usr/bin/less -c"

# if there is no such pager as above, or it hasn't been set, use
# $PAGER (set in /etc/profile, or it should be)

#### End Configuration Section

#### a bunch of functions called by main script or other functions

#These two functions are called with main menu items "file -L" and "ls -Als"
#file is set to dereference symbolic links -- use "ls -Als" to see them

option1 () {
clear
/bin/ls -A | xargs file -L | $pager
}

option2 () {
clear
/bin/ls -Als | $pager
}

#formatting functions

form1 () {
printf "%-20s" "[${num}] $file"
[ `dc $num 5 mod p` = 0 ] && echo
}

form2 () {
printf "%-20s" "[${num}] $file"
[ `dc $num 4 mod p` = 0 ] && echo
}


form3 () {
printf "%-20s" "[${num}] $file"
[ `dc $num 3 mod p` = 0 ] && echo
}

# for COMMAND and SAVE submenus because file names have
# a tendency to be longer than directory names

form4 () {
printf "%-24s" "[${num}] $file"
[ `dc $num 4 mod p` = 0 ] && echo
}

form5 () {
printf "%-24s" "[${num}] $file"
[ `dc $num 3 mod p` = 0 ] && echo
}

size () {
if ! [ -x /bin/stty ]
then formx=form5
elif [ $columns -ge 100 ]
then formx=form4
else formx=form5
fi
}

command () {

size

clear
while : ; do
num=1
set "MAIN MENU" `/bin/ls -AF $PWD | grep -v "/" | sed 's/@//' 2> /dev/null`
for file in "$@" ; do
$formx
num=`expr $num + 1`
done
echo

read -p "Command: " a b c d e f g h i j k l m n o p q r s t u v w x y z
echo
for var in $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q $r $s $t $u $v
$w $x $y $z
do
case "$var" in
[0-9]*)
if [ $var = 1 ]
then return
fi
eval num2=\$\{$var\} > /dev/null 2>&1
echo -n "${num2} " >> /tmp/sfm-22-$string
;;
ZZ)
echo -n `cat /tmp/sfm-11-$string 2> /dev/null` >> /tmp/sfm-22-$string
/bin/rm /tmp/sfm-11-$string 2> /dev/null
;;
.) echo -n " $PWD " >> /tmp/sfm-22-$string ;;
*)
echo -n "${var} " >> /tmp/sfm-22-$string
;;
esac
done
eval `cat /tmp/sfm-22-$string 2> /dev/null` # 2> /dev/null
echo
/bin/rm /tmp/sfm-22-$string 2> /dev/null

done

}

save () {

size

clear
#while : ; do
num=1
set `/bin/ls -AF $PWD | grep -v "/" | sed 's/@//' 2> /dev/null`
for file in "$@" ; do
$formx
num=`expr $num + 1`
done
printf "%s\n"

/bin/rm /tmp/sfm-11-$string 2> /dev/null

read -p "Save: " a b c d e f g h i j k l m n o p q r s t u v w x y z
echo
for var in $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q $r $s $t $u $v
$w $x $y $z
do
case "$var" in
[0-9]*)
eval num3=\$\{$var\} > /dev/null 2>&1
if [ -f "${num3}" ] ; then
echo -n "${PWD}/${num3} " >> /tmp/sfm-11-$string
else continue
fi
esac
done

#done

return

}

###### Main Script

# if the pager in $pager variable doesn't exist, etc., use $PAGER
# (set in /etc/profile, or it should be)

if ! [ -x $pager ]
then pager=$PAGER
fi

#select the right number of columns output for window size

columns=`/bin/stty size | sed -n 's/^\(.* \)\(.*\)/\2/p' 2> /dev/null`

#The current 24-hour time will give a string that's unique in 24
#hours to tack on the end of the names of both tempfiles so that
#many instances of sfm can be run concurrently without stepping
#on each other.

time=`date +%T`
string=$time

#get the directory you started sfm in and save it in a variable
#so that it won't change at all during swm session. So you can
#always find your way back home in a jiff

start_dir=$PWD
START_DIR=$start_dir

#choose which of the formatting functions to use for formatting
#the screen depending on how many columns your screen has if
#there's no /bin/stty, then choose form2 - change to form3 if
#you have less than 80 columns on the screen - just the first
#occurence below

if ! [ -x /bin/stty ]
then form=form2 #first occurence
elif [ $columns -ge 100 ]
then form=form1
elif [ $columns -ge 80 ]
then form=form2
else form=form3
fi

#use 'while : do' loop to keep swm starting over at the top of
#the loop unless explicitly killed; ":" means "true" which means
#"do nothing".

while :; do

clear
num=1

#make the names below accessible through the positional paramaters
#$1 $2, etc.

set "EXIT" "COMMAND" "SAVE" "file -L" "ls -Als" "/" "/bin" "/dev" "/etc"
"/home" "/lib" "/proc" "/root" "/sbin" "/usr" "/var" "STARTDIR" "LASTDIR"
".." `/bin/ls -F $PWD | grep '/' 2> /dev/null`

#loop through them and assign numbers

for file in "$@" ; do
$form
num=`expr $num + 1`
done

printf "%s\n"

#present a prompt to take input

read -p "$PWD: " a

case "$a" in

[0-9]*)
eval num1=\$\{$a\} > /dev/null 2>&1
if test -d "$num1" ; then cd "$num1"
elif [ "$num1" = "STARTDIR" ] ; then
cd $START_DIR
elif [ "$num1" = "LASTDIR" ] ; then
cd $OLDPWD
elif [ "$num1" = "file -L" ] ; then
option1
elif [ "$num1" = "ls -Als" ] ; then
option2
elif [ "$num1" = "COMMAND" ] ; then
command
elif [ "$num1" = "SAVE" ] ; then
save
elif [ "$num1" = "EXIT" ] ; then
/bin/rm /tmp/sfm-11-$string /tmp/sfm-22-$string > /dev/null 2>&1
return
else continue; fi
;;
*)
clear
echo -n "$PWD - "
/bin/ls -AFs $PWD
read x
case "$x" in
*) continue ;;
esac
;;
*) continue ;;
esac

done

## Thanks to Steven, founder of BasicLinux, for help with the formatting.
## http://www.basiclinux.com.ru
## Copywrong Wed Feb 7 2007 Lee Forrest lforrestster AT gmail.com

/quote

Lee

--
BasicLinux: Small is Beautiful
http://www.basiclinux.com.ru




  • [BL] Simplistic File Manager - Script, Lee Forrest, 02/07/2007

Archive powered by MHonArc 2.6.24.

Top of Page