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