SlocateGUI with apptree
@pelo
Sorry for my always hurried and abbreviated explanations. Yes I make too many assumptions about the reader.
After you input your search term you then get a gui to select which partition to search 1 or many; system or external partition.
If you want always to search every partition then yes remove /mnt from /etc/updatedb.conf (not recommended!)
The link command format is 'ln -s "/path/file" "/path/file-link-name"', but you do not need to worry about that just choose file to link and then give the link path/name.
apptree is a separate script at the moment. It builds a pet/sfs file from a /root/.packages/'app-name.files' list.
Best is just to install it and try it but be careful with the 'rm' or 'mv' commands, as they work really really well. Worst case scenario is that you might have to reboot with no savefile.
I hope this helps.
stemsee
Sorry for my always hurried and abbreviated explanations. Yes I make too many assumptions about the reader.
After you input your search term you then get a gui to select which partition to search 1 or many; system or external partition.
If you want always to search every partition then yes remove /mnt from /etc/updatedb.conf (not recommended!)
The link command format is 'ln -s "/path/file" "/path/file-link-name"', but you do not need to worry about that just choose file to link and then give the link path/name.
apptree is a separate script at the moment. It builds a pet/sfs file from a /root/.packages/'app-name.files' list.
Best is just to install it and try it but be careful with the 'rm' or 'mv' commands, as they work really really well. Worst case scenario is that you might have to reboot with no savefile.
I hope this helps.
stemsee
Musher0, our canadian colleague will explain me more
Musher0, our canadian colleague will explain me more, as he settled in Quebec, and he is bilingual french english
slocate explained in french
slocate explained in french
slocategui update. Just copy this to /usr/bin/slocategui
Code: Select all
# !/bin/sh
# copyright (c) 2015 Marcos M Contant
# all rights reserved
#yad splash --text "disclaimer use at your own risk. No responsibility accepted.
#Using this app will backup your fstab
#and add entries to /etc/fstab if not already there.
#To reset fstab and remove .db files in term type
#slocategui reset'
#Press Enter"
#read dummy
# set path definition for puppy or debiandog
# lighthouse also has /media
pathdef () {
if [ -d /live* ]; then
path=media
else
path=mnt
fi
}
pathdef
#[[ -f /mnt/Home ]] && ln -fs /mnt/Home /mnt/sdz1
#[[ -f /mnt/home ]] && ln -fs /mnt/home /mnt/sdz2
if [ -e /var/lib/slocate/1slocate.db ]; then
rename 1slocate.db slocate.db /var/lib/slocate/1slocate.db
fi
added=`cat /etc/group | grep 'slocate'`
if [ -z "$added" ]; then
addgroup -S slocate &> /dev/null
fi
# Restore fstab, remove flags and databases named slocate.db
if [ "$1" = reset ]; then
for file in `probepart -m | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
do
[[ ! -d /"$path"/"$file" ]] && mkdir /"$path"/"$file"
mount -a
sleep 3
up=`mount -l | grep -e 'sd[a-z][1-9]' | grep "$file"`
if [[ -z "$up" ]]; then
mount /dev/"$file" /"$path"/"$file"
fi
[[ -e /"$path"/"$file"/slocate.db ]] && rm -f /"$path"/"$file"/slocate.db
[[ -e /"$path"/"$file"/.did ]] && rm -f /"$path"/"$file"/.did
[[ -e /"$path"/"$file"/.didex ]] && rm -f /"$path"/"$file"/.didex
done
[[ -e $HOME/.did ]] && rm $HOME/.did
rm -f /var/lib/slocate/*
[[ -f /etc/fstab-backup ]] && mv /etc/fstab-backup /etc/fstab
[[ -f /tmp/result ]] && rm /tmp/result
[[ -f /tmp/*.m3u ]] && rm /tmp/*.m3u
exit 0
fi
# backup fstab, create blkid.txt for UUID to fstab
[[ ! -f /etc/fstab-backup ]] && cp /etc/fstab /etc/fstab-backup
rm -f /tmp/blkid.txt
blkid | grep --invert-match 'loop' > /tmp/blkid.txt
sed -i 's/\"//g' /tmp/blkid.txt
# This function adds partition entries to fstab if not already there.
idfn () {
while read line
do
ud=`echo "$line" | cut -f2 -d ' '`
fs=`echo "$line" | rev | cut -f1 -d '=' | rev`
mntpnt=`echo "$line" | cut -f1 -d ':' | rev | cut -f1 -d '/' | rev`
yn=`cat /etc/fstab | grep "$ud"`
case "$fs" in
ntfs) drvr="ntfs-3g"
extra=" defaults,locale=en_GB.utf8 0 0"
if [[ -z "$yn" ]]; then
echo "'$ud' /'$path'/'$mntpnt' '$drvr' '$extra' " >> /etc/fstab # ntfs partition fstab entry
fi
;;
ext[2-4]) extra=" defaults 0 2"
if [[ -z "$yn" ]]; then
echo "'$ud' /'$path'/'$mntpnt' '$drvr' '$fs' '$extra' " >> /etc/fstab # ext filesystem fstab entry
fi
;;
vfat)
extra="defaults,user,exec,uid=0,gid=0,dmask=027,umask=137 0 0"
if [[ -z "$yn" ]]; then
echo "'$ud' /'$path'/'$mntpnt' '$drvr' '$fs' '$extra' " >> /etc/fstab # vfat/fat32 fstab entry
fi
;;
hfsplus) extra="rw,exec,auto,users 0 0"
drvr="hfsplus"
if [[ -z "$yn" ]]; then
echo "'$ud' /'$path'/'$mntpnt' '$drvr' '$fs' '$extra' " >> /etc/fstab # mac hfs+ fstab entry
fi
;;
esac
sed -i "s/'//g" /etc/fstab
sed -i 's/"//g' /etc/fstab
sed -i 's/ntfs-3g ext/ext/g' /etc/fstab
sed -i 's/ntfs-3g vfat/vfat/g' /etc/fstab
sed -i 's/ntfs-3g hfsplus/hfsplus/g' /etc/fstab
touch /"$path"/"$mntpnt"/.didex
done < /tmp/blkid.txt
rm -f /tmp/blkid.txt
}
for file in `probepart -m | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
do
if [ ! -e /"$path"/"$file"/.didex ]; then
idfn
fi
done
# yad gui input search term
filext=`yad --title="Find files by stemsee" --text="What are you looking for?:
e.g. *.mp3" --field="Type file name or extension:" --window-icon="" --entry`
if [[ -z "$filext" ]]; then
exit 1
fi
# store and format search term
echo $filext > /tmp/name
sed -i 's/^/nm=/' /tmp/name
# create root db and make searchable
rootdbfn () {
slocate -u -e /dev,/proc,/tmp,/aufs,/usr/tmp,/var/tmp,/var/run,/initrd,/"$path", -o /var/lib/slocate/slocate.db | yad --window-icon="" --width=300 --title "Creating Database for '/'" --progress --auto-close --pulsate
chmod a+x /var/lib/slocate/slocate.db
ln -fs /var/lib/slocate/slocate.db /var/lib/slocate/sys
touch $HOME/.did
}
# has root database been created?
if [ ! -e /var/lib/slocate/slocate.db ]; then
rootdbfn
else
slocate -u -o /var/lib/slocate/slocate.db &
ln -fs /var/lib/slocate/slocate.db /var/lib/slocate/sys
fi
# create external partition db and make searchable
extdbfn () {
for file in `probepart -m | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
do
emp=$(ls -A /$path/$file/)
if [[ -z "$emp" ]]; then
mkdir /"$path"/"$file"
mount -a
sleep 3
fi
up=`mount -l | grep -e 'sd[a-z][1-9]' | grep "$file"`
if [[ -z "$up" ]]; then
mount /dev/"$file" /"$path"/"$file"
sleep 4
fi
if [[ ! -e /"$path"/"$file"/slocate.db ]]; then
slocate -U /"$path"/"$file"/ -o /"$path"/"$file"/slocate.db | yad --progress --auto-close --pulsate --window-icon="" --width=300 --title "Creating Database '$file'" &
elif [[ -e /"$path"/"file"/slocate.db ]]; then
slocate -U -o /"$path"/"$file"/slocate.db | yad --progress --auto-close --pulsate --window-icon="" --width=300 --title "Updating Database '$file'" &
fi
ln -fs /"$path"/"$file"/slocate.db /var/lib/slocate/"$file"
touch /"$path"/"$file"/.did
done
}
extdbfn
sync
#update DBs if in existence
for i in `ls "$path"`; do slocate -U /"$path"/"$i" -e /dev,/proc,/tmp,/aufs,/usr/tmp,/var/tmp,/var/run,/initrd,/"$path", -o slocate.db; done &
# choose database to search
pathfn () {
for F in `ls /var/lib/slocate/* | grep --invert-match 'slocate.db' `
do
if [ -L "$F" ]; then
if readlink -q "$F" >/dev/null ; then
echo
else
rm /var/lib/slocate/"$F"
fi
fi
done
pathto=`ls /var/lib/slocate/* | grep --invert-match 'slocate.db' | yad --geometry=300x600 --list --column="Databases available" --multiple --title="Find files in" --text="Which drive to search?:
e.g. sdb5 or sys for /." --window-icon="" --separator ' '`
}
YADPID=$(ps -eo pid,cmd | grep -v grep | grep "yad --progress" | tr ' ' '\n' | wc -l )
if [ "$YADPID" = 0 ]; then
pathfn
fi
# checks empty variable
if [ -z "$pathto" ]; then
exec "$0"
fi
#if [[ "$pathto" ]]; then
# yad splash --text " Please wait: Now searching \n'$pathto'" &
#fi
# search databases
syste=`echo $pathto | grep 'sys'`
if [ ! -z "$syste" ]; then
echo
else
rename slocate.db 1slocate.db /var/lib/slocate/slocate.db
touch /var/lib/slocate/slocate.db
fi
pathto=`echo $pathto | tr ' ' ':' | tr '\n' ':' | grep --invert-match 'sys'`
#part=`echo $pathto | cut -f1 -d '\n'`
slocate -i "$filext" --database="$pathto" > /tmp/"$filext"-result
# multiple file/dir selection gui
select=$(cat /tmp/"$filext"-result | yad --window-icon="" --title "SlocateGUI" --list --multiple --center --height="400" --width="300" --column="$filext:" --print-column="1" --separator="\n")
ret=$?
[[ $ret -eq 1 ]] && exit 0
if [[ $ret -eq 0 ]]; then
# gui command to execute input box
app=`yad --window-icon="" --title="Type Command + space" --text="command + options+space:
e.g. vlc " --field="Add £ for multiples\n e.g. petget +£ \n Type command:" --entry`
if [[ -z "$app" ]]; then
exit 1
fi
echo "$select" > /tmp/list-"$filext".m3u # create file list as 'search-term'.m3u playlist with blank lines in between
if [[ -h "$select" ]]; then
select=`realpath $select` # incase of link
fi
if [[ "$app" = rm ]]; then # delete files/dirs
while read line
do
rm -rf "$line"
done < /tmp/list-"$filext".m3u
elif [[ `echo "$app"| rev | cut -f1 -d ' '` = £ ]]; then # loop over list for given commands + options
app=`echo "$app" | cut -f1 -d '£'`
while read line
do
dirr=`echo $line | rev | cut -f2,3,4,5,6,7,8,9,10,11,12,13,14 -d '/' | rev`
line=`echo $line | rev | cut -f1 -d '/' | rev`
cd "$dirr"
"$app""$line"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = mv ]]; then # move files/dirs to 'gui input box'
location=`yad --window-icon="" --geometry=250 --title="Type Path To Destination" --text="Path:
e.g. /root/my-documents" --field="Type Path:" --entry`
if [[ -z "$location" ]]; then
exit 1
fi
while read line
do
mv "$line" "$location"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = ln ]]; then # link single file
linknm=`yad --window-icon="" --geometry=200 --title="Type link name" --entry`
if [[ -z "$linknm" ]]; then
exit 1
fi
line1=`echo $select | cut -f2,3,4,5,6,7,8,9,10 -d '/'`
ln -s "$select" "$line1"/"$linknm"
elif [[ "$app" = rename ]]; then # rename single file
newname=`yad --window-icon="" --geometry=200 --title="Type new name" --entry`
if [[ -z "$newname" ]]; then
exit 1
fi
line=`echo $select | cut -f1 -d '/'`
rename "$line" "$newname" "$select"
elif [[ "$app" = replace ]]; then # replace string or symbol except apostrophe and backslash (but possible)
replace=`yad --window-icon="" --geometry=440 --title="Format: 'ReplaceThis'WithThis' " --text "But not ' nor /:" --entry`
if [[ -z "$replace" ]]; then
exit 1
fi
t1=`echo "$replace" | cut -f2 -d "'"`
t2=`echo "$replace" | cut -f3 -d "'"`
while read line
do
select2=`echo $line | rev | cut -f1 -d '/' | rev`
rp=`echo "$select2" | tr "$t1" "$t2"`
rename "$select2" "$rp" "$line"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = cp ]]; then # copy files/dirs to 'gui input box'
location=`yad --window-icon="" --geometry=260 --title="Type Path To Destination" --text="Path:
e.g. /root/my-documents" --field="Type Path:" --entry`
if [[ -z "$location" ]]; then
exit 1
fi
while read line
do
cp -rf "$line" "$location"
done < /tmp/list-"$filext".m3u
else
playlist=$(yad --window-icon="" --width=430 --title "Do you want to open as a playlist? y or n?" --entry) #gui to open as playlist or individual files
case $playlist in
y) "$app" /tmp/list-"$filext".m3u & # app opens playlist
;;
n) "$app" "$select" & # execute command on file
;;
g) geany /tmp/list-"$filext".m3u & # open file list in geany
;;
esac
fi
fi
if [ -e /var/lib/slocate/1slocate.db ]; then
rename 1slocate.db slocate.db /var/lib/slocate/1slocate.db
fi
rm /tmp/result # remove search results list
rm /tmp/"$filext"-result
for i in "$pathto"; do slocate -U /"$path"/"$i" -o slocate.db; done &
sync
exec "$0" & # open again for convenience to search new term
Last edited by stemsee on Wed 27 Jan 2016, 09:29, edited 3 times in total.
I could do with some help to simplify adding slocate group to /etc/group
This is the code I have that greps for slocate and if not found adds with a set number 159.
Ideally I want the code to also check for a spare number but I couldn't work out how to code it. But something like while slocate is not in /etc/group and 159 is not in group then add line slocate159: to /etc/group. If 159 is used then add 1 to 159 and to the sum of that until a free number is found than add the line with that value.
This is the code I have that greps for slocate and if not found adds with a set number 159.
Code: Select all
added=`cat /etc/group | grep 'slocate'`
if [ -z "$added" ]; then
echo "slocate:x:159:" >> /etc/group
fi
Perfected! Finally!!
So now you can search multiple partitions or the running / sys(-tem) ... not both! Although it is possible to have all file data stored in sys db.
So now you can search multiple partitions or the running / sys(-tem) ... not both! Although it is possible to have all file data stored in sys db.
Code: Select all
# !/bin/sh
# copyright (c) 2015 Marcos M Contant
# all rights reserved
# for i in `ls /mnt/`; do slocate -U /mnt/"$i" -o slocate.db; done
#yad splash --text "disclaimer use at your own risk. No responsibility accepted.
#Using this app will backup your fstab
#and add entries to /etc/fstab if not already there.
#To reset fstab and remove .db files in term type
#slocatgui reset'
#Press Enter"
#read dummy
# set path definition for puppy or debiandog
# lighthouse also has /media
pathdef () {
if [ -d /live* ]; then
path=media
else
path=mnt
fi
}
pathdef
#[[ -f /mnt/Home ]] && ln -fs /mnt/Home /mnt/sdz1
#[[ -f /mnt/home ]] && ln -fs /mnt/home /mnt/sdz2
if [ -e /var/lib/slocate/1slocate.db ]; then
rename 1slocate.db slocate.db /var/lib/slocate/1slocate.db
fi
added=`cat /etc/group | grep 'slocate'`
if [ -z "$added" ]; then
echo "slocate:x:159:" >> /etc/group
fi
# Restore fstab, remove flags and databases named slocate.db
if [ "$1" = reset ]; then
for file in `probepart -m | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
do
[[ ! -d /"$path"/"$file" ]] && mkdir /"$path"/"$file"
mount -a
sleep 3
up=`mount -l | grep -e 'sd[a-z][1-9]' | grep "$file"`
if [[ -z "$up" ]]; then
mount /dev/"$file" /"$path"/"$file"
fi
[[ -e /"$path"/"$file"/slocate.db ]] && rm -f /"$path"/"$file"/slocate.db
[[ -e /"$path"/"$file"/.did ]] && rm -f /"$path"/"$file"/.did
[[ -e /"$path"/"$file"/.didex ]] && rm -f /"$path"/"$file"/.didex
done
[[ -e $HOME/.did ]] && rm $HOME/.did
rm -f /var/lib/slocate/*
[[ -f /etc/fstab-backup ]] && mv /etc/fstab-backup /etc/fstab
[[ -f /tmp/result ]] && rm /tmp/result
[[ -f /tmp/*.m3u ]] && rm /tmp/*.m3u
exit 0
fi
# backup fstab, create blkid.txt for UUID to fstab
[[ ! -f /etc/fstab-backup ]] && cp /etc/fstab /etc/fstab-backup
rm -f /tmp/blkid.txt
blkid | grep --invert-match 'loop' > /tmp/blkid.txt
sed -i 's/\"//g' /tmp/blkid.txt
# This function adds partition entries to fstab if not already there.
idfn () {
while read line
do
ud=`echo "$line" | cut -f2 -d ' '`
fs=`echo "$line" | rev | cut -f1 -d '=' | rev`
mntpnt=`echo "$line" | cut -f1 -d ':' | rev | cut -f1 -d '/' | rev`
yn=`cat /etc/fstab | grep "$ud"`
case "$fs" in
ntfs) drvr="ntfs-3g"
extra=" defaults,locale=en_GB.utf8 0 0"
if [[ -z "$yn" ]]; then
echo "'$ud' /'$path'/'$mntpnt' '$drvr' '$extra' " >> /etc/fstab # ntfs partition fstab entry
fi
;;
ext[2-4]) extra=" defaults 0 2"
if [[ -z "$yn" ]]; then
echo "'$ud' /'$path'/'$mntpnt' '$drvr' '$fs' '$extra' " >> /etc/fstab # ext filesystem fstab entry
fi
;;
vfat)
extra="defaults,user,exec,uid=0,gid=0,dmask=027,umask=137 0 0"
if [[ -z "$yn" ]]; then
echo "'$ud' /'$path'/'$mntpnt' '$drvr' '$fs' '$extra' " >> /etc/fstab # vfat/fat32 fstab entry
fi
;;
hfsplus) extra="rw,exec,auto,users 0 0"
drvr="hfsplus"
if [[ -z "$yn" ]]; then
echo "'$ud' /'$path'/'$mntpnt' '$drvr' '$fs' '$extra' " >> /etc/fstab # mac hfs+ fstab entry
fi
;;
esac
sed -i "s/'//g" /etc/fstab
sed -i 's/"//g' /etc/fstab
sed -i 's/ntfs-3g ext/ext/g' /etc/fstab
sed -i 's/ntfs-3g vfat/vfat/g' /etc/fstab
sed -i 's/ntfs-3g hfsplus/hfsplus/g' /etc/fstab
touch /"$path"/"$mntpnt"/.didex
done < /tmp/blkid.txt
rm -f /tmp/blkid.txt
}
for file in `probepart -m | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
do
if [ ! -e /"$path"/"$file"/.didex ]; then
idfn
fi
done
# yad gui input search term
filext=`yad --title="Find files by stemsee" --text="What are you looking for?:
e.g. *.mp3" --field="Type file name or extension:" --window-icon="" --entry`
if [[ -z "$filext" ]]; then
exit 1
fi
# store and format search term
echo $filext > /tmp/name
sed -i 's/^/nm=/' /tmp/name
# create root db and make searchable
rootdbfn () {
slocate -u -e /dev,/proc,/tmp,/aufs,/usr/tmp,/var/tmp,/var/run,/initrd,/"$path", -o /var/lib/slocate/slocate.db | yad --window-icon="" --width=300 --title "Creating Database for '/'" --progress --auto-close --pulsate
chmod a+x /var/lib/slocate/slocate.db
ln -fs /var/lib/slocate/slocate.db /var/lib/slocate/sys
touch $HOME/.did
}
# has root database been created?
if [ ! -e /var/lib/slocate/slocate.db ]; then
rootdbfn
exec "$0"
exit 0
else
slocate -u -e /dev,/proc,/tmp,/aufs,/usr/tmp,/var/tmp,/var/run,/initrd,/"$path", -o /var/lib/slocate/slocate.db &
ln -fs /var/lib/slocate/slocate.db /var/lib/slocate/sys
fi
# create external partition db and make searchable
extdbfn () {
for file in `probepart -m | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
do
emp=$(ls -A /$path/$file/)
if [[ -z "$emp" ]]; then
mkdir /"$path"/"$file"
mount -a
sleep 3
fi
up=`mount -l | grep -e 'sd[a-z][1-9]' | grep "$file"`
if [[ -z "$up" ]]; then
mount /dev/"$file" /"$path"/"$file"
sleep 4
fi
if [[ ! -e /"$path"/"$file"/slocate.db ]]; then
slocate -U /"$path"/"$file"/ -o /"$path"/"$file"/slocate.db | yad --progress --auto-close --pulsate --window-icon="" --width=300 --title "Creating Database '$file'" &
elif [[ -e /"$path"/"file"/slocate.db ]]; then
slocate -U -o /"$path"/"$file"/slocate.db | yad --progress --auto-close --pulsate --window-icon="" --width=300 --title "Updating Database '$file'" &
fi
ln -fs /"$path"/"$file"/slocate.db /var/lib/slocate/"$file"
touch /"$path"/"$file"/.did
done
}
extdbfn
sync
#update DBs if in existence
for i in `ls "$path"`; do slocate -U /"$path"/"$i" -e /dev,/proc,/tmp,/aufs,/usr/tmp,/var/tmp,/var/run,/initrd,/"$path", -o /"$path"/"$i"/slocate.db; done &
# choose database to search
pathfn () {
for F in `ls /var/lib/slocate/* | grep --invert-match 'slocate.db' `
do
if [ -L "$F" ]; then
if readlink -q "$F" >/dev/null ; then
echo
else
rm /var/lib/slocate/"$F"
fi
fi
done
pathto=`ls /var/lib/slocate/* | grep --invert-match 'slocate.db' | yad --geometry=300x400 --list --column="Search partition/s or sys(-tem)?" --multiple --title="Find files in these partitions?" --window-icon="" --separator ' '`
}
YADPID=$(ps -eo pid,cmd | grep -v grep | grep "yad --progress" | tr ' ' '\n' | wc -l )
if [ "$YADPID" = 0 ]; then
pathfn
fi
# checks empty variable
if [ -z "$pathto" ]; then
exec "$0"
fi
#if [[ "$pathto" ]]; then
# yad splash --text " Please wait: Now searching \n'$pathto'" &
#fi
# search databases
syste=`echo $pathto | grep 'sys'`
if [ ! -z "$syste" ]; then
echo
else
rename slocate.db 1slocate.db /var/lib/slocate/slocate.db
touch /var/lib/slocate/slocate.db
fi
pathto=`echo $pathto | tr ' ' ':' | tr '\n' ':' | grep --invert-match 'sys'`
#part=`echo $pathto | cut -f1 -d '\n'`
slocate -i "$filext" --database="$pathto" > /tmp/"$filext"-result
# multiple file/dir selection gui
select=$(cat /tmp/"$filext"-result | yad --window-icon="" --title "SlocateGUI" --list --multiple --center --height="400" --width="300" --column="$filext:" --print-column="1" --separator="\n")
ret=$?
[[ $ret -eq 1 ]] && exit 0
if [[ $ret -eq 0 ]]; then
# gui command to execute input box
app=`yad --window-icon="" --title="Type Command + space" --text="command + options+space:
e.g. vlc " --field="Add £ for multiples\n e.g. petget +£ \n Type command:" --entry`
if [[ -z "$app" ]]; then
exit 1
fi
echo "$select" > /tmp/list-"$filext".m3u # create file list as 'search-term'.m3u playlist with blank lines in between
if [[ -h "$select" ]]; then
select=`realpath $select` # incase of link
fi
if [[ "$app" = rm ]]; then # delete files/dirs
while read line
do
rm -rf "$line"
done < /tmp/list-"$filext".m3u
elif [[ `echo "$app"| rev | cut -f1 -d ' '` = £ ]]; then # loop over list for given commands + options
app=`echo "$app" | cut -f1 -d '£'`
while read line
do
dirr=`echo $line | rev | cut -f2,3,4,5,6,7,8,9,10,11,12,13,14 -d '/' | rev`
line=`echo $line | rev | cut -f1 -d '/' | rev`
cd "$dirr"
"$app""$line"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = mv ]]; then # move files/dirs to 'gui input box'
location=`yad --window-icon="" --geometry=250 --title="Type Path To Destination" --text="Path:
e.g. /root/my-documents" --field="Type Path:" --entry`
if [[ -z "$location" ]]; then
exit 1
fi
while read line
do
mv "$line" "$location"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = ln ]]; then # link single file
linknm=`yad --window-icon="" --geometry=200 --title="Type link name" --entry`
if [[ -z "$linknm" ]]; then
exit 1
fi
line1=`echo $select | cut -f2,3,4,5,6,7,8,9,10 -d '/'`
ln -s "$select" "$line1"/"$linknm"
elif [[ "$app" = rename ]]; then # rename single file
newname=`yad --window-icon="" --geometry=200 --title="Type new name" --entry`
if [[ -z "$newname" ]]; then
exit 1
fi
line=`echo $select | cut -f1 -d '/'`
rename "$line" "$newname" "$select"
elif [[ "$app" = replace ]]; then # replace string or symbol except apostrophe and backslash (but possible)
replace=`yad --window-icon="" --geometry=440 --title="Format: 'ReplaceThis'WithThis' " --text "But not ' nor /:" --entry`
if [[ -z "$replace" ]]; then
exit 1
fi
t1=`echo "$replace" | cut -f2 -d "'"`
t2=`echo "$replace" | cut -f3 -d "'"`
while read line
do
select2=`echo $line | rev | cut -f1 -d '/' | rev`
rp=`echo "$select2" | tr "$t1" "$t2"`
rename "$select2" "$rp" "$line"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = cp ]]; then # copy files/dirs to 'gui input box'
location=`yad --window-icon="" --geometry=260 --title="Type Path To Destination" --text="Path:
e.g. /root/my-documents" --field="Type Path:" --entry`
if [[ -z "$location" ]]; then
exit 1
fi
while read line
do
cp -rf "$line" "$location"
done < /tmp/list-"$filext".m3u
else
playlist=$(yad --window-icon="" --width=430 --title "Do you want to open as a playlist? y or n?" --entry) #gui to open as playlist or individual files
case $playlist in
y) "$app" /tmp/list-"$filext".m3u & # app opens playlist
;;
n) "$app" "$select" & # execute command on file
;;
g) geany /tmp/list-"$filext".m3u & # open file list in geany
;;
esac
fi
fi
if [ -e /var/lib/slocate/1slocate.db ]; then
rename 1slocate.db slocate.db /var/lib/slocate/1slocate.db
fi
rm /tmp/result # remove search results list
rm /tmp/"$filext"-result
for i in `ls "$path"`; do slocate -U /"$path"/"$i" -o /"$path"/"$i"/slocate.db; done &
sync
exec "$0" & # open again for convenience to search new term
Hi all
I just added a section to slocategui for playing selected media files over a bluetooth device using mplayer backend. This assumes you have a bluetooth device configured in /etc/asound.conf . So you can play a list of files over bluetooth speaker/headset in some other room and not interfere with your local media experience. Working well! I also set F9 key to killall mpalyer for stop. When the gui asks for command to execute type btp.
Also added one line of code to remove blank lines from /tmp/list-"$filext".m3u
I just added a section to slocategui for playing selected media files over a bluetooth device using mplayer backend. This assumes you have a bluetooth device configured in /etc/asound.conf . So you can play a list of files over bluetooth speaker/headset in some other room and not interfere with your local media experience. Working well! I also set F9 key to killall mpalyer for stop. When the gui asks for command to execute type btp.
Code: Select all
elif [[ "$app" = btp ]]; then
yaf-splash -bg blue -text "Press F9 to stop bluetooth player" &
mplayer -ao alsa:device=btheadset -playlist /tmp/list-"$filext".m3u &
Code: Select all
sed -i '/^$/d' /tmp/list-"$filext".m3u
Updated to improve performance.
Also updated for fatdog mount points /aufs/devsave and /aufs/devbase
If there are any phantom drives then perform 'slocategui.sh reset' in terminal. Also do the same to completely refresh all databases.
Also updated for fatdog mount points /aufs/devsave and /aufs/devbase
If there are any phantom drives then perform 'slocategui.sh reset' in terminal. Also do the same to completely refresh all databases.
Code: Select all
#!/bin/sh
# slocategui.sh by stemsee copyright (c) 2014 Marcos Contant
# FatDog version
# Find files and execute commands upon them or send them to apps
slct=`busybox which slocate`
if [[ ! -z "$slct" ]]; then
[[ ! -d /var/lib/slocate ]] && mkdir -p /var/lib/slocate
else
yad -undecorated --no-buttons --skip-taskbar --text "The slocate binary was not found. Install slocate." --timeout 4
exit
fi
pathdef (){
if [ -d /live ]; then
path=media
else
path=mnt
fi
export path
}
pathdef
extdbfn (){
for file in `probepart -m | grep -v -e 'none' | cut -f1 -d'|' | cut -f3 -d'/' | grep -v -e 'sr0' -e 'devsave' -e 'devbase' | tr '\n' ' '`
do
emp=`ls -A /$path/$file/`
if [[ -z "$emp" ]]; then
mkdir /"$path"/"$file"
fi
up=`mount | grep -e 'sd[a-z][1-9]' | grep "$file"`
if [[ -z "$up" ]]; then
[[ `mount | grep '$file'` != devsave || `mount | grep '$file'` != devbase ]] && mount --rw /dev/"$file" /"$path"/"$file"
fi
if [[ ! -e /"$path"/"$file"/slocate.db ]]; then
yad --progress --pulsate --auto-close --window-icon="" --width=300 --title "Creating Database '$file'" &
pid1=$!
slocate -U /"$path"/"$file"/ -o /"$path"/"$file"/slocate.db &
chmod a+x /"$path"/"$file"/slocate.db
kill $pid1
elif [[ -e /"$path"/"$file"/slocate.db ]]; then
yad --progress --pulsate --auto-close --window-icon="" --width=300 --title "Updating Database '$file'" &
pi=$!
slocate -qv -o /"$path"/"$file"/slocate.db &
chmod a+x /"$path"/"$file"/slocate.db
kill $pi
fi
ln -fs /"$path"/"$file"/slocate.db /var/lib/slocate/"$file"
done
thisdsave=`mount | grep 'devsave'`
dbaseit=`mount | grep 'devbase'`
if [[ ! -z "$thisdsave" ]]; then
slocate -U /aufs/devsave -o /aufs/devsave/slocate.db &
chmod a+x /aufs/devsave/slocate.db
ln -s /aufs/devsave/slocate.db /var/lib/slocate/devsave
fi
if [[ ! -z "$dbaseit" ]]; then
slocate -U /aufs/devbase -o /aufs/devbase/slocate.db &
chmod a+x /aufs/devbase/slocate.db
ln -s /aufs/devbase/slocate.db /var/lib/slocate/devbase
fi
}
extdbfn
update (){
for i in $pathto
do
up=`mount | grep -e 'sd[a-z][1-9]' | grep -v -e 'devsave' -e 'devbase' | grep "$i"`
[[ ! -z "$up" ]] && slocate -U /"$path"/"$i" -o /"$path"/"$i"/slocate.db &
if [[ -z "$up" ]]; then
[[ -e /"$path"/"$i"/slocate.db ]] && rm -f /"$path"/"$i"/slocate.db
fi
done
}
export -f update
already=$(grep -e slocate /etc/group)
if [[ -z "$already" ]]; then
addgroup slocate 2>/dev/null
fi
# remove databases named slocate.db
if [[ "$1" = reset ]]; then
for file in `probepart -m | grep -v -e 'none' | cut -f1,2 -d '|' | cut -f3 -d '/' | grep -v -e 'sr0' | tr '\n' ' '`
do
file=`echo $file | cut -f1 -d'|'`
fs=`echo $file | cut -f2 -d'|'`
[[ ! -d /"$path"/"$file" ]] && mkdir /"$path"/"$file"
sleep 2
up=`mount | grep -e 'sd[a-z][1-11]' | grep -v -e 'devsave' -e 'devbase' | grep "$file"`
if [[ -z "$up" ]]; then
mount -t $fs --rw /dev/"$file" /"$path"/"$file"
sleep 1
fi
[[ /"$path"/"$file"/slocate.db ]] && rm -f /"$path"/"$file"/slocate.db
done
thisdsave=`mount | grep 'devsave'`
dbaseit=`mount | grep 'devbase'`
if [[ ! -z "$thisdsave" ]]; then
rm -f /aufs/devsave/slocate.db &
rm /var/lib/slocate/devsave
fi
if [[ ! -z "$dbaseit" ]]; then
rm -f /aufs/devbase/slocate.db &
rm /var/lib/slocate/devbase
fi
rm -f /var/lib/slocate/*
[[ /tmp/result ]] && rm /tmp/result
[[ /tmp/list-*.m3u ]] && rm /tmp/list-*.m3u
extdbfn &
fi
# yad gui input search term
filext=`yad --window-icon="" --title="Find files" --text="Input search text:
e.g. .mp3" --entry`
ret=$?
[[ $ret -eq 1 ]] && exit
if [[ -z "$filext" ]]; then
slocategui.sh &
exit
fi
# store and format search term
echo "$filext" > /tmp/name
sed -i 's/^/nm=/' /tmp/name
# create root db and make searchable
rootdbfn (){
yad --window-icon="" --width=300 --title="Creating Database for '/'" --progress --pulsate &
pid=$!
slocate -u -e /media,/aufs,/initrd,/$path -o /var/lib/slocate/system
chmod a+x /var/lib/slocate/system
}
# has root database been created?
if [ ! -e /var/lib/slocate/system ]; then
rootdbfn
else
slocate -qv -o /var/lib/slocate/system &
fi
# choose database to search
pathfn (){
for F in `ls /var/lib/slocate/*`
do
if [ -L "$F" ]; then
if readlink -q "$F" 2>/dev/null ; then
continue
else
rm /var/lib/slocate/"$F"
fi
fi
done
kill $pid
pathto=`ls /var/lib/slocate/* | grep --invert-match 'slocate.db' | yad --geometry=200x400 --list --column="Search sys or drives" --multiple --title="Find files in" --text="Which drives to search?" --window-icon="" --separator ' '`
export pathto
}
YADPID=$(ps -eo pid,cmd | grep -v grep | grep "yad --progress" | tr ' ' '\n' | wc -l )
if [ "$YADPID" = 0 ]; then
pathfn
fi
if [ -z "$pathto" ]; then
exec "$0"
exit
fi
if [[ -e "$pathto" ]]; then
yad --splash --text " Please wait: Now searching \n'$pathto'" --progress --pulsate &
pid3=$!
fi
# search databases
pathto=`echo $pathto | tr ' ' ':' | tr '\n' ':'`
#part=`echo $pathto | cut -f1 -d' \n'`
slocate -i "$filext" --database="$pathto" > /tmp/"$filext"-result
# multiple file/dir selection gui
kill $pid3
select=$(cat /tmp/"$filext"-result | yad --window-icon="" --title "SlocateGUI: multiple selection" --list --multiple --center --height="400" --width="300" --column="$filext:" --print-column="1" --separator="\n")
ret=$?
[[ $ret -eq 1 ]] && slocategui.sh && exit
[[ -z "$select" ]] && slocategui.sh && exit
if [[ $ret -eq 0 ]]; then
echo "$select" | sed '/^$/d' > /tmp/list-"$filext".m3u
# gui command to execute input box=
prog=`yad --width=400 --window-icon="" --title="Command" --form --field="Enter command/app to execute:" -entry "" --field="playlist:CHK" "FALSE"`
if [[ -z "$prog" ]]; then
slocategui.sh &
exit
fi
app=`echo "$prog" | cut -f1 -d'|'`
#options=`echo "$prog" | cut -f2 -d'|'`
pl=`echo "$prog" | cut -f2 -d'|'`
yad --undecorated --no-buttons --no-focus --skip-taskbar --progress --pulsate --progress-text="Performing $app on selected" --timeout=4 &
if [[ "$pl" = TRUE ]]; then
"$app" /tmp/list-"$filext".m3u & # app opens playlist
elif [[ "$app" = rm ]]; then # delete files/dirs
while read line
do
rm -rf "$line"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = lrm ]]; then
while read line
do
rm -rf "$line"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = mv ]]; then # move files/dirs to 'gui input box'
location=`yad --window-icon="" --geometry=250 --title="Type Path To Destination" --text="Path:
e.g. /root/my-documents" --field="Type Path:" --entry`
if [[ -z "$location" ]]; then
slocategui.sh &
exit
fi
while read line
do
mv -rf "$line" "$location"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = replace ]]; then # replace string or symbol except apostrophe and backslash (but possible)
replace=`yad --window-icon="" --geometry=440 --title="Format: :ReplaceThis:WithThis: " --text "But not ' nor /:" --entry`
if [[ -z "$replace" ]]; then
slocategui.sh &
exit
fi
t1=`echo "$replace" | cut -f2 -d ":"`
t2=`echo "$replace" | cut -f3 -d ":"`
while read line
do
select2=`echo "$line" | rev | cut -f1 -d '/' | rev`
rp=`echo "$select2" | sed "s/$t1/$t2/"`
rename "$select2" "$rp" "$line"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = cp ]]; then # copy files/dirs to 'gui input box'
location=`yad --window-icon="" --geometry=260 --title="Type Path To Destination" --text="Path:
e.g. /root/my-documents" --field="Type Path:" --entry`
if [[ -z "$location" ]]; then
slocategui.sh &
exit
fi
while read line
do
cp -rf "$line" "$location"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = ln ]]; then # link files
while read line
do
linknm=`yad --window-icon="" --geometry=200 --title="Type link name" --entry`
if [[ -z "$linknm" ]]; then
slocategui.sh &
exit
fi
line1=`echo $select | cut -f2,3,4,5,6,7,8,9,10 -d '/'`
ln -s "$select" /"line1"/"$linknm"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = rename ]]; then # rename files
while read line
do
newname=`yad --window-icon="" --geometry=200 --title="Type new name" --entry`
if [[ -z "$newname" ]]; then
slocategui.sh &
exit
fi
line=`echo $select | rev | cut -f1 -d'/' | rev`
rename "$line" "$newname" "$select"
done < /tmp/list-"$filext".m3u
elif [[ "$app" = viewnior ]]; then
while read line
do
"$app" "$line"
rm -f /tmp/list-"$filext".m3u
done < /tmp/list-"$filext".m3u
elif [[ "$app" = btp ]]; then
mplayer -ao alsa:device=btheadset -playlist /tmp/list-"$filext".m3u &
else
while read line
do
"$app" "$line"
done < /tmp/list-"$filext".m3u
fi
fi
bash -c update
exec "$0" &
# open again for convenience to search new term
function finish (){
rm -rf /tmp/result
}
export -f finish
trap finish EXIT
Last edited by stemsee on Thu 21 Jun 2018, 08:58, edited 9 times in total.
new script
Hi stemsee,
Am I guessing correctly that the above replaces the bash-script file named slocategui at /usr/bin?
Lest you not spend an inordinate amount of time in recriminations about not being specific, bear in mind that the only useful contributions of editors and attorneys is making certain i's are dotted and t's are crossed.
In order to see how things functioned I viewed the contents of slocateGUI-x86_64.pet.sfs. At its top-most level were etc, usr and var folders and a script named pinstall. Pinstall reads:
#!/bin/sh
echo "slocate::21:root,spot,fido
" >> /etc/group
rm -f /pinstall
I may be mistaken --always a very strong possibility-- but my impression was that if loaded as an SFS, a pinstall would not be executed and that some kind of "import" or "export" command was required. . Can you clarify?
Thanks,
mikesLr
Am I guessing correctly that the above replaces the bash-script file named slocategui at /usr/bin?
Lest you not spend an inordinate amount of time in recriminations about not being specific, bear in mind that the only useful contributions of editors and attorneys is making certain i's are dotted and t's are crossed.
In order to see how things functioned I viewed the contents of slocateGUI-x86_64.pet.sfs. At its top-most level were etc, usr and var folders and a script named pinstall. Pinstall reads:
#!/bin/sh
echo "slocate::21:root,spot,fido
" >> /etc/group
rm -f /pinstall
I may be mistaken --always a very strong possibility-- but my impression was that if loaded as an SFS, a pinstall would not be executed and that some kind of "import" or "export" command was required. . Can you clarify?
Thanks,
mikesLr
Hi mikeslr
The pinstall from the package is no longer needed as this snippet of code takes care of that on first use
The script must now be named slocategui.sh, as that is the name it calls itself with or $0 ....
Thanks for your interest. I too am a learning, albeit very slowly indeed!
Use this app at your own risk ... I have yet to create traps in case of deleting '/' ... ha ha! I have not had any bad experiences with it and i is one of my most used apps ... that and Wifi-Scanner-2, and refdnd!
As I learn more about regex expressions and other cool stuff I will rewrite my three favourite utilities...!
cheers
stemsee
The pinstall from the package is no longer needed as this snippet of code takes care of that on first use
Code: Select all
if [[ ! /root/.did ]]; then
addgroup slocate 2>/dev/null
touch /root/.did
fi
Thanks for your interest. I too am a learning, albeit very slowly indeed!
Use this app at your own risk ... I have yet to create traps in case of deleting '/' ... ha ha! I have not had any bad experiences with it and i is one of my most used apps ... that and Wifi-Scanner-2, and refdnd!
As I learn more about regex expressions and other cool stuff I will rewrite my three favourite utilities...!
cheers
stemsee
Hi Stemsee,
Learning is always fun, except when its something you have to do it, and especially when an arbitrary deadline has been set. Those are the distinguishing factors between games and work, the hallmark of civilization, and the primary reason for our discontent.
Your application is interesting for its capabilities other than "delete". Delete is something I do manually and cautiously or by accident.
mikesLr
Learning is always fun, except when its something you have to do it, and especially when an arbitrary deadline has been set. Those are the distinguishing factors between games and work, the hallmark of civilization, and the primary reason for our discontent.
Your application is interesting for its capabilities other than "delete". Delete is something I do manually and cautiously or by accident.
mikesLr