LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Fast random recursive slideshow script

Posted 01-24-2017 at 11:45 PM by the dsc
Tags slideshow

This is probably buggy and not well written, but it's faster than some other CLI image slideshow tools such as feh [citation needed], as it doesn't try to scan the whole folder tree for image files first, but it only has a directory list cache file (txt stored on $HOME, which may be a little bit slow to build for the first time, but not as much), picks one randomly, lists (ls) the image files into a cache file (txt on /dev/shm), and makes one randmoly into the wallpaper (if hsetroot is able to do that).

Other not perfectly developed features are browsing the session's "history", deleting the current file, and linking to a /dev/shm subfolder.

Warning: it has "read" command that doesn't require enter, so special keys besides enter itself will give as input several keys at the same time. Therefore, if some special key happens to be composed with a d-y sequence, it will send the image file to trash.

Other options call other scripts I have or geeqie.

It's free-do-whatever-you-want-and-whatever. Just absolutely no guarantees, and, by the very act reading this you're automatically legally binded to not sue me for any reason whatsoever.

Sorry for the messy and ill-documented code.

Right now "," (same key as "<" on my keyboard) moves back in history, and "." (same key as ">") forwards/ newrandom.

Keys chosen because the real arrows would be way too complicated to use in a bash script.

By default it doesn't go to the next image automatically, but it can be set with "s" and giving a number of seconds, otherwise it sleeps for 999999999999 seconds or so, which is something like 200 years, and therefore, in effect, it's paused.

The "interface" is tremendously ill developed, the output messages are mostly garbage-ish things that only made sense to me while I was trying to make it work, sort of a debug. Part of the code is from previous versions that had a permanent file list as well, and it really shouldn't be there, but I haven't cleaned it yet.


Code:
#!/bin/bash

touch /dev/shm/noOSD

# idx=$HOME/imgidx.txt

diridx=$HOME/diridx.txt

histbrow=0
keep=no

[[ ! -e $diridx ]] && touch $diridx 

# rm /dev/shm/brkgslide*
# exit 0

sleepsec=9999999999999


rm /dev/shm/.gslides.h 2>/dev/null



while [[ ! -z $(pgrep $$) ]] ; do
xscreensaver-command -deactivate
sleep 3m
done &



for i in "$@"
do
case $i in
#     -d=*|d=*)
#     depth="${i#*=}"
#     
# echo DEPTH $depth
#     shift # past argument=value
#     ;;
    -s=*|s=*|-t=*|t=*)
    sleepsec="${i#*=}"
    shift # past argument=value
    ;;
    -nr|nr|nr)
	echo NONRECURSIVE 1
    nr=1
    
    shift # past argument=value
    ;;
        -ns|ns)
    random=y
    
    shift # past argument=value
    ;;

    -g=*)
    grep="${i#*=}"
    echo grep $grep
    shift
    ;;
    -gv=*)
    grepv="${i#*=}"
    echo grep -v $grepv
    shift
    ;;
#     grep="$(i#*=}"
#     --default)
#     DEFAULT=YES
#     shift # past argument with no value
#     ;;
    *)
        echo UNKNOWN OPTION
    ;;
esac
done

diridxtmp=/dev/shm/diridx.tmp
dirsnow=/dev/shm/dirsnow$$
imgidx=/dev/shm/imgidx
history=/dev/shm/imghistory$$



if ! grep -x "$PWD" $diridx ; then 

echo $PWD not in diridx
echo gonna update diridx
ls -1DR "$PWD" | grep ':$' | sed 's|:||' > $diridxtmp
sort -u $diridx >> $diridxtmp
cat $diridxtmp > $diridx
echo updated?
fi

grep "$PWD" $diridx > $dirsnow
echo PWD to dirsnow

while true ; do

echo loop

echo keep image  $keep
if [[ "$keep" == "no" ]] ; then
unset img
    if [[ $histbrow == "1" ]] && (( hist <= histtotal )) ; then 
    echo BROWSING HISTORY
    echo $hist / $histtotal
    echo
    img="$(sed -n ""$hist"p" /dev/shm/imghistory$$ )"
    else
    histbrow=0
    fi
    
    until [[ ! -z "$img" ]] ; do
        
        echo getting img

        dir=$( shuf -n 1 $dirsnow )

        echo $dir
        
        grep "$dir" $imgidx | grep ".jp\|.png\|.gif\|.bmp\|.tif" > /dev/null && ok=1 && echo ok1

    #     grep -E "$dir.*.jp\|.png\|.gif\|.bmp\|.tif" $imgidx  > /dev/null && ok=1


            if [[ ! $ok == "1" ]] ; then

            unset ok

            echo no imgs yet on imgidx, gonna ls

            ls -1 -- "$dir"/*.{jp*g,png,gif,bmp,tif*} >/dev/null >> $imgidx

            echo ls-ed

            fi
        unset ok
        echo dir 2nd $dir
        echo shuffing img
        img=$(grep "$dir" $imgidx | shuf -n 1 )
        echo -e "=========================\n$img\n========================="
        grep "$img" $history > /dev/null && img="" && echo repeated

        done

[[ "$histbrow" == "0" ]] && echo  $img >> $history

histtotal=$(cat $history | wc -l)
ionice -c3 hsetroot -full "$img"
# unset img
else

keep=no

fi





read -t $sleepsec -r -sn1 key ; case $key in



u|U) [[ ! -f /dev/shm/images$$ ]] && mkdir /dev/shm/images$$ ; ln -s "$img" /dev/shm/images$$/ ; notify-send linked to shm  ;;
w|) if [[ -e "$img" ]] ; then if [[ !  "$img" ]] ; then echo "$img" | tee -a ~/wallpapers/wplist.temp >> /dev/shm/wplist.temp ; else echo "$(realpath "$img")" | tee -a /dev/shm/wplist.temp >> ~/wallpapers/wplist.temp ; fi ; fi ; echo -e "\n added $img to wallpaper list" ; notify-send "$(realpath "$img")" "added to wallpaper list" -i insert-image ; keep=yes ;;
W|) if [[ -e "$img" ]] ; then if [[ !  "$img" ]] ; then echo "$img" | tee -a ~/wallpapers/favs.lst >> /dev/shm/wplist.temp ; else echo "$(realpath "$img")" | tee -a /dev/shm/wplist.temp >> ~/wallpapers/favs.lst ; fi ; fi ; echo -e "\n added $img to wallpaper list" ; notify-send "$(realpath "$img")" "added to wallpaper favorites" -i insert-image ; keep=yes ;;
"") echo ... >/dev/null ;; 
[0-9]) 
echo  "$(realpath "$img")" >> /dev/shm/hslides-mark${key}.txt
notify-send "$(realpath "$img")" "added to hslides-mark${key}.txt" -i insert-image
keep=yes
#sleepsec="$key" ; echo sleepsec $sleepsec\s ; keep=yes  ;;
;;
y|l) autorenlink "$img" ; keep=yes
;;
Y|L) autorenlinkprev "$img" ; keep=yes
;;
m) guimove "$img" #; keep=yes
;;
n) guimovequick "$img" #; keep=yes
;;
N) guimovequickprev "$img" #; keep=yes
;;
y) guilink "$img" ; keep=yes
;;
o) jpgopt.sh "$img" ; keep=yes
;;
i|I) echo -e "\n" ; identify "$img" | sed 's| |\n|g' ; keep=yes 
;;
c) cropgui-ren "$img" ; keep=yes ;;
g) 
# if [[ ! -e /dev/shm/.gslides.h ]] ; then 
echo "===== PAUSED =====" 
[[ ! -e /dev/shm/.gslides.h ]] && echo $sleepsec > /dev/shm/.gslides.h 
keep=yes 
sleepsec=999999999999 

notify-send geeqie
geeqie -r +t "$img" &
disown
# else
# sleepsec=$(cat /dev/shm/.gslides.h )
# rm /dev/shm/.gslides.h 
# keep=yes
# echo "continuing ( $sleepsec )"
# fi
;;
G)
keep=yes 
[[ ! -f /dev/shm/.gslides.h ]] && echo $sleepsec > /dev/shm/.gslides.h
sleepsec=999999999999 
echo "===== PAUSED =====" 

gooims "$img" &
disown


;;
B|b) if [ ! -f /dev/shm/noOSD ] ; then touch /dev/shm/noOSD && echo OSD off
else rm /dev/shm/noOSD && echo OSD on
fi
;;

.) keep=no
if [[ "$histbrow" == "1" ]] ; then
hist=$((hist+1))

fi

;;

,) if [[ -z "$hist" ]] || (( histbrow == 0 )) ; then
hist=$histtotal
 histbrow=1
fi

hist=$((hist-1)) 

keep=no
;;



    S|s)
    echo Give number of seconds to show each image
    read sec
    sleepsec="$sec" 
    shift
    ;;
    d|D) echo -e "\n\n\n\ARE YOU SURE YOU WANT TO\n*** D E L E T E ***\n$img\n?????"
	read inp ; case $inp in
	y|Y|yes|YES|Yes) trash "$(realpath "$img")" ; [[ -e "$img" ]] && trash "$img"  ;; # had break fsr
	*) echo Cancelled ; keep=yes ;;
	esac ;;
    
    h|H) 
if [[ ! -e /dev/shm/.gslides.h ]] ; then 
echo "===== PAUSED =====" 
echo $sleepsec > /dev/shm/.gslides.h 
keep=yes 
sleepsec=999999999999 
else
sleepsec=$(cat /dev/shm/.gslides.h )
sleepsec=${sleepsec:-2}
rm /dev/shm/.gslides.h 
keep=yes
echo "continuing ( $sleepsec )"
fi
;;

*) echo nothing ; keep=yes


;;
esac

# unset img


done

# exit 0
Posted in Uncategorized
Views 660 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 05:13 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration