Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added features : random wallpaper style setting #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 71 additions & 8 deletions dwall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ REDBG="$(printf '\033[41m')" GREENBG="$(printf '\033[42m')" ORANGEBG="$(printf
MAGENTABG="$(printf '\033[45m')" CYANBG="$(printf '\033[46m')" WHITEBG="$(printf '\033[47m')" BLACKBG="$(printf '\033[40m')"

## Wallpaper directory
DIR="/usr/share/dynamic-wallpaper/images"
DIR="/usr/share/dynamic-wallpaper"
DIRIMG="$DIR/images"
HOUR=`date +%k`

## Wordsplit in ZSH
Expand Down Expand Up @@ -64,16 +65,20 @@ usage() {
Dwall V2.0 : Set wallpapers according to current time.
Developed By : Aditya Shakya (@adi1090x)

Usage : `basename $0` [-h] [-p] [-s style]
Usage : `basename $0` [-h] [-p] [-r] [-d] [-s style]

Options:
-h Show this help message
-p Use pywal to set wallpaper
-s Name of the style to apply
-d Change style every day
-r Get a random wallpaper style

NOTE: [-r] and [-d] can't be used together. If [-r] and [-d] are provided the [-s style] is ignored.

EOF

styles=(`ls $DIR`)
styles=(`ls $DIRIMG`)
printf ${GREEN}"Available styles: "
printf -- ${ORANGE}'%s ' "${styles[@]}"
printf -- '\n\n'${WHITE}
Expand All @@ -82,6 +87,8 @@ usage() {
Examples:
`basename $0` -s beach Set wallpaper from 'beach' style
`basename $0` -p -s sahara Set wallpaper from 'sahara' style using pywal
`basename $0` -r Set a random wallpaper style
`basename $0` -d Set a random wallpaper style every day(Better use with cron jobs)

EOF
}
Expand Down Expand Up @@ -137,7 +144,49 @@ esac

## Get Image
get_img() {
image="$DIR/$STYLE/$1"

FILEPATH="$DIR/intermediate.txt"
OLDDATE=`cat "$FILEPATH" | awk '{print $1}'`
CURRDATE="$(echo `date` | awk '{print $2}')"

# GET A RANDOW WALLPAPER NAME
WALLPAPER="$(find "$DIRIMG" -maxdepth 1 -type d -printf '%f\n' | shuf -n 1 )"

# IF THE NAME OF WALLPAPER = "images" THEN GET ANOTHER RANDOM WALLPAPER
if [ $WALLPAPER == "images" ]
then
WALLPAPER="$(find "$DIRIMG" -maxdepth 1 -type d -printf '%f\n' | shuf -n 1 )"
fi

if [ $RANDOMDAY ]
then
if [ $RANDOM ]
then
# ERROR RANDOMDAY AND RANDOM CAN'T BE SET TO TRUE SIMULTANEOUSLY
echo -e ${RED}"[!] Invalid option combination : ${GREEN}-r -d simultaneosly can't be used${RED}, exiting..."
{ reset_color; exit 1; }
else
if [ $CURRDATE != $OLDDATE ]
then
image="$DIRIMG/$WALLPAPER/$1"
# UPDATE THE INTERMEDIATE.TXT FILE
echo "${CURRDATE} ${WALLPAPER}" > "$FILEPATH"
else
WALLPAPER=`cat "$FILEPATH" | awk '{print $2}'`
image="$DIRIMG/$WALLPAPER/$1"
fi
fi
else
if [ $RANDOM ]
then
image="$DIRIMG/$WALLPAPER/$1"
# UPDATE THE INTERMEDIATE.TXT FILE
echo "${CURRDATE} ${WALLPAPER}" > "$FILEPATH"
else
image="$DIRIMG/$STYLE/$1"
echo "${CURRDATE} ${STYLE}" > "$FILEPATH"
fi
fi

# get image format
if [[ -f "${image}.png" ]]; then
Expand Down Expand Up @@ -182,7 +231,7 @@ set_wallpaper() {

## Check valid style
check_style() {
styles=(`ls $DIR`)
styles=(`ls $DIRIMG`)
for i in "${styles[@]}"; do
if [[ "$i" == "$1" ]]; then
echo -e ${BLUE}"[*] Using style : ${MAGENTA}$1"
Expand Down Expand Up @@ -211,12 +260,21 @@ main() {
fi
}


unset RANDOM
unset RANDOMDAY
## Get Options
while getopts ":s:hp" opt; do
while getopts ":s:hprd" opt; do
case ${opt} in
p)
PYWAL=true
;;
r)
RANDOM=true
;;
d)
RANDOMDAY=true
;;
s)
STYLE=$OPTARG
;;
Expand All @@ -236,9 +294,14 @@ done

## Run
Prerequisite
if [[ "$STYLE" ]]; then
check_style "$STYLE"
if [[ "$RANDOM" ]]; then
main
elif [ "$RANDOMDAY" = true ]
then
main
elif [[ "$STYLE" ]]; then
check_style "$STYLE"
main
else
{ usage; reset_color; exit 1; }
fi
3 changes: 2 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ mkdir_dw() {
## Copy files
copy_files() {
# copy images and scripts
sudo cp -r "$DIR"/images "$DES"/dynamic-wallpaper && sudo cp -r "$DIR"/dwall.sh "$DES"/dynamic-wallpaper
sudo cp -r "$DIR"/images "$DES"/dynamic-wallpaper && sudo cp -r "$DIR"/dwall.sh "$DES"/dynamic-wallpaper && sudo cp -r "$DIR"/intermediate.txt "$DES"/dynamic-wallpaper
# make script executable
sudo chmod +x "$DES"/dynamic-wallpaper/dwall.sh
sudo chmod 666 "$DES"/dynamic-wallpaper/intermediate.txt
# create link in bin directory
if [[ -L /usr/bin/dwall ]]; then
sudo rm /usr/bin/dwall
Expand Down
1 change: 1 addition & 0 deletions intermediate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
26 tokyo