Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions wp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@ function main {
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
K_MEANS=16
WALLPAPER_DIR=${WALLPAPER_DIR:-~/.wallpapers/}
WALLPAPER_DIR=${WALLPAPER_DIR:-~/.wallpapers}
# Get canonical path
WALLPAPER_DIR="$(readlink -f "$WALLPAPER_DIR")"

while test $# -gt 0; do
if test $# -gt 0; then
case "$1" in
usage | -h | --help)
usage | -h | --help | help)
shift
usage
;;
n | -n)
shift
K_MEANS=$1
shift
;;
add | -a | --add)
shift
add $*
Expand All @@ -35,7 +32,7 @@ function main {
shift
remove $*
;;
change)
change | next)
shift
change $*
;;
Expand All @@ -56,11 +53,12 @@ function main {
slideshow $*
;;
*)
shift
indent "$1 is not a recognised directive"
indent "$1 is not a recognized directive"
;;
esac
done
else
usage
fi
}

#:: Prety print function
Expand All @@ -86,6 +84,11 @@ function add {
exit 1
fi

if [ '-n' = $1 ]; then
K_MEANS=$2
shift 2
fi

files=$*

for file in $files; do
Expand All @@ -99,7 +102,7 @@ function add {
cd $WALLPAPER_DIR

for file in $*; do
echo ":: Generating .$file.colors and .$file.Xres in $PWD"
echo ":: Generating .$file.colors and .$file.Xres in $PWD with $K_MEANS colors"
python2 $DIR/py/color_detect.py $file $K_MEANS
done
}
Expand All @@ -117,14 +120,14 @@ function remove {
for file in $*; do
indent "Removing $file"
rm ${WALLPAPER_DIR}/${file}
rm ${WALLPAPER_DIR}/.${file}.{colors,Xres}
rm ${WALLPAPER_DIR}/.${file}.{colors,Xres,sample.png}
done
}

function change {
#:: Select a random background from WALLPAPER_DIR, or use the passed background
if [ -z $1 ]; then
background=$(find $WALLPAPER_DIR -type f \( -name '*.jpg' -o -name '*.png' \) | shuf -n1)
background=$(find $WALLPAPER_DIR -type f | grep -P "^((?!sample).)*\.(jpg|png)\$" | shuf -n1)
else
background=$WALLPAPER_DIR/$1

Expand Down Expand Up @@ -186,7 +189,7 @@ function get_current {
}

function set_current {
ln -sf $1 $WALLPAPER_DIR/.current
ln -sf $1 $WALLPAPER_DIR/.current
}

function list {
Expand Down Expand Up @@ -231,18 +234,17 @@ function usage {
printf "%b" " $0 [action] [options]

Actions
- usage: Print this help message.
- n [number] : Number of colors to gather.
- add [file]...: Add file, or files, to the wallpaper database.
- rm [file]...: Remove file, or files, from the wallpaper database.
- change [file]: Set the wallpaper to file, or a random wallpaper
from the wallpaper database.
- slideshow [cmd file]: Rotate through wallpapers, optionally
running cmd each time and using only
wallpapers listed in the file.
- current: List the current background
- ls: List all wallpapers in the database.
- colors: Display the current set of colors.
- usage: Print this help message.
- add [-n [number of colors]] [file]...: Add file, or files, to the wallpaper database.
- rm [file]...: Remove file, or files, from the wallpaper database.
- change [file]: Set the wallpaper to file, or a random wallpaper
from the wallpaper database.
- slideshow [cmd file]: Rotate through wallpapers, optionally
running cmd each time and using only
wallpapers listed in the file.
- current: List the current background
- ls: List all wallpapers in the database.
- colors: Display the current set of colors.
"
}

Expand Down