From e3ad2d7fca44323e02d537ddd7c6a0fbb367e253 Mon Sep 17 00:00:00 2001 From: hugogrochau Date: Mon, 21 Dec 2015 17:33:17 -0200 Subject: [PATCH 1/8] Modify `wp change` to not select sample images --- wp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp b/wp index cd1a714..03b85eb 100755 --- a/wp +++ b/wp @@ -124,7 +124,7 @@ function remove { 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 From 5d6adabea1c07b6c57981ba4d319b867fe44faa3 Mon Sep 17 00:00:00 2001 From: hugogrochau Date: Mon, 21 Dec 2015 17:39:49 -0200 Subject: [PATCH 2/8] Fix not printing unrecognised directive --- wp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wp b/wp index 03b85eb..706fdc3 100755 --- a/wp +++ b/wp @@ -15,10 +15,11 @@ function main { DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" K_MEANS=16 WALLPAPER_DIR=${WALLPAPER_DIR:-~/.wallpapers/} + PARAM=$1 while test $# -gt 0; do case "$1" in - usage | -h | --help) + usage | -h | --help | help) shift usage ;; @@ -57,7 +58,7 @@ function main { ;; *) shift - indent "$1 is not a recognised directive" + indent "$PARAM is not a recognised directive" ;; esac done From 51aa2b4cb7f6fcf1dd3142ae52ddfb4d399997fc Mon Sep 17 00:00:00 2001 From: hugogrochau Date: Mon, 21 Dec 2015 17:50:28 -0200 Subject: [PATCH 3/8] Fix bug with parameter parsing Commands with more than two parameters were giving a message of unrecognised directive --- wp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp b/wp index 706fdc3..2a65645 100755 --- a/wp +++ b/wp @@ -17,7 +17,7 @@ function main { WALLPAPER_DIR=${WALLPAPER_DIR:-~/.wallpapers/} PARAM=$1 - while test $# -gt 0; do + if test $# -gt 0; then case "$1" in usage | -h | --help | help) shift @@ -61,7 +61,7 @@ function main { indent "$PARAM is not a recognised directive" ;; esac - done + fi } #:: Prety print function From 24696088c055b7324730392e46766e3b8043e04f Mon Sep 17 00:00:00 2001 From: hugogrochau Date: Mon, 21 Dec 2015 18:01:14 -0200 Subject: [PATCH 4/8] Print usage if no parameters are specified --- wp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wp b/wp index 2a65645..f685cd9 100755 --- a/wp +++ b/wp @@ -16,7 +16,6 @@ function main { K_MEANS=16 WALLPAPER_DIR=${WALLPAPER_DIR:-~/.wallpapers/} PARAM=$1 - if test $# -gt 0; then case "$1" in usage | -h | --help | help) @@ -61,6 +60,8 @@ function main { indent "$PARAM is not a recognised directive" ;; esac + else + usage fi } From e151014acdd6b7340c05d6133247eee432d40f53 Mon Sep 17 00:00:00 2001 From: hugogrochau Date: Mon, 21 Dec 2015 18:15:53 -0200 Subject: [PATCH 5/8] Make -n a parameter in the add directive --- wp | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/wp b/wp index f685cd9..cdebcf6 100755 --- a/wp +++ b/wp @@ -15,18 +15,13 @@ function main { DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" K_MEANS=16 WALLPAPER_DIR=${WALLPAPER_DIR:-~/.wallpapers/} - PARAM=$1 + if test $# -gt 0; then case "$1" in usage | -h | --help | help) shift usage ;; - n | -n) - shift - K_MEANS=$1 - shift - ;; add | -a | --add) shift add $* @@ -56,8 +51,7 @@ function main { slideshow $* ;; *) - shift - indent "$PARAM is not a recognised directive" + indent "$1 is not a recognised directive" ;; esac else @@ -88,6 +82,11 @@ function add { exit 1 fi + if [ '-n' = $1 ]; then + K_MEANS=$2 + shift 2 + fi + files=$* for file in $files; do @@ -101,7 +100,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 } @@ -233,18 +232,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. " } From fadf3a2cf5bec567b839ab2fb56c4fc6bfa4635b Mon Sep 17 00:00:00 2001 From: hugogrochau Date: Mon, 21 Dec 2015 18:22:43 -0200 Subject: [PATCH 6/8] Fix spelling mistake Recognised -> Recognized --- wp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp b/wp index cdebcf6..4d01291 100755 --- a/wp +++ b/wp @@ -51,7 +51,7 @@ function main { slideshow $* ;; *) - indent "$1 is not a recognised directive" + indent "$1 is not a recognized directive" ;; esac else From efcfce9edc29c1715842a878a80fd999f86eb8a0 Mon Sep 17 00:00:00 2001 From: Hugo Grochau Date: Mon, 16 Jan 2017 13:02:00 -0200 Subject: [PATCH 7/8] Use canonical path for wallpapers and remove sample files on deletion --- wp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wp b/wp index 4d01291..5325fda 100755 --- a/wp +++ b/wp @@ -14,7 +14,9 @@ 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")" if test $# -gt 0; then case "$1" in @@ -118,7 +120,7 @@ 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 } @@ -187,7 +189,7 @@ function get_current { } function set_current { - ln -sf $1 $WALLPAPER_DIR/.current + ln -sf $1 $WALLPAPER_DIR/.current } function list { From 78d33e2b40cfe3d0f2806ed7274c06b83a444137 Mon Sep 17 00:00:00 2001 From: Hugo Grochau Date: Thu, 13 Apr 2017 12:39:40 -0300 Subject: [PATCH 8/8] Add wp next as an alias to `wp change` --- wp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp b/wp index 5325fda..5cca878 100755 --- a/wp +++ b/wp @@ -32,7 +32,7 @@ function main { shift remove $* ;; - change) + change | next) shift change $* ;;