Handy scripts you'd like to share

useful one liner that updates the system and removes orphaned packages to free up disk space :

sudo pacman -Syu --noconfirm && sudo pacman -Qdtq | sudo pacman -Rns - --noconfirm

Doing this automatically via a script can sometimes create problems. It is usually best to review the packages you intend to uninstall prior to doing so.

10 Likes

I can confirm this has happened to me once. Not a biggie, still a pity :).

2 Likes

Since its gone awfully quite in here, his a modification that makes my fzf life much easier best works when added to your fish profile

export FZF_DEFAULT_OPTS="
  --height=60%
  --border=double
  --padding=1%
  --info=right
  --separator=_
  --preview='
    set filename (basename {})
    if string match -q \"*.txt\" -- \$filename
      bat --style=numbers --color=always {}
    else if string match -q \"*.pdf\" -- \$filename
      zathura {} &
    else if string match -q \"*.jpg\" -- \$filename
      feh {} &
    else if string match -q \"*.jpeg\" -- \$filename
      feh {} &
    else if string match -q \"*.png\" -- \$filename
      feh {} &
    else if string match -q \"*.gif\" -- \$filename
      feh {} &
    else
      bat --style=numbers --color=always {}
    end
  '
  --preview-window=hidden:right:69%
  --preview-label=eyes
  --margin=5%
  --border-label=search
  --color=16
  --layout=reverse
  --prompt=⭐
  --bind='enter:execute(
    set filename (basename {})
    if string match -q \"*.txt\" -- \$filename
      emacsclient -nw {}
    else if string match -q \"*.pdf\" -- \$filename
      zathura {}
    else if string match -q \"*.jpg\" -- \$filename
      feh {}
    else if string match -q \"*.jpeg\" -- \$filename
      feh {}
    else if string match -q \"*.png\" -- \$filename
      feh {}
    else if string match -q \"*.gif\" -- \$filename
      feh {}
    else
      emacsclient -nw {}
    end
  )'
  --bind=alt-o:toggle-preview
"

4 Likes

It will put tabs at the bottom. Though I’m not sure this counts as a script.

It’s for firefox you need to put it in the chrome folder in you firefox profile and have CSS turned on in fire fox but,

Saved as userChrome.css

#TabsToolbar {
  position: absolute;
  display: block;
  bottom: 0;
  width: 100vw;
  background-clip: padding-box;
  color: var(--toolbar-color);
}

#tabbrowser-tabs {
  width: 100vw;
}

#navigator-toolbox {
  position: relative;
  padding-bottom: calc( var(--tab-min-height) + 8px );
}

#main-window[tabsintitlebar][sizemode="maximized"]:not([inDOMFullscreen="true"]) #titlebar {
  height: 36px;
}

.titlebar-buttonbox-container {
  position: fixed;
  right: 0;
  visibility: visible;
  display: block;
}

#TabsToolbar .titlebar-buttonbox-container,
#TabsToolbar #window-controls {
  display: none;
}

Location should look something like /home/$USER/.mozilla/firefox/ <Your Profile>

I don’t remember where I found this code was like 8+ years ago. but was before ML.

3 Likes

Browsing log streams with fzf
I found this from the author fzf: Browsing log streams | junegunn.choi.
This is the log file I wanted to see.

journalctl -b -1 | fzf --tail 100000 --tac --no-sort --exact --wrap

Best practices (from the website):
Use --tac to see the newest items up front
Use --wrap to prevent truncation of long lines
You might want to use --no-sort option to keep the order of the items intact without sorting
You’ll likely see many irrelevant matches, so try disabling fuzzy matching with --exact

Now you can have fun browsing in combinations for example: fail wayland

3 Likes

This will only run for those using X11 window manager and KDE. (but can be modified to run other desktop environments on X11.)

Originally written for Debian, i recently modified this script to run Arch Linux. It is a photo slide screensaver, that i wrote because i did not like how xscreensaver portrayed, (ugly black edges,) and randomized (very badly,) the photos. (It will install itself, and give instructions where to run the screensaver from. ($HOME/“Scripts/screensaverfiles/screensaver2.sh”))

First install the dependencies listed at the beginning of the Script, if not installed already, and modify the default settings if you want.

Once install it will display your photos randomly, and in aspect, from your default Picture directory, with the same photo blurred in the back ground filling up the entire monitor. It will detect if you are using sound, or if your power settings have turned the monitor off. It will NOT show the same photo twice, but remove the photo out of the photo list, once shown. When the photo list runs out, it will automatically fill it up again from your default Picture directory.

The only issue with Garuda is that KDE’s main panel has a mind of its own, and keeps popping up randomly. For myself i use pixelcolor to detect if the panel has popped up and put it down again, however since i do not know where people have their panel on the screen i kept part of the code out and simply minimize the panel ever 1.4 seconds. If you want the pixelcolor function restored let me know and i give you the lines needed.

Cheers.

#!/usr/bin/bash
#run this script to install it in the DefaultDirPath directory.
#After installing run screensaver2.sh in the DefaultDirPath directory. (line 15)
#This slideshow aims at filling the screen keeping the images in ratio, and blurring the black background with the same image. 
# When an image is displayed it is removed from the photo list. When the photo list runs out a new one will be automatically generated. 
# sound (line 18) and or shuffling (line 19) can be switched on or off. If you want to modify the Default instalation directory please use line 16 to do so, Picture Directory the same on line 15.
#you can autostart this script once installed if you change the values to your liking beforehand on the screensaver2 in the installation directory,or now before you install the screensaver.

#default values
re='^[0-9]+$' #check if input is a number
idlewaittime=18 #time in seconds to wait before starting to display the images
DefaultPicDir=$HOME"/Pictures/" #default image directory
DefaultDirPath=$HOME"/Scripts/screensaverfiles" #default running files directory
BlurredImagesDir=$DefaultDirPath"/tempphotodir/" #temp directory for background images
speak="on" #determine if the speech engine is switched on.
shuffle="on"
blur="28x28" #value to blur background image
sleeper=7 #time in seconds before next image is shown
blankscreen=3600 #3600 seconds is 1 hour before blanking screen.
wait=.14 #value to pause between loading the images. (try a greater value if your computer has trouble loading the images at this speed.)
period=1.4 #times the value of sleeper. (line 21)
passed=0
righton=0
blank=0
desktop="KDE"

#dependecies.  These are the essential apps needed to run this photoslide screensaver. if not installed yet please do so now by changing the value of to pass=1
pass=0
if [ $pass = 1 ];then
#install with pacman
sudo pacman -Syu geany xprintidle xdotool wmctrl feh arandr imagemagick feh zenity 
#install these files with bauh; pico2wave-shell, pixelcolor, ddccontrol
sudo bauh 
fi

#distro info
DistroBasedOn='Arch Linux';PSUEDONAME="Garuda";echo "Installing a screensaver on ""$DistroBasedOn"" ""$PSUEDONAME"; 

#text to speech function
speaking() {  
	echo 'Entering speaking';
	eval 'pico2wave -l en-GB -w $HOME"/speaking.wav" "${speech}" &';sleep .28;
	eval 'play -q  $HOME"/speaking.wav" &';speech="";sleep .777;
	if [ -s $HOME"/speaking.wav" ];then rm $HOME"/speaking.wav";
	fi;	
};echo 'You can turn speech off. By modifying the value speak=on to speak=off on line 18';speech='You can turn speech off. By modifying the value speak on line 18';speaking;sleep 5;

