summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2018-03-18 15:23:30 +1100
committerDylan Araps <dylan.araps@gmail.com>2018-03-18 15:23:30 +1100
commit7c3e1ad4e86a2f2747a63b81127f377a2a38e87c (patch)
tree084e3830660704db4cd808297fdf3fc7878f14aa
parent1cff79bcc6f64c8b52c255c9dd161cd5564bf748 (diff)
theme: Added random option. -f random
-rw-r--r--pywal/__main__.py4
-rw-r--r--pywal/theme.py14
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)