diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2017-06-28 20:21:22 +1000 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2017-06-28 20:21:22 +1000 |
| commit | c00df332aa1abeb67d340c6a2d5dffe46ae5b7ee (patch) | |
| tree | 6c2f9f0151f622154fb20490e3990a2ec4348eab /pywal | |
| parent | 3121a1a5c8d8ce6880147573769d7ad858f0fa4f (diff) | |
General: Fix bug when shuffling in a directory with only one image.
Diffstat (limited to 'pywal')
| -rwxr-xr-x | pywal/gen_colors.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/pywal/gen_colors.py b/pywal/gen_colors.py index c4a4623..4b606dc 100755 --- a/pywal/gen_colors.py +++ b/pywal/gen_colors.py @@ -17,13 +17,17 @@ def random_img(img_dir): current_wall = pathlib.Path(CACHE_DIR / "wal") if current_wall.is_file(): - current_wall = util.read_file(current_wall) - current_wall = os.path.basename(current_wall[0]) + wallpaper = util.read_file(current_wall) + current_wall = os.path.basename(wallpaper[0]) # Add all images to a list excluding the current wallpaper. file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif") images = [img for img in os.scandir(img_dir) - if img.name.endswith(file_types) and img.name != current_wall] + if img.name.endswith(file_types) and img.name != wallpaper] + + # If no images are found, use the current wallpaper. + if not images: + return pathlib.Path(wallpaper) return pathlib.Path(img_dir / random.choice(images).name) |