#checking running directories. Creating them if they don't exist and copying screensaver.sh in it as screensaver2.sh
if ! [ -s $DefaultDirPath"/tempphotodir" ];then 
speech='Do you want to install the screensaver';
if [ $speak = "on" ];then speaking;fi;
answer=`zenity --forms --width=700 --title="Installing The Screensaver" --text="The default directories will be made" --separator="," --text="                    The default directory is:"$DefaultDirPath"    " --separator="," --add-entry="Please Answer (y)es or (n)o" `;
if [ $answer = 'n' ] || [ $answer = 'N' ] || [ ${#answer} -lt 1 ];then 
speech='canceling the installation. Please modify your Default Directory Path on line 16';
if [ $speak = "on" ];then speaking;fi;sleep 4;exit;
elif [ $answer = 'y' ] || [ $answer = 'Y' ];then speech='Adding the new installation directories!';
if [ $speak = "on" ];then speaking;fi;sleep 2;fi;
if ! [ -s $HOME"/Scripts" ];then mkdir $HOME"/Scripts";fi;
if ! [ -s $HOME"/Scripts/screensaverfiles" ];then mkdir $HOME"/Scripts/screensaverfiles";fi;
mkdir $HOME"/Scripts/screensaverfiles/tempphotodir";cp "./screensaver.sh" $DefaultDirPath"/screensaver2.sh";chmod a+x $DefaultDirPath"/screensaver2.sh";
fi;

#loading image files into an array - creating photo list from the DefaultPicDir
loadfiles() { 
	echo 'Entering loadfiles'
	echo 'Please be patient';
	echo 'Making a photo list of your photos';
	echo 'this process could take some time!';
	echo 'Depending on the size of your photo collection!';
	
	speech='Preparing your photo list. This may take some time depending on the size of your photo collection.';
	if [ $speak = "on" ];then speaking;fi;
	sleep 3;unset array;
	if [ -s $DefaultDirPath"/orderedphotos.txt" ];then rm $DefaultDirPath"/orderedphotos.txt";rm $DefaultDirPath"/oldphotos.txt";rm $DefaultDirPath"/photolist.txt";
	fi;
	printf "%s\n" "$blank" > $DefaultDirPath"/oldphotos.txt";check=`find "$DefaultPicDir" -type f -exec echo {} \;`;xxxx=0;
	while IFS='F' read -ra ADDR;do 
	for photoname in "${ADDR[@]}";do photo=${photoname: -4};
	if [ "${photo^^}" = ".JPG" ] || [ "${photo^^}" = '.PNG' ];then  
	xxxx=$(( xxxx + 1 ));array[${#array[*]}]="$photoname";echo $xxxx")"$photoname;
	fi;
	done;done <<< "$check";
	if [ ${#check} -lt 1 ];then 
	speech='there are no images in this directory. Please choose picture default directory with images';
	if [ $speak = "on" ];then speaking;fi;
	rm -rf $DefaultDirPath;sleep 7;exit;
	else speech='there are '$xxxx' images in your photo list.';
	if [ $speak = "on" ];then speaking;fi;
	sleep 4;printf "%s\n" "${array[@]}" > $DefaultDirPath"/orderedphotos.txt";printf "%s\n" "${array[@]}" > $DefaultDirPath"/photolist.txt";fi;
	setupfiles=0;xxxx=0;
};if ! [ -s $DefaultDirPath"/photolist.txt" ];then 
speech="Are your photos in this directory?";
if [ $speak = "on" ];then speaking;fi;
answer=`zenity --forms --width=700 --title=" Making a photo list of your pictures." --text="Your images are in this directory?  "$DefaultPicDir --separator="," --add-entry="Please Answer (y)es or (n)o" `;
if [ $answer = 'n' ] || [ $answer = 'N' ] || [ ${#answer} -lt 1 ];then 
speech='canceling any further installation. Please modify Your Picture Default Directory on line 15';
if [ $speak = "on" ];then speaking;fi;sleep 4;exit;
elif [ $answer = 'y' ] || [ $answer = 'Y' ];then 
speech='Making New Photolist.';
if [ $speak = "on" ];then 
speaking;
fi;
sleep 2;fi;
loadfiles;
fi

if ! [ $PWD = $DefaultDirPath ] && [ -s $DefaultDirPath"/tempphotodir" ];then 
speech='Please run the Screensaver 2 file directly from your default directory';
if [ $speak = "on" ];then speaking;fi;
echo "";echo "Please run the Screensaver2.sh file directly in the "$DefaultDirPath" folder";sleep 2;
else righton=1;
fi


#loading photolist.
readarray -t array < $DefaultDirPath"/photolist.txt";

#Randomly shuffling the photolist
shuffle() { 
	echo 'Entering shuffle';
	speech='I will shuffle your photo entries into a random order. You can turn shuffle off. Just modify the default shuffle value on line 19.';
	if [ $speak = "on" ];then speaking;fi;
	
	local i tmp RANGE rand rand2;RANGE=$(( ${#array[*]} - 1 ));
	if [ $RANGE = -1 ];then 
	readarray -t array < $DefaultDirPath"/photolist.txt";RANGE=$(( ${#array[*]} - 1 ));
	fi;
	echo 'shuffling '$RANGE' images';
	if [ $RANGE -lt  3 ];then 
	loadfiles;readarray -t array < $DefaultDirPath"/photolist.txt";RANGE=$(( ${#array[*]} - 1 ));
	fi;
	size=$(( RANGE + 1 ));i2=0;
	for ((i=size-1; i>0; i--)); do 
	while :;do no=$((no+1));rand=$((0 + RANDOM % $RANGE));rand2=$((0 + RANDOM % $RANGE));
	if ! [ $rand = $rand2 ];then break;
	else echo 'Bypassed identical shuffle move';i2=$(( i2 + 1 ));sleep 2;
	fi;
	done;
	tmp=${array[i]}; 
	array[i]=${array[rand]};
	array[rand]=$tmp;tmp=${array[i2]};
	array[i2]=${array[rand2]}; 
	array[rand2]=$tmp;i2=$(( i2 + 1 ));
	echo $no") ""shuffling entry "$i" to entry "$rand;
	echo $no") ""shuffling entry "$i2" to entry "$rand2;
	done;
	printf "%s\n" "${array[@]}" > $DefaultDirPath"/photolist.txt";
	echo $((RANGE+1))" Photos in the file list ("$DefaultDirPath"/photolist.txt).";
};

#get the idenity number of mouse and keyboard
inputdevices() { 
	echo 'Entering inputdevices'
	KeyboardId=`xinput --list --long | grep XIKeyClass | head -n 1 | egrep -o '[0-9]+'`;
	MouseId=`xinput --list --long | grep XIButtonClass | head -n 1 | egrep -o '[0-9]+'`;
	echo $KeyboardId"=Keyboard Id < inputdevices2 > Mouse Id="$MouseId;
};inputdevices

#Getting screen width and screen height.
ScreenWidth=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1);
echo "Screen Width="$ScreenWidth
ScreenHeight=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2);
len=${#ScreenHeight};if [ ${ScreenHeight:$((len-1)):1} = "i" ];then 
ScreenHeight=${ScreenHeight:0:$((len-1))};
fi;
echo "Screen Height="$ScreenHeight;


echo "Linux Version="$version;echo "Distro Name="$PSUEDONAME;echo 'Desktop='$desktop;

if [ $righton = 0 ];then 
answer=`zenity --forms --width=700 --title="  Do you want to run the screensaver from here?" --text="Do you want to run the screensaver?" --separator="," --add-entry="Please Answer (y)es or (n)o" `;
if [ $answer = 'n' ] || [ $answer = 'N' ] || [ ${#answer} -lt 1 ];then 
speech='Canceling! Load your screensaver from the default Directory';if [ $speak = "on" ];then 
speaking;
fi;
sleep 5;
exit;
elif [ $answer = 'y' ] || [ $answer = 'Y' ];then speech='Loading screensaver';if [ $speak = "on" ];then speaking;fi;
sleep 3;
cd $DefaultDirPath;
eval '$DefaultDirPath"/screensaver2.sh" &';sleep 28;
exit;
fi;fi

startscreensaver=`date +%s`;speech="The Screensaver is up and running!";if [ $speak = "on" ];then speaking;fi;sleep 4

#panel up on KDE Desktop
KDEpanelup() { 
	echo 'Entering KDEpanelup'
	qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "panels()[0].hiding = \"null\"";
	qdbus org.kde.plasmashell /PlasmaShell evaluateScript "p = panelById(panelIds[0]); p.maximumLength = '$ScreenWidth'";
	qdbus org.kde.plasmashell /PlasmaShell evaluateScript "p = panelById(panelIds[0]); p.minimumLength = '$ScreenWidth'";
}
#panel down on KDE
KDEpaneldown() { 
	echo 'Entering KDEpaneldown'
	qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "panels()[0].hiding = \"$value\"";
	qdbus org.kde.plasmashell /PlasmaShell evaluateScript "p = panelById(panelIds[0]); p.maximumLength = '7'";
	qdbus org.kde.plasmashell /PlasmaShell evaluateScript "p = panelById(panelIds[0]); p.minimumLength = '7'";
	qdbus org.kde.plasmashell /PlasmaShell evaluateScript "p = panelById(panelIds[0]); p.alignment = \"left\"";
};value="dodgewindows";#autohide;windowsgobelow;windowscover;dodgewindows;null;

#screensaver main control function
screensaver() { checksound=`pw-dump`;
	if [[ "$checksound" = *"running"* ]] ;then eval $(xdotool getmouselocation --shell);xx=$X;yy=$Y;xdotool mousemove 0 0;xdotool mousemove $xx $yy;return;fi;
	sleeperbak=$sleeper;
	echo "entering screensaver";
	readarray -t array < $DefaultDirPath"/photolist.txt";
	eval $(xdotool getmouselocation --shell);
	mxx=$X;myy=$Y;readarray -t oldphotos < $DefaultDirPath"/oldphotos.txt";
	pidbak1=0;pidbak2=0;pass=1;
	if [ $desktop = "KDE" ];then KDEpaneldown;elif [ $desktop = "Unity" ];then UbuntuHidePanel;elif [ $desktop = "LXQt" ];then LubuntuHidePanel;fi;
	while : ; do 
	screensaver1;
	for R in `seq 1  $sleeper`;do 
	eval $(xdotool getmouselocation --shell);
	if [ $X -lt $(( mxx - 21 )) ] || [ $X -gt $(( mxx + 7 )) ] || [ $Y -lt $(( myy - 7 )) ] || [ $Y -gt $(( myy + 7 )) ];then 
	break 2;
	fi;
	sleep $period;KDEpaneldown;
	done;done;
	while : ; do winpid3=`xdotool search --class "one"`;winpid4=`xdotool search --class "two"`;
	if ! [ ${winpid3:-null} = null ];then xdotool windowclose $winpid3;
	elif ! [ ${winpid4:-null} = null ];then xdotool windowclose $winpid4;
	elif [ ${winpid4:-null} = null ] && [ ${winpid3:-null} = null ];then 
	break;
	fi;
	sleep .035;
	done;statetime=`date +%s`;
	printf "%s\n" "${oldphotos[@]}" > $DirPath"oldphotos.txt";
	printf "%s\n" "${array[@]}" > $DirPath"ourphotos.txt";
	unset oldphotos;unset array;sleeper=$sleeperbak;period=1.600;pass=0;begintime=`date +%s`;
	KDEpanelup;
}

#manipulate photos
screensaver1() { 
	echo 'Entering screensaver1'
	loadphoto;
	resized=$ScreenWidth"x"$ScreenHeight"!";
	if [ $width -gt $height ] && [ $rotate = 1 ];then 
	width3=$width;height3=$height;width=$height3;height=$width3;
	fi;answer=`printf "%.*f\n" '1' $(python -c "print($width / $height)")`;
	if [ $width = $ScreenWidth ] && [ $height = $ScreenHeight ];then 
	first='0) fit '$ScreenWidth"x"$ScreenHeight;width2=$ScreenWidth;height2=$ScreenHeight;
	elif [ $answer = 2.2 ] || [ $answer = 2.1 ] || [ $answer = 2.0 ] || [ $answer = 2.3 ] || [ $answer = 2.4 ];then 
	height2=$height;width2=$width;
	else 
	if [ $height -lt $ScreenHeight ] && [ $rotate = 0 ];then 
	first='1) -lt ScreenHeight '$ScreenHeight;token=`printf "%.*f\n" '4' $(python -c "print($ScreenHeight / $height".00")")`;height2=`printf "%.*f\n" '0' $(python -c "print($height * $token)")`; width2=`printf "%.*f\n" '0' $(python -c "print($width * $token)")`;
	elif [ $height -gt $ScreenHeight ] && [ $rotate = 0 ];then 
	first='2) -gt ScreenHeight '$ScreenHeight;token=`printf "%.*f\n" '4' $(python -c "print($height".00" / $ScreenHeight)")`;height2=`printf "%.*f\n" '0' $(python -c "print($height / $token)")`; width2=`printf "%.*f\n" '0' $(python -c "print($width / $token)")`;
	elif [ $height -gt $ScreenHeight ] && [ $rotate = 1 ];then 
	first='3) -gt '$ScreenHeight' & rotate=1';token=`printf "%.*f\n" '4' $(python -c "print($height".00" / $ScreenHeight)")`;height2=`printf "%.*f\n" '0' $(python -c "print($height / $token)")`; width2=`printf "%.*f\n" '0' $(python -c "print($width / $token)")`;
	elif [ $rotate = 1 ] && [ $height -lt $ScreenHeight ];then 
	first='4) -lt ScreenHeight '$ScreenHeight' & rotate=1';token=`printf "%.*f\n" '4' $(python -c "print($ScreenHeight".00" / $height)")`;height2=`printf "%.*f\n" '0' $(python -c "print($height * $token)")`;width2=`printf "%.*f\n" '0' $(python -c "print($width * $token)")`;
	fi;fi;
	photoname3=$(basename "$photoname");
	if [ -s $BlurredImagesDir$photoname3"7" ];then 
	notify-send -t 3333 'found blurred image';sleep .1;
	else 
	if [ $height -gt $width ];then 
	magick convert -resize $ScreenHeight -colors 49 $photoname $BlurredImagesDir$photoname3"7";mogrify -blur $blur $BlurredImagesDir$photoname3"7";
	else magick convert -resize $resized -colors 49 $photoname $BlurredImagesDir$photoname3"7";mogrify -blur $blur $BlurredImagesDir$photoname3"7";
	fi;
	fi;
	photoname2=$BlurredImagesDir$photoname3"7";width3=$((ScreenWidth-width2));width4=$((width3/2));
	if [ ${#pid2a} -gt 1 ];then 
	if [ ${#pid2} -gt 0 ];then kill -9 $pid2;
	fi;
	pid2a=0;
	fi;
	if [ $width -lt $ScreenWidth ] && [ $height -lt $ScreenHeight ] && [ $rotate = 0 ];then
	 eval 'feh -x  --hide-pointer --class "one" --geometry $ScreenWidth"x"$ScreenHeight+0+0  $photoname2 & pid1=$!';sleep $wait;
	 eval 'feh -x --class "two" --hide-pointer --zoom fill --geometry $width2"x"$ScreenHeight+$width4+0 -B black $photoname & pid2=$!';
	 elif [ $rotate = 0 ] && [ $height -gt $ScreenHeight ];then 
	 eval 'feh -x --class "one"  --hide-pointer --geometry $ScreenWidth"x"$ScreenHeight+0+0 $photoname2 & pid1=$!';sleep $wait;
	 eval 'feh -x  -. --class "two"  --hide-pointer --geometry $width2"x"$ScreenHeight+$width4+0 -B Black $photoname & pid2=$!';
	 elif [ $height -gt $ScreenHeight ] && [ $rotate = 1 ];then 
	 eval 'feh -x --zoom fill  --hide-pointer --class "one" --geometry $ScreenWidth"x"$ScreenHeight+0+0 $photoname2 & pid1=$!';sleep $wait;eval 'feh -x -. --hide-pointer --geometry $width2"x"$ScreenHeight+$width4+0 --class "two"  -B black $photoname & pid2=$!';
	 elif [ $height -lt $ScreenHeight ] && [ $rotate = 1 ];then 
	 eval 'feh -x --zoom fill --hide-pointer --class "one"  --geometry $ScreenWidth"x"$ScreenHeight+0+0   $photoname2 & pid1=$!';sleep $wait;fi;start=`date +%s`;sleep .777;windowname=$(xdotool getactivewindow getwindowname);if ! [[ "$windowname" = *"${photoname}"* ]];then 
	 eval 'feh -x --class "two" --zoom fill  --hide-pointer  --geometry $width2"x"$ScreenHeight+$width4+0  -B black $photoname & pid2a=$!';
	 sleep $wait;
	 pixelcolour8=`pixelcolor --x 910 --y 2142 --hex`;
	 if [ $pixelcolour7 = $pixelcolour8 ];then 
	 notify-send 'same colour';
	 if [ $value = "autohide" ];then 
	 value="dodgewindows";
	 elif [ $value = "dodgewindows" ];then 
	 value="windowscover";
	 elif [ $value = "windowscover" ];then 
	 value="autohide";fi;
	 sleep .28;
	 KDEpaneldown;
	 sleep 1.4;
	 pixelcolour7=`pixelcolor --x 910 --y 2142 --hex`;
	 fi;
	 if [ ${#pid2} -gt 0 ];then kill -9 $pid2;fi;
	 else pid2a=0;winpid1=`xdotool search --pid $pid1`;
	 sleep $wait;
	 winpid2=`xdotool search --pid $pid2`;
	 sleep $wait;
	 xdotool windowfocus $winpid1;
	 sleep $wait;
	 xdotool windowfocus $winpid2;
	 fi;
	 id1=$(xdotool search --pid $pid1);
	 if ! [ $pid1 = $pidbak1 ] && [ $pass = 0 ];then 
	 echo -e $RG'kill pid1!''\e[0m''\e[49m';kill -9 $pidbak1;
	 fi;
	 if ! [ $pid2 = $pidbak2 ] && [ $pass = 0 ];then 
	 echo -e $RG'kill pid2!''\e[0m''\e[49m';kill -9 $pidbak2;
	 fi;
	 pass=0;
	 if [ ${#pid2a} -gt 1 ];then 
	 pidbak2=$pid2a;
	 else pidbak2=$pid2;
	 fi;pidbak1=$pid1;
	 if [ $terminal = 1 ];then 
	 echo -e $RG"width="$width'\e[0m''\e[49m';
	 echo -e $RG"height="$height'\e[0m''\e[49m';
	 echo -e $RG"width2="$width2'\e[0m''\e[49m';
	 echo -e $RG"height2="$height2'\e[0m''\e[49m';
	 echo -e $RG'token='$token'\e[0m''\e[49m';
	 echo -e $RG"rotate="$rotate'\e[0m''\e[49m';
	 echo -e $RG'first='$first'\e[0m''\e[49m';
	 echo -e 'photoname='$photoname'\e[0m''\e[49m';
	 fi;
	 screensaver=0;idle2=`xprintidle`;xdotool windowactivate $winpid2;
}	

#Loading the image
loadphoto() { echo 'entering loadphoto';
	oldphotoNo="${#oldphotos[@]}";
	arrayNo="${#array[@]}";
	if [ $arrayNo -lt 1 ];then 
	unset array;photofiles=1;loadfiles;readarray -t array < $DefaultDirPath"/photolist.txt";printf "%s\n"$blank" " > $DefaultDirPath"/oldphotos.txt";readarray -t oldphotos < $DefaultDirPath"/oldphotos.txt";
	else 
	photofiles=0;
	fi;
	arrayNo="${#array[@]}";oldphotoNo="${#oldphotos[@]}";RANGE="${#array[@]}";
	while :;do 
	number=$RANDOM;let "number %= $RANGE";photoname=${array[$number]};
	if [ ! -f "$photoname" ];then unset array[$number];fault=1;
	else 
	if [[ !  -z  "$photoname"  ]];then 
	oldphotos[${#oldphotos[*]}]="$photoname";unset array[$number];
	break;
	else 
	unset array[$number];fault=1;
	fi;fi;
	sleep .1;done;
	array=("${array[@]}");oldphotos=("${oldphotos[@]}");loadfile2=0;getresolution;loadfile2=1;sleep .21
}

# getting the image resolution and if it is a landscape or portray.
getresolution() { 
	echo 'Entering getresolution'
	rotate=0;
	SizePhoto1=0;
	answer=`identify "$photoname"`;
	x=0;x1=0;x2=0;
	while IFS=' ' read -ra ADDR;do 
	for ii in "${ADDR[@]}";
	do x=$(( x + 1 ));
	if [ $x = 3 ];then photosize=$ii;
	if [ ${#photosize} = 9 ];then width=`echo -n $ii | head -c 4`;height=`echo -n $ii | tail -c 4`;
	elif [ ${#photosize} = 8 ];then 
	height=`echo -n $ii | tail -c 4`;
	if [[ $height =~ $re ]];then 
	width=`echo -n $ii | head -c 3`;
	else 
	width=`echo -n $ii | head -c 4`;height=`echo -n $ii | tail -c 3`;
	fi;
	elif [ ${#photosize} = 7 ];then 
	width=`echo -n $ii | head -c 3`;height=`echo -n $ii | tail -c 3`;
	fi;
	break 2;fi;
	done;
	done <<< "$answer";
	if [ $loadfile2 = 0 ];then 
	answer=`exiftool "$photoname"`;fi;
	if [ $height -gt $width ];then rotate=1;fi;
	if [[ "$answer" = *"Rotate 270 CW"* ]] && ! [ $height -gt $width ] || [[ "$answer" = *"Rotate 90 CW"* ]] && ! [ $height -gt $width ] || [[ $answer = *"Portray"* ]] && ! [ $height -gt $width ];then 
	rotate=1;convert -resize $heightx$width -auto-orient "$photoname" "$photoname";fi;
	
};

#loading photolist.
readarray -t array < $DefaultDirPath"/photolist.txt";

#priming final screensaver values
if [ $shuffle = "on" ];then shuffle;fi #randomly shuffling your images
endscreensaver=`date +%s`;#setting idle time
eval $(xdotool getmouselocation --shell);#getting x, y value of the mouse cursor
xxx=$X
yyy=$Y

#running loop
while :;do
eval $(xdotool getmouselocation --shell);
sleep 1
if [ $xxx = $X ] && [ $yyy = $Y ];then 
endscreensaver=`date +%s`;echo $((endscreensaver-startscreensaver))" out of "$idlewaittime;
if [ $((endscreensaver-startscreensaver)) -gt $idlewaittime ];then 
screensaver;
fi;
else xxx=$X;yyy=$Y;startscreensaver=`date +%s`;
fi
done
4 Likes

Well he is 14 now so yeah.

I have the Logitech MX Keys S - keyboard and MS Master 3S mouse. To get the battery levels I needed to install the extra/solaar 1.1.13-2 [installed] application, it’s both GUI and CLI. Both give the battery level but it’s cumbersome (It does complain about not having a Gnome extension). I simplified this with a one-liner.

solaar show 2>&1 | awk '/Codename/{ CODENAME=$3 " " $4 " " $5; next } /Kind/{ KIND=$2; next } /            Battery/{ print CODENAME ", " KIND ": " $2, $3 }'

The output looks like:
MX KEYS S, keyboard: 35%, discharging.
MX Master 3S, mouse: 75%, discharging.
I did think of adding it to conky and fastfetch, but it takes 9 seconds to run this on my computer. Quick note, the ‘2>&1’ suppresses solaars message about Gnome and the search for battery yielded 2 per device so adding 12 spaces eliminated one of them. The fun in doing this, was getting awk to find 6 lines and combine them into 2 output lines. Hope the necrobumping isn’t too bad.

3 Likes

Hi there @ARClite.

Necbumping on this type of thread is just fine. It’s the threads requesting technical assistance that we prefer to not be resurrected, as information can become quickly outdated with a rolling distro.

Love that one liner @ARClite, thanks for posting your solution.

1 Like

Nice one, but autostart solaar and you can check it in the tray bar :wink: at least easy under KDE.

solaar show 2>&1 | awk '/Codename/{ CODENAME=$3 " " $4 " " $5; next } /Kind/{ KIND=$2; next } /            Battery/{ print CODENAME ", " KIND ": " $2, $3 }'
MX Master 3S, mouse: 70%, discharging.
MX KEYS S, keyboard: 80%, discharging.

Yeah, awk from solaar show is tricky :smiley:
Well done :slight_smile:

3 Likes

A handy little script for any X11 KDE system, which could easliy be configured to run on other desktops as well

This handy little screensaver script will install itself. And automatically prepare your photos, and display the photos 100% random, if you desire. Neither will it show the same photo twice, but fill, and then empty the photo list completely, before reloading a new photo list. Also it will show any photo in perspective with any possible sides filled with the same photo resized, blurred, and colour reduced, as back ground. So no ugly black sides to your photos.

All instruction are on the first lines of the script. (i use Geany to edit, and test, my script, handy as!)

Cheers.

#!/usr/bin/bash
#run this script to install it in the DefaultDirPath directory.
#After installing run screensaver2.sh in the DefaultDirPath directory. (line 12)
#This slideshow aims at filling the screen keeping the images in ratio, and blurring the black background with the same image. 
# When an image is displayed it is removed from the photo list. When the photo list runs out a new one will be automatically generated. 
# sound (line 15) and or shuffling (line 16) can be switched on or off. If you want to modify the Default instalation directory please use line 13 to do so, Picture Directory the same on line 12.
#you can autostart this script once installed if you change the values to your liking beforehand on the screensaver2 in the installation directory,or now before you install the screensaver.

#default values
re='^[0-9]+$' #check if input is a number
idlewaittime=18 #time in seconds to wait before starting to display the images
DefaultPicDir=$HOME"/Pictures/" #default image directory
DefaultDirPath=$HOME"/Scripts/screensaverfiles" #default running files directory
BlurredImagesDir=$DefaultDirPath"/tempphotodir/" #temp directory for background images
speak="on" #determine if the speech engine is switched on.
shuffle="off"
blur="28x28" #value to blur background image
sleeper=7 #time in seconds before next image is shown
blankscreen=3600 #3600 seconds is 1 hour before blanking screen.
wait=.14 #value to pause between loading the images. (try a greater value if your computer has trouble loading the images at this speed.)
period=1.4 #times the value of sleeper. (line 18)
passed=0
righton=0
blank=0
desktop="KDE"

#dependecies.  These are the essential apps needed to run this photoslide screensaver. if not installed yet please do so now by changing the value of to pass=1
pass=0
if [ $pass = 1 ];then
#install with pacman
sudo pacman -Syu geany xprintidle xdotool wmctrl feh arandr imagemagick feh zenity 
#install these files with bauh or Octopi; pico2wave-shell, pixelcolor, ddccontrol
/usr/bin/octopi
sudo bauh 
fi

#distro info
DistroBasedOn='Arch Linux';PSUEDONAME="Garuda";echo "Installing a screensaver on ""$DistroBasedOn"" ""$PSUEDONAME"; 

#text to speech function
speaking() {  if [ $speak = 'on' ];then
	echo 'Entering speaking';
	eval 'pico2wave -l en-GB -w $HOME"/speaking.wav" "${speech}" &';sleep .28;
	eval 'play -q  $HOME"/speaking.wav" &';speech="";sleep .777;
	if [ -s $HOME"/speaking.wav" ];then rm $HOME"/speaking.wav";
	fi;	
	fi
};echo 'You can turn speech off. By modifying the value speak=on to speak=off on line 18';speech='You can turn speech off. By modifying the value speak on line 18';speaking;sleep 5;

#checking running directories. Creating them if they don't exist and copying screensaver.sh in it as screensaver2.sh
if ! [ -s $DefaultDirPath"/tempphotodir" ];then 
speech='Do you want to install the screensaver';
if [ $speak = "on" ];then speaking;fi;
answer=`zenity --forms --width=700 --title="Installing The Screensaver" --text="The default directories will be made" --separator="," --text="                    The default directory is:"$DefaultDirPath"    " --separator="," --add-entry="Please Answer (y)es or (n)o" `;
if [ $answer = 'n' ] || [ $answer = 'N' ] || [ ${#answer} -lt 1 ];then 
speech='canceling the installation. Please modify your Default Directory Path on line 13';
if [ $speak = "on" ];then speaking;fi;sleep 4;exit;
elif [ $answer = 'y' ] || [ $answer = 'Y' ];then speech='Adding the new installation directories!';
if [ $speak = "on" ];then speaking;fi;sleep 2;fi;
if ! [ -s $HOME"/Scripts" ];then mkdir $HOME"/Scripts";fi;
if ! [ -s $HOME"/Scripts/screensaverfiles" ];then mkdir $HOME"/Scripts/screensaverfiles";fi;
mkdir $HOME"/Scripts/screensaverfiles/tempphotodir";cp "./screensaver2.sh" $DefaultDirPath"/screensaver2.sh";chmod a+x $DefaultDirPath"/screensaver2.sh";
fi;

#loading image files into an array - creating photo list from the DefaultPicDir
loadfiles() { 
	echo 'Entering loadfiles'
	echo 'Please be patient';
	echo 'Making a photo list of your photos';
	echo 'this process could take some time!';
	echo 'Depending on the size of your photo collection!';
	
	speech='Preparing your photo list. This may take some time depending on the size of your photo collection.';
	if [ $speak = "on" ];then speaking;fi;
	sleep 3;unset array;
	if [ -s $DefaultDirPath"/orderedphotos.txt" ];then rm $DefaultDirPath"/orderedphotos.txt";rm $DefaultDirPath"/oldphotos.txt";rm $DefaultDirPath"/photolist.txt";
	fi;
	printf "%s\n" "$blank" > $DefaultDirPath"/oldphotos.txt";check=`find "$DefaultPicDir" -type f -exec echo {} \;`;xxxx=0;
	while IFS='F' read -ra ADDR;do 
	for photoname in "${ADDR[@]}";do photo=${photoname: -4};
	if [ "${photo^^}" = ".JPG" ] || [ "${photo^^}" = '.PNG' ] || [ "${photo^^}" = '.SVG' ] || [ "${photo^^}" = 'WEBP' ] || [ "${photo^^}" = 'HEIC' ] || [ "${photo^^}" = 'JPEG' ];then  
	xxxx=$(( xxxx + 1 ));array[${#array[*]}]="$photoname";echo $xxxx")"$photoname;
	fi;
	done;done <<< "$check";
	if [ ${#check} -lt 1 ];then 
	speech='there are no images in this directory. Please choose picture default directory with images';
	if [ $speak = "on" ];then speaking;fi;
	rm -rf $DefaultDirPath;sleep 7;exit;
	else speech='there are '$xxxx' images in your photo list.';
	if [ $speak = "on" ];then speaking;fi;
	sleep 4;printf "%s\n" "${array[@]}" > $DefaultDirPath"/orderedphotos.txt";printf "%s\n" "${array[@]}" > $DefaultDirPath"/photolist.txt";fi;
	setupfiles=0;xxxx=0;
};if ! [ -s $DefaultDirPath"/photolist.txt" ];then 
speech="Are your photos in this directory?";
if [ $speak = "on" ];then speaking;fi;
answer=`zenity --forms --width=700 --title=" Making a photo list of your pictures." --text="Your images are in this directory?  "$DefaultPicDir --separator="," --add-entry="Please Answer (y)es or (n)o" `;
if [ $answer = 'n' ] || [ $answer = 'N' ] || [ ${#answer} -lt 1 ];then 
speech='canceling any further installation. Please modify Your Picture Default Directory on line 15';
if [ $speak = "on" ];then speaking;fi;sleep 4;exit;
elif [ $answer = 'y' ] || [ $answer = 'Y' ];then 
speech='Making New Photolist.';
if [ $speak = "on" ];then 
speaking;
fi;
sleep 2;fi;
loadfiles;
fi

if ! [ $PWD = $DefaultDirPath ] && [ -s $DefaultDirPath"/tempphotodir" ];then 
speech='Please run the Screensaver 2 file directly from your default directory';
if [ $speak = "on" ];then speaking;fi;
echo "";echo "Please run the Screensaver2.sh file directly in the "$DefaultDirPath" folder";sleep 2;
else righton=1;
fi


#loading photolist.
readarray -t array < $DefaultDirPath"/photolist.txt";

#Randomly shuffling the photolist
shuffle() { 
	echo 'Entering shuffle';
	speech='I will shuffle your photo entries into a random order. You can turn shuffle off. Just modify the default shuffle value on line 16.';
	if [ $speak = "on" ];then speaking;fi;
	
	local i tmp RANGE rand rand2;RANGE=$(( ${#array[*]} - 1 ));
	if [ $RANGE = -1 ];then 
	readarray -t array < $DefaultDirPath"/photolist.txt";RANGE=$(( ${#array[*]} - 1 ));
	fi;
	echo 'shuffling '$RANGE' images';
	if [ $RANGE -lt  3 ];then 
	loadfiles;readarray -t array < $DefaultDirPath"/photolist.txt";RANGE=$(( ${#array[*]} - 1 ));
	fi;
	size=$(( RANGE + 1 ));i2=0;
	for ((i=size-1; i>0; i--)); do 
	while :;do no=$((no+1));rand=$((0 + RANDOM % $RANGE));rand2=$((0 + RANDOM % $RANGE));
	if ! [ $rand = $rand2 ];then break;
	else echo 'Bypassed identical shuffle move';i2=$(( i2 + 1 ));sleep 2;
	fi;
	done;
	tmp=${array[i]}; 
	array[i]=${array[rand]};
	array[rand]=$tmp;tmp=${array[i2]};
	array[i2]=${array[rand2]}; 
	array[rand2]=$tmp;i2=$(( i2 + 1 ));
	echo $no") ""shuffling entry "$i" to entry "$rand;
	echo $no") ""shuffling entry "$i2" to entry "$rand2;
	done;
	printf "%s\n" "${array[@]}" > $DefaultDirPath"/photolist.txt";
	echo $((RANGE+1))" Photos in the file list ("$DefaultDirPath"/photolist.txt).";
};

#get the idenity number of mouse and keyboard
inputdevices() { 
	echo 'Entering inputdevices'
	KeyboardId=`xinput --list --long | grep XIKeyClass | head -n 1 | grep -E -o '[0-9]+'`;
	MouseId=`xinput --list --long | grep XIButtonClass | head -n 1 | grep -E -o '[0-9]+'`;
	echo $KeyboardId"=Keyboard Id < inputdevices2 > Mouse Id="$MouseId;
};inputdevices

#Getting screen width and screen height.
ScreenWidth=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1);
echo "Screen Width="$ScreenWidth
ScreenHeight=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2);
len=${#ScreenHeight};if [ ${ScreenHeight:$((len-1)):1} = "i" ];then 
ScreenHeight=${ScreenHeight:0:$((len-1))};
fi;
echo "Screen Height="$ScreenHeight;


echo "Linux Version="$version;echo "Distro Name="$PSUEDONAME;echo 'Desktop='$desktop;

if [ $righton = 0 ];then 
answer=`zenity --forms --width=700 --title="  Do you want to run the screensaver from here?" --text="Do you want to run the screensaver?" --separator="," --add-entry="Please Answer (y)es or (n)o" `;
if [ $answer = 'n' ] || [ $answer = 'N' ] || [ ${#answer} -lt 1 ];then 
speech='Canceling! Load your screensaver from the default Directory';if [ $speak = "on" ];then 
speaking;
fi;
sleep 5;
exit;
elif [ $answer = 'y' ] || [ $answer = 'Y' ];then speech='Loading screensaver';if [ $speak = "on" ];then speaking;fi;
sleep 3;
cd $DefaultDirPath;
eval '$DefaultDirPath"/screensaver2.sh" &';sleep 28;
exit;
fi;fi

startscreensaver=`date +%s`;speech="The Screensaver is up and running!";if [ $speak = "on" ];then speaking;fi;sleep 4

#panel up on KDE Desktop
KDEpanelup() { 
	echo 'Entering KDEpanelup'
	qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "panels()[0].hiding = \"null\"";
	qdbus org.kde.plasmashell /PlasmaShell evaluateScript "p = panelById(panelIds[0]); p.maximumLength = '$ScreenWidth'";
	qdbus org.kde.plasmashell /PlasmaShell evaluateScript "p = panelById(panelIds[0]); p.minimumLength = '$ScreenWidth'";
}
#panel down on KDE
KDEpaneldown() { 
	echo 'Entering KDEpaneldown'
	qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "panels()[0].hiding = \"$value\"";
	qdbus org.kde.plasmashell /PlasmaShell evaluateScript "p = panelById(panelIds[0]); p.maximumLength = '7'";
	qdbus org.kde.plasmashell /PlasmaShell evaluateScript "p = panelById(panelIds[0]); p.minimumLength = '7'";
	qdbus org.kde.plasmashell /PlasmaShell evaluateScript "p = panelById(panelIds[0]); p.alignment = \"left\"";
};value="autohide";#autohide;windowsgobelow;windowscover;null;

#screensaver main control function
screensaver() { checksound=`pw-dump`;
	if [[ "$checksound" = *"running"* ]] ;then eval $(xdotool getmouselocation --shell);xx=$X;yy=$Y;xdotool mousemove 0 0;xdotool mousemove $xx $yy;return;fi;
	sleeperbak=$sleeper;
	echo "entering screensaver";
	readarray -t array < $DefaultDirPath"/photolist.txt";
	eval $(xdotool getmouselocation --shell);
	mxx=$X;myy=$Y;readarray -t oldphotos < $DefaultDirPath"/oldphotos.txt";
	pidbak1=0;pidbak2=0;pass=1;
	if [ $desktop = "KDE" ];then KDEpaneldown;elif [ $desktop = "Unity" ];then UbuntuHidePanel;elif [ $desktop = "LXQt" ];then LubuntuHidePanel;fi;
	while : ; do 
	screensaver1;
	for R in `seq 1  $sleeper`;do 
	eval $(xdotool getmouselocation --shell);
	if [ $X -lt $(( mxx - 21 )) ] || [ $X -gt $(( mxx + 7 )) ] || [ $Y -lt $(( myy - 7 )) ] || [ $Y -gt $(( myy + 7 )) ];then 
	break 2;
	fi;
	sleep $period;KDEpaneldown;
	done;done;
	while : ; do winpid3=`xdotool search --class "one"`;winpid4=`xdotool search --class "two"`;
	if ! [ ${winpid3:-null} = null ];then xdotool windowclose $winpid3;
	elif ! [ ${winpid4:-null} = null ];then xdotool windowclose $winpid4;
	elif [ ${winpid4:-null} = null ] && [ ${winpid3:-null} = null ];then 
	break;
	fi;
	sleep .035;
	done;statetime=`date +%s`;
	printf "%s\n" "${oldphotos[@]}" > $DirPath"oldphotos.txt";
	printf "%s\n" "${array[@]}" > $DirPath"ourphotos.txt";
	unset oldphotos;unset array;sleeper=$sleeperbak;period=1.600;pass=0;begintime=`date +%s`;
	KDEpanelup;
}

#manipulate photos
screensaver1() { 
	echo 'Entering screensaver1'
	loadphoto;
	resized=$ScreenWidth"x"$ScreenHeight"!";
	if [ $width -gt $height ] && [ $rotate = 1 ];then 
	width3=$width;height3=$height;width=$height3;height=$width3;
	fi;answer=`printf "%.*f\n" '1' $(python -c "print($width / $height)")`;
	if [ $width = $ScreenWidth ] && [ $height = $ScreenHeight ];then 
	first='0) fit '$ScreenWidth"x"$ScreenHeight;width2=$ScreenWidth;height2=$ScreenHeight;
	elif [ $answer = 2.2 ] || [ $answer = 2.1 ] || [ $answer = 2.0 ] || [ $answer = 2.3 ] || [ $answer = 2.4 ];then 
	height2=$height;width2=$width;
	else 
	if [ $height -lt $ScreenHeight ] && [ $rotate = 0 ];then 
	first='1) -lt ScreenHeight '$ScreenHeight;token=`printf "%.*f\n" '4' $(python -c "print($ScreenHeight / $height".00")")`;height2=`printf "%.*f\n" '0' $(python -c "print($height * $token)")`; width2=`printf "%.*f\n" '0' $(python -c "print($width * $token)")`;
	elif [ $height -gt $ScreenHeight ] && [ $rotate = 0 ];then 
	first='2) -gt ScreenHeight '$ScreenHeight;token=`printf "%.*f\n" '4' $(python -c "print($height".00" / $ScreenHeight)")`;height2=`printf "%.*f\n" '0' $(python -c "print($height / $token)")`; width2=`printf "%.*f\n" '0' $(python -c "print($width / $token)")`;
	elif [ $height -gt $ScreenHeight ] && [ $rotate = 1 ];then 
	first='3) -gt '$ScreenHeight' & rotate=1';token=`printf "%.*f\n" '4' $(python -c "print($height".00" / $ScreenHeight)")`;height2=`printf "%.*f\n" '0' $(python -c "print($height / $token)")`; width2=`printf "%.*f\n" '0' $(python -c "print($width / $token)")`;
	elif [ $rotate = 1 ] && [ $height -lt $ScreenHeight ];then 
	first='4) -lt ScreenHeight '$ScreenHeight' & rotate=1';token=`printf "%.*f\n" '4' $(python -c "print($ScreenHeight".00" / $height)")`;height2=`printf "%.*f\n" '0' $(python -c "print($height * $token)")`;width2=`printf "%.*f\n" '0' $(python -c "print($width * $token)")`;
	fi;fi;
	photoname3=$(basename "$photoname");
	if ! [ -s $BlurredImagesDir$photoname3"7" ];then if [ $height -gt $width ];then magick $photoname -resize $ScreenHeight -colors 49 $BlurredImagesDir$photoname3"7";sleep 1;mogrify -blur $blur $BlurredImagesDir$photoname3"7";else magick $photoname -resize $resized -colors 49 $BlurredImagesDir$photoname3"7";sleep 1;mogrify -blur $blur $BlurredImagesDir$photoname3"7";fi;fi;photoname2=$BlurredImagesDir$photoname3"7";width3=$((ScreenWidth-width2));width4=$((width3/2));
	if [ ${#pid2a} -gt 1 ];then 
	if [ ${#pid2} -gt 0 ];then kill -9 $pid2;
	fi;
	pid2a=0;
	fi;
	if [ $width -lt $ScreenWidth ] && [ $height -lt $ScreenHeight ] && [ $rotate = 0 ];then
	 eval 'feh -x  --hide-pointer --class "one" --geometry $ScreenWidth"x"$ScreenHeight+0+0  $photoname2 & pid1=$!';sleep $wait;
	 eval 'feh -x --class "two" --hide-pointer --zoom fill --geometry $width2"x"$ScreenHeight+$width4+0 -B black $photoname & pid2=$!';
	 elif [ $rotate = 0 ] && [ $height -gt $ScreenHeight ];then 
	 eval 'feh -x --class "one"  --hide-pointer --geometry $ScreenWidth"x"$ScreenHeight+0+0 $photoname2 & pid1=$!';sleep $wait;
	 eval 'feh -x  -. --class "two"  --hide-pointer --geometry $width2"x"$ScreenHeight+$width4+0 -B Black $photoname & pid2=$!';
	 elif [ $height -gt $ScreenHeight ] && [ $rotate = 1 ];then 
	 eval 'feh -x --zoom fill  --hide-pointer --class "one" --geometry $ScreenWidth"x"$ScreenHeight+0+0 $photoname2 & pid1=$!';sleep $wait;eval 'feh -x -. --hide-pointer --geometry $width2"x"$ScreenHeight+$width4+0 --class "two"  -B black $photoname & pid2=$!';
	 elif [ $height -lt $ScreenHeight ] && [ $rotate = 1 ];then 
	 eval 'feh -x --zoom fill --hide-pointer --class "one"  --geometry $ScreenWidth"x"$ScreenHeight+0+0   $photoname2 & pid1=$!';sleep $wait;fi;start=`date +%s`;sleep .777;windowname=$(xdotool getactivewindow getwindowname);if ! [[ "$windowname" = *"${photoname}"* ]];then 
	 eval 'feh -x --class "two" --zoom fill  --hide-pointer  --geometry $width2"x"$ScreenHeight+$width4+0  -B black $photoname & pid2a=$!';
	 sleep $wait;
	 if [ ${#pid2} -gt 0 ];then kill -9 $pid2;fi;
	 else pid2a=0;winpid1=`xdotool search --pid $pid1`;
	 sleep $wait;
	 winpid2=`xdotool search --pid $pid2`;
	 sleep $wait;
	 xdotool windowfocus $winpid1;
	 sleep $wait;
	 xdotool windowfocus $winpid2;
	 fi;
	 id1=$(xdotool search --pid $pid1);
	 if ! [ $pid1 = $pidbak1 ] && [ $pass = 0 ];then 
	 echo -e $RG'kill pid1!''\e[0m''\e[49m';kill -9 $pidbak1;
	 fi;
	 if ! [ $pid2 = $pidbak2 ] && [ $pass = 0 ];then 
	 echo -e $RG'kill pid2!''\e[0m''\e[49m';kill -9 $pidbak2;
	 fi;
	 pass=0;
	 if [ ${#pid2a} -gt 1 ];then 
	 pidbak2=$pid2a;
	 else pidbak2=$pid2;
	 fi;pidbak1=$pid1;
	 if [ $terminal = 1 ];then 
	 echo -e $RG"width="$width'\e[0m''\e[49m';
	 echo -e $RG"height="$height'\e[0m''\e[49m';
	 echo -e $RG"width2="$width2'\e[0m''\e[49m';
	 echo -e $RG"height2="$height2'\e[0m''\e[49m';
	 echo -e $RG'token='$token'\e[0m''\e[49m';
	 echo -e $RG"rotate="$rotate'\e[0m''\e[49m';
	 echo -e $RG'first='$first'\e[0m''\e[49m';
	 echo -e 'photoname='$photoname'\e[0m''\e[49m';
	 fi;
	 screensaver=0;idle2=`xprintidle`;xdotool windowactivate $winpid2;
}	

#Loading the image
loadphoto() { echo 'entering loadphoto';
	oldphotoNo="${#oldphotos[@]}";
	arrayNo="${#array[@]}";
	if [ $arrayNo -lt 1 ];then 
	unset array;photofiles=1;loadfiles;readarray -t array < $DefaultDirPath"/photolist.txt";printf "%s\n"$blank" " > $DefaultDirPath"/oldphotos.txt";readarray -t oldphotos < $DefaultDirPath"/oldphotos.txt";
	else 
	photofiles=0;
	fi;
	arrayNo="${#array[@]}";oldphotoNo="${#oldphotos[@]}";RANGE="${#array[@]}";
	while :;do 
	number=$RANDOM;let "number %= $RANGE";photoname=${array[$number]};
	if [ ! -f "$photoname" ];then unset array[$number];fault=1;
	else 
	if [[ !  -z  "$photoname"  ]];then 
	oldphotos[${#oldphotos[*]}]="$photoname";unset array[$number];
	break;
	else 
	unset array[$number];fault=1;
	fi;fi;
	sleep .1;done;
	array=("${array[@]}");oldphotos=("${oldphotos[@]}");loadfile2=0;getresolution;loadfile2=1;sleep .21
}

# getting the image resolution and if it is a landscape or portray.
getresolution() { 
	echo 'Entering getresolution'
	rotate=0;
	SizePhoto1=0;
	answer=`identify "$photoname"`;
	x=0;x1=0;x2=0;
	while IFS=' ' read -ra ADDR;do 
	for ii in "${ADDR[@]}";
	do x=$(( x + 1 ));
	if [ $x = 3 ];then photosize=$ii;
	if [ ${#photosize} = 9 ];then width=`echo -n $ii | head -c 4`;height=`echo -n $ii | tail -c 4`;
	elif [ ${#photosize} = 8 ];then 
	height=`echo -n $ii | tail -c 4`;
	if [[ $height =~ $re ]];then 
	width=`echo -n $ii | head -c 3`;
	else 
	width=`echo -n $ii | head -c 4`;height=`echo -n $ii | tail -c 3`;
	fi;
	elif [ ${#photosize} = 7 ];then 
	width=`echo -n $ii | head -c 3`;height=`echo -n $ii | tail -c 3`;
	fi;
	break 2;fi;
	done;
	done <<< "$answer";
	if [ $loadfile2 = 0 ];then 
	answer=`exiftool "$photoname"`;fi;
	if [ $height -gt $width ];then rotate=1;fi;
	if [[ "$answer" = *"Rotate 270 CW"* ]] && ! [ $height -gt $width ] || [[ "$answer" = *"Rotate 90 CW"* ]] && ! [ $height -gt $width ] || [[ $answer = *"Portray"* ]] && ! [ $height -gt $width ];then 
	rotate=1;convert -resize $heightx$width -auto-orient "$photoname" "$photoname";fi;
	
};

#loading photolist.
readarray -t array < $DefaultDirPath"/photolist.txt";

#priming final screensaver values
if [ $shuffle = "on" ];then shuffle;fi #randomly shuffling your images
endscreensaver=`date +%s`;#setting idle time
eval $(xdotool getmouselocation --shell);#getting x, y value of the mouse cursor
xxx=$X
yyy=$Y

#running loop
while :;do
eval $(xdotool getmouselocation --shell);
sleep 1
if [ $xxx = $X ] && [ $yyy = $Y ];then 
endscreensaver=`date +%s`;echo $((endscreensaver-startscreensaver))" out of "$idlewaittime;
if [ $((endscreensaver-startscreensaver)) -gt $idlewaittime ];then 
screensaver;
fi;
else xxx=$X;yyy=$Y;startscreensaver=`date +%s`;
fi
done
2 Likes

I lost a sizable directory and got tired of ‘du’. So added this to config.fish:

alias lss 'eza -al --total-size --color=always --group-directories-first --icons' # preferred listing with directory size
2 Likes

That’s a good one! We added that exact alias to the default config last year (except as lsz).

The way they color code it from green to red is a nice touch, very easy to see where the big files are with just a glance.

Maybe off-topic for this thread, but another really nice app for checking file size on disk is dua-cli.

It is incredibly fast, and the TUI mode makes it super easy to drill down into a large directory to see where the big files are.

5 Likes

Interesting, I took a look in the default config for a lsz type alias but didn’t find one. I rebuilt on 2024-11-14 with the garuda-dr460nized-linux-zen-240428 iso and it’s not in /etc/skel/.config/fish/config.fish file.

Thanks for the dua-cli

1 Like

O wow, you weren’t kidding about dua-cli’s speed. :astonished:

1 Like

That’s weird. Do you have 1.5.23 of garuda-fish-config installed? At least in /etc/skel, your Fish config should look like this: garuda-fish-config/config.fish · main · Garuda Linux 🦅 / PKGBUILDs · GitLab

# Replace ls with eza
alias ls 'eza -al --color=always --group-directories-first --icons' # preferred listing
alias la 'eza -a --color=always --group-directories-first --icons'  # all files and dirs
alias ll 'eza -l --color=always --group-directories-first --icons'  # long format
alias lt 'eza -aT --color=always --group-directories-first --icons' # tree listing
alias l. 'eza -ald --color=always --group-directories-first --icons .*' # show only dotfiles
pacman -Qi garuda-fish-config
Name                     : garuda-fish-config
Version                  : 1.5.23-1

No lsz in skel

pacman -Ss  garuda-fish-config
garuda/garuda-fish-config 1.5.23-1 [installed]

I have the same as SGS in /etc/skel.
There is a different number of lines (176 in …Gitlab)

cat /etc/skel/.config/fish/config.fish | wc -l
171

Looks like I did not properly bump the pkgver, causing garuda-fish-config to become “stuck” on an old version. :eyes:

This ought to fix it:

1.5.24 should be showing up shortly, which will finally deliver the updated config to /etc/skel. Thanks for the heads-up @ARClite!

8 Likes