Quote:
Originally Posted by pan64
You ought to simplify those overcomplicated commands, that will help you to understand what's happening and will allow also to follow intermediate steps/values.
echo $(command....) is almost completely equivalent to command.... but costs more.
|
Code:
+ echo 'find /media/data/wallpaper/307 -type f \( -name '\''*.jpg'\'' -o -name '\''*.png'\'' -o -name *.bmp \) -print0 | shuf -n 1-44 -z | tee -a changebgimage.log | xargs -0 mhsetroot -add #84b996 -add #2cae59 -gradient 10 -fimgv)'
find /media/data/wallpaper/307 -type f \( -name '*.jpg' -o -name '*.png' -o -name *.bmp \) -print0 | shuf -n 1-44 -z | tee -a changebgimage.log | xargs -0 mhsetroot -add #84b996 -add #2cae59 -gradient 10 -fimgv)
or echo this is off cli without set -x
Code:
userx%slackwhere ⚡ ~ ⚡> find /media/data/wallpaper/778 -type f \( -name '*.jpg' -o -name '*.png' -o -name *.bmp \) -print0 | shuf -n 1-10 -z | tee -a changebgimage.log | xargs -0 mhsetroot -add #d4fb95 -add #d98d24 -gradient 10 -dcenter 533x811
to break that up and echo it separately -- I don't think it'd produce what desired results to try and see what is going on either.
as far as that end character tee is putting on it I do not know what or why.
in emacs it show this, I cannot copy it because it is read only so I will simulate it with my fancy keyboard.
Code:
/media/data/wallpaper/609/////////////////Image-270-0555.png^@
Kwrite shows something that looks like a mini % sign at the end.
this is rather simple whence you get your head wrapped around it. Plus as I was writing that out I realized I was out of time so I posted and ran out to catch the last bus home.
let me break it down for you.
returns what when piped into ls or find?
Code:
find /home -type d | wc -l
find: `/home/surooterdude': Permission denied
find: `/home/lost+found': Permission denied
3709
shows a number value of total dir in /home - minus the ones it cannot look at.
Using shuf
Code:
shuf -i 1-10 -n 1
9
-i indicates a range 0 ... whatever N ; -n 1 indicates return one number within that range RANDOM. so it is simple math when we put these two methods together.
if one wants to RANDOMize the obtaining of one image within many subdirectories then what is the best way to get a random? by randomizing everything posable, because RANDOM is not RANDOM.
get count of total subdir in wallpaper parent dir, feed it into shuf for HI end.
what is the fastest and simplest way to do that?
Code:
SetSubDir=$(shuf -i 1-$((($(find "$WALLPAPERS" -type d | wc -l)-1))) -n 1)
Look closely and see that all this is doing is returning total count of dir and subdir in path $WALLPAPERS minus 1 to remove the parent dir count. then tail end is -n 1 return one of them numbers from the RANGE= 1-$(total subDir) - n 1.
then assign that same subdir to the entire path for find a random image to display on the background. JUst add the subDir
Code:
WALLPAPERS="$WALLPAPERS/$SetSubDir"
inside it reads /media/data/wallpaper/(whatever number is returned) because all of the subdirectories are numbered 1 thru N
Now just apply that same line of thought to get a RANDOM image
Code:
this sets the type of files to look for print0 uses a null character as a separator
find "$WALLPAPERS" -type f \( -name '*.jpg' -o -name '*.png' -o -name "*.bmp" \) -print0 | shuf -n 1-$(find "$WALLPAPERS" -type f | wc -l) -z | tee -a changebgimage.log | xargs -0 \
mhsetroot -add $(color) -add $(color) -gradient $gradientAngle $Imageis
break it down a bit
first just find file types needed then place a NULL at the end with -print0 so the program taking in the file name will not error.
https://linux.die.net/man/1/xargs
Code:
userx%slackwhere ⚡ ~ ⚡> find /media/data/wallpaper/2 -type f -name "*.png" -print0
/media/data/wallpaper/2/1920x1080.png/media/data/wallpaper/2/DispicableMe-1-104124.png/media/data/wallpaper/2/DispicableMe-1-10624.png/media/data/wallpaper/2/DispicableMe-1-108024.png/media/data/wallpaper/2/DispicableMe-1-108124.png/media/data/wallpaper/2/DispicableMe-1-110024.png/media/data/wallpaper/2/DispicableMe-1-116024.png/media/data/wallpaper/2/DispicableMe-1-119724.png/media/data/wallpaper/2/DispicableMe-1-121624.png/media/data/wallpaper/2/DispicableMe-1-123424.png/media/data/wallpaper/2/DispicableMe-1-132824.png/media/data/wallpaper/2/DispicableMe-1-23324.png/media/data/wallpaper/2/DispicableMe-1-29124.png/media/data/wallpaper/2/DispicableMe-1-33224.png/media/data/wallpaper/2/DispicableMe-1-33924.png/media/data/wallpaper/2/DispicableMe-1-37224.png/media/data/wallpaper/2/DispicableMe-1-41324.png/media/data/wallpaper/2/DispicableMe-1-44524.png/media/data/wallpaper/2/DispicableMe-1-50724.png/media/data/wallpaper/2/DispicableMe-1-55724.png/media/data/wallpaper/2/DispicableMe-1-60624.png/media/data/wallpaper/2/DispicableMe-1-79224.png/media/data/wallpaper/2/DispicableMe-1-84824.png/media/data/wallpaper/2/DispicableMe-1-99824.png/media/data/wallpaper/2/Heidy-Pino-269-0006.png/media/data/wallpaper/2/Heidy-Pino-269-12066.png/media/data/wallpaper/2/Heidy-Pino-269-3996.png/media/data/wallpaper/2/Heidy-Pino-269-8036.png/media/data/wallpaper/2/slack-blulin-1600x1200.png/media/data/wallpaper/2/slack-glass-1024x768.png/media/data/wallpaper/2/DispicableMe-1-112224.png/media/data/wallpaper/2/DispicableMe-1-60224.png/media/data/wallpaper/2/Nature.Image-63-63.pnguserx%slackwhere ⚡ ~ ⚡>
now pipe all of that into shuf and give it a range to pick from. the HI end matches the total files - this is kept true by using that same method beforehand
Code:
find /media/data/wallpaper/2 -type f -name "*.png" -print0 |shuf -n 1-$(find "$WALLPAPERS" -type f | wc -l) -z
/media/data/wallpaper/2/DispicableMe-1-10624.png
then pipe it to xargs -0 (Input items are terminated by a null character) NULL character is gained by -print0 before hand.
https://linux.die.net/man/1/xargs
the only thing I just found while picking this apart and explaining it to you is this within shuf
https://linux.die.net/man/1/shuf
when it use to be
Code:
return one
shuf -n 1 -z
then I changed it to
Code:
LOW end = 1 to Hi end = total files in subdir set in code prior to
shuf -n 1-$(find "$WALLPAPERS" -type f | wc -l) -z
not changing or forgetting to change the -n to -i
but when I ran and run it on the cli I get a image file returned.
now that I have changed that -n to an -i I get numbers returned instead.
Code:
userx%slackwhere ⚡ ~ ⚡> find "$WALLPAPERS" -type f \( -name '*.jpg' -o -name '*.png' -o -name "*.bmp" \) -print0 | shuf -i 1-$(find "$WALLPAPERS" -type f | wc -l) -z
228789558108867390608280626820256133037721683842410639454071810033657665956962685711431431112156593499842388941705481619444351112299419746310129110976491468821527951105233385109344869677553927717103764719102871041073227555010userx%slackwhere ⚡ ~ ⚡>
so why that is returning only one actual file and path to it being formed improperly I do not know.
Code:
userx%slackwhere ⚡ ~ ⚡> find "$WALLPAPERS" -type f \( -name '*.jpg' -o -name '*.png' -o -name "*.bmp" \) -print0 | shuf -n 1-$(find "$WALLPAPERS" -type f | wc -l) -z
/media/data/wallpaper/1/Abstract 3.jpguserx%slackwhere ⚡ ~ ⚡>
it worked so I ran with it.
..
so let me put this on hold for a bit - remove sleep and run it with various changes to code and see what happens
and see if it stops doing this.
Code:
/media/data/wallpaper/117///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Images.Image-141-129.jpg
/media/data/wallpaper/117////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////slack-freedom-1920x1200.jpg
/media/data/wallpaper/117/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////t137.jpg
---------------------------------------------------------
as far as that end character tee is putting on it I do not know what or why.
in emacs it show this, I cannot copy it because it is read only so I will simulate it with my fancy keyboard.
Code:
/media/data/wallpaper/609/////////////////Image-270-0555.png^@
Kwrite shows something that looks like a mini % sign at the end.
(that was a repeat so it wouldn't get lost in the shuffle)