summaryrefslogtreecommitdiff
path: root/pywal/__main__.py
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-06-26 12:09:35 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-06-26 12:09:35 +1000
commit583a0c19ad2f67a54130a219eeeaccf53ea08ded (patch)
treea72b51a6cf219c46c55f8fe9033814c48d23d48b /pywal/__main__.py
parentd17282cdc01a41cc70e0919ace55715eac3dd6d1 (diff)
General: Split wal into multiple files.
Diffstat (limited to 'pywal/__main__.py')
-rwxr-xr-xpywal/__main__.py108
1 files changed, 106 insertions, 2 deletions
diff --git a/pywal/__main__.py b/pywal/__main__.py
index 4781f8f..7ede827 100755
--- a/pywal/__main__.py
+++ b/pywal/__main__.py
@@ -2,7 +2,111 @@
wal - Generate and change colorschemes on the fly.
Created by Dylan Araps.
"""
-from pywal.wal import main
+import argparse
+import os
+import shutil
+import sys
+from pywal import settings as s
+from pywal import export
+from pywal import gen_colors
+from pywal import set_colors
+from pywal import wallpaper
+from pywal import util
-main()
+
+__version__ = "0.1.6"
+
+
+def get_args():
+ """Get the script arguments."""
+ description = "wal - Generate colorschemes on the fly"
+ arg = argparse.ArgumentParser(description=description)
+
+ # Add the args.
+ arg.add_argument("-c", action="store_true",
+ help="Delete all cached colorschemes.")
+
+ arg.add_argument("-i", metavar="\"/path/to/img.jpg\"",
+ help="Which image or directory to use.")
+
+ arg.add_argument("-n", action="store_true",
+ help="Skip setting the wallpaper.")
+
+ arg.add_argument("-o", metavar="\"script_name\"",
+ help="External script to run after \"wal\".")
+
+ arg.add_argument("-q", action="store_true",
+ help="Quiet mode, don\"t print anything and \
+ don't display notifications.")
+
+ arg.add_argument("-r", action="store_true",
+ help="Reload current colorscheme.")
+
+ arg.add_argument("-t", action="store_true",
+ help="Fix artifacts in VTE Terminals. \
+ (Termite, xfce4-terminal)")
+
+ arg.add_argument("-v", action="store_true",
+ help="Print \"wal\" version.")
+
+ return arg.parse_args()
+
+
+def process_args(args):
+ """Process args."""
+ # If no args were passed.
+ if not len(sys.argv) > 1:
+ print("error: wal needs to be given arguments to run.\n"
+ " Refer to \"wal -h\" for more info.")
+ exit(1)
+
+ # -q
+ if args.q:
+ sys.stdout = sys.stderr = open(os.devnull, "w")
+ s.Args.notify = False
+
+ # -c
+ if args.c:
+ shutil.rmtree(s.CACHE_DIR / "schemes")
+ util.create_cache_dir()
+
+ # -r
+ if args.r:
+ gen_colors.reload_colors(args.t)
+
+ # -v
+ if args.v:
+ print(f"wal {__version__}")
+ exit(0)
+
+ # -i
+ if args.i:
+ image = gen_colors.get_image(args.i)
+ s.ColorType.plain = gen_colors.get_colors(image)
+
+ if not args.n:
+ wallpaper.set_wallpaper(image)
+
+ # Set the colors.
+ set_colors.send_sequences(s.ColorType.plain, args.t)
+ export.export_colors(s.ColorType.plain)
+
+ # -o
+ if args.o:
+ util.disown(args.o)
+
+
+def main():
+ """Main script function."""
+ util.create_cache_dir()
+ args = get_args()
+ process_args(args)
+
+ # This saves 10ms.
+ # pylint: disable=W0212
+ # os._exit(0)
+
+
+if __name__ == "__main__":
+ main()