From 7c3e1ad4e86a2f2747a63b81127f377a2a38e87c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 18 Mar 2018 15:23:30 +1100 Subject: [PATCH] theme: Added random option. -f random --- pywal/__main__.py | 4 +++- pywal/theme.py | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pywal/__main__.py b/pywal/__main__.py index 8086e39..d7ba602 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -106,7 +106,9 @@ def process_args(args): sys.exit(0) if args.f == "list_themes": - print("Themes:", ", ".join(theme.index())) + themes = theme.index() + themes = [theme.name.replace(".json", "") for theme in themes] + print("Themes:", ", ".join(themes)) sys.exit(0) if args.q: diff --git a/pywal/theme.py b/pywal/theme.py index 8023d73..66beac6 100644 --- a/pywal/theme.py +++ b/pywal/theme.py @@ -2,6 +2,7 @@ Theme file handling. """ import os +import random import sys from .settings import CONF_DIR, MODULE_DIR @@ -10,9 +11,11 @@ from . import util def index(): """List all installed theme files.""" - themes = os.listdir(os.path.join(CONF_DIR, "colorschemes")) - themes += os.listdir(os.path.join(MODULE_DIR, "colorschemes")) - return [theme.replace(".json", "") for theme in themes] + themes = [theme for theme in + os.scandir(os.path.join(CONF_DIR, "colorschemes"))] + themes += [theme for theme in + os.scandir(os.path.join(MODULE_DIR, "colorschemes"))] + return themes def terminal_sexy_to_wal(data): @@ -46,6 +49,11 @@ def file(input_file): elif os.path.isfile(theme_file): theme_file = theme_file + elif input_file == "random": + themes = [theme.path for theme in index()] + random.shuffle(themes) + theme_file = themes[0] + # Parse the theme file. if os.path.isfile(theme_file): data = util.read_file_json(theme_file)