mirror of
https://git.adityakumar.xyz/betterlockscreen-openrc.git
synced 2024-11-09 10:39:45 +00:00
Make compatible with shellcheck
Add double quotes for variables, fix minor semantic problems.
This commit is contained in:
parent
643ea70aa7
commit
89f7dcd2be
1 changed files with 37 additions and 31 deletions
|
@ -6,14 +6,14 @@
|
|||
|
||||
# find your resolution so images can be resized to match your screen resolution
|
||||
res=$(xdpyinfo | grep dimensions | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/')
|
||||
default_timeout=`cut -d ' ' -f4 <<< $(xset q | sed -n '25p')`
|
||||
default_timeout="$(cut -d ' ' -f4 <<< $(xset q | sed -n '25p'))"
|
||||
|
||||
init_filenames() {
|
||||
#$1 resolution
|
||||
|
||||
# custom i3lock colors
|
||||
theme_rc="$HOME/.config/betterlockscreenrc"
|
||||
if [ -e $theme_rc ]; then
|
||||
if [ -e "$theme_rc" ]; then
|
||||
source "$theme_rc"
|
||||
else
|
||||
# copy this block to ~/.config/betterlockscreenrc" to customize
|
||||
|
@ -37,11 +37,11 @@ init_filenames() {
|
|||
# create folder in ~/.cache/i3lock directory
|
||||
res_folder="$HOME/.cache/i3lock/$1"
|
||||
folder="$HOME/.cache/i3lock/current"
|
||||
echo "Got" $@ $res_folder
|
||||
if [ ! -d $folder -o -n "$2" ]; then
|
||||
rm -rf $folder
|
||||
mkdir -p $res_folder
|
||||
ln -s $res_folder $folder
|
||||
echo "Got" "$@" "$res_folder"
|
||||
if [ ! -d "$folder" -o -n "$2" ]; then
|
||||
rm -rf "$folder"
|
||||
mkdir -p "$res_folder"
|
||||
ln -s "$res_folder" "$folder"
|
||||
fi
|
||||
|
||||
# ratio for rectangle to be drawn for time background on lockscreen
|
||||
|
@ -67,12 +67,12 @@ init_filenames() {
|
|||
l_pixel="$folder/l_pixel.png"
|
||||
}
|
||||
|
||||
init_filenames $res
|
||||
init_filenames "$res"
|
||||
|
||||
|
||||
prelock() {
|
||||
if [ -n lock_timeout ]; then
|
||||
xset dpms $lock_timeout
|
||||
xset dpms "$lock_timeout"
|
||||
fi
|
||||
if [ ! -z "$(pidof dunst)" ]; then
|
||||
pkill -u "$USER" -USR1 dunst
|
||||
|
@ -95,13 +95,13 @@ lock() {
|
|||
--radius=20 --ring-width=4 --veriftext='' --wrongtext='' \
|
||||
--verifcolor="$verifcolor" --timecolor="$timecolor" --datecolor="$datecolor" \
|
||||
--time-font="$font" --date-font="$font" --layout-font="$font" --verif-font="$font" --wrong-font="$font" \
|
||||
--noinputtext='' --force-clock $lockargs
|
||||
--noinputtext='' --force-clock "$lockargs"
|
||||
}
|
||||
|
||||
|
||||
postlock() {
|
||||
if [ -n lock_timeout ]; then
|
||||
xset dpms $default_timeout
|
||||
xset dpms "$default_timeout"
|
||||
fi
|
||||
if [ ! -z "$(pidof dunst)" ] ; then
|
||||
pkill -u "$USER" -USR2 dunst
|
||||
|
@ -156,17 +156,19 @@ lockselect() {
|
|||
# $2: 1 for width. 2 for height
|
||||
logical_px() {
|
||||
# get dpi value from xrdb
|
||||
local DPI=$(xdpyinfo | sed -En "s/\s*resolution:\s*([0-9]*)x([0-9]*)\s.*/\\$2/p" | head -n1)
|
||||
|
||||
local DPI
|
||||
DPI=""$(xdpyinfo | sed -En "s/\s*resolution:\s*([0-9]*)x([0-9]*)\s.*/\\$2/p" | head -n1)
|
||||
|
||||
# return the default value if no DPI is set
|
||||
if [ -z "$DPI" ]; then
|
||||
echo $1
|
||||
echo "$1"
|
||||
else
|
||||
local SCALE=$(echo "scale=2; $DPI / 96.0" | bc)
|
||||
local SCALE
|
||||
SCALE=$(echo "scale=2; $DPI / 96.0" | bc)
|
||||
|
||||
# check if scaling the value is worthy
|
||||
if [ $(echo "$SCALE > 1.25" | bc -l) -eq 0 ]; then
|
||||
echo $1
|
||||
if [ "$(echo "$SCALE > 1.25" | bc -l)" -eq 0 ]; then
|
||||
echo "$1"
|
||||
else
|
||||
echo "$SCALE * $1 / 1" | bc
|
||||
fi
|
||||
|
@ -174,7 +176,7 @@ logical_px() {
|
|||
}
|
||||
|
||||
update() {
|
||||
# use
|
||||
# use
|
||||
background="$1"
|
||||
|
||||
# default blur level; fallback to 1
|
||||
|
@ -184,8 +186,8 @@ update() {
|
|||
SR=$(xrandr --query | grep ' connected' | grep -o '[0-9][0-9]*x[0-9][0-9]*[^ ]*')
|
||||
for RES in $SR; do
|
||||
SRA=(${RES//[x+]/ })
|
||||
CX=$((${SRA[2]} + $(logical_px 25 1)))
|
||||
CY=$((${SRA[1]} - $(logical_px 30 2)))
|
||||
CX=$((SRA[2] + $(logical_px 25 1)))
|
||||
CY=$((SRA[1] - $(logical_px 30 2)))
|
||||
rectangles+="rectangle $CX,$CY $((CX+$(logical_px 300 1))),$((CY-$(logical_px 80 2))) "
|
||||
done
|
||||
|
||||
|
@ -193,7 +195,7 @@ update() {
|
|||
user_image="$folder/user_image.png"
|
||||
|
||||
# create folder
|
||||
if [ ! -d $folder ]; then
|
||||
if [ ! -d "$folder" ]; then
|
||||
echo "Creating '$folder' directory to cache processed images."
|
||||
mkdir -p "$folder"
|
||||
fi
|
||||
|
@ -203,7 +205,7 @@ update() {
|
|||
|
||||
# get user image
|
||||
cp "$user_input" "$user_image"
|
||||
if [ ! -f $user_image ]; then
|
||||
if [ ! -f "$user_image" ]; then
|
||||
echo 'Please specify the path to the image you would like to use'
|
||||
exit 1
|
||||
fi
|
||||
|
@ -275,34 +277,34 @@ wallpaper() {
|
|||
case "$1" in
|
||||
'')
|
||||
# set resized image as wallpaper if no argument is supplied by user
|
||||
feh --bg-fill $resized
|
||||
feh --bg-fill "$resized"
|
||||
;;
|
||||
|
||||
dim)
|
||||
# set dimmed image as wallpaper
|
||||
feh --bg-fill $dim
|
||||
feh --bg-fill "$dim"
|
||||
;;
|
||||
|
||||
blur)
|
||||
# set blurred image as wallpaper
|
||||
feh --bg-fill $blur
|
||||
feh --bg-fill "$blur"
|
||||
;;
|
||||
|
||||
dimblur)
|
||||
# set dimmed + blurred image as wallpaper
|
||||
feh --bg-fill $dimblur
|
||||
feh --bg-fill "$dimblur"
|
||||
;;
|
||||
|
||||
pixel)
|
||||
# set pixelated image as wallpaper
|
||||
feh --bg-fill $pixel
|
||||
feh --bg-fill "$pixel"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
empty() {
|
||||
if [ -f $l_dim ]; then
|
||||
if [ -f "$l_dim" ]; then
|
||||
echo -e "\nSeems you haven't provided any arguments. See below for usage details."
|
||||
else
|
||||
echo 'Important: Update the image cache (e.g. betterlockscreen -u path/to/image.jpg).'
|
||||
|
@ -410,7 +412,11 @@ for arg in "$@"; do
|
|||
-l | --lock)
|
||||
runlock=true
|
||||
[[ $runsuspend ]] || lockargs="$lockargs -n"
|
||||
[[ ${2:0:1} = '-' ]] && shift 1 || { lockstyle="$2"; shift 2; }
|
||||
if [[ ${2:0:1} = '-' ]]; then
|
||||
shift 1
|
||||
else
|
||||
lockstyle="$2"; shift 2
|
||||
fi
|
||||
;;
|
||||
|
||||
-w | --wall | --wallpaper)
|
||||
|
@ -436,7 +442,7 @@ for arg in "$@"; do
|
|||
|
||||
-r | --resolution)
|
||||
res="$2"
|
||||
init_filenames $res force
|
||||
init_filenames "$res" force
|
||||
shift 2
|
||||
;;
|
||||
|
||||
|
@ -446,7 +452,7 @@ for arg in "$@"; do
|
|||
;;
|
||||
|
||||
--)
|
||||
lockargs="$lockargs ${@:2}"
|
||||
lockargs="$lockargs ${*:2}"
|
||||
break
|
||||
;;
|
||||
|
||||
|
|
Loading…
Reference in a new issue