├── .gitignore ├── LICENSE ├── README.md ├── setup.py └── wal_vtop.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Evan Lock 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wal_vtop 2 | 3 | Automate [vtop](https://github.com/MrRio/vtop) theme creation from generated [pywal](https://github.com/dylanaraps/pywal) colors 4 | 5 | ## About 6 | 7 | `wal_vtop` is a small Python utility meant to work with `wal` by reading colors generated from a JSON file and translating them into a JSON-based `vtop` theme file. 8 | 9 | ## Install 10 | 11 | ```bash 12 | git clone `https://github.com/elock37/wal_vtop.git` 13 | cd wal_vtop 14 | pip install . 15 | ``` 16 | 17 | ### Requirements 18 | 19 | * [python3](https://www.python.org/) 20 | 21 | Tested with Python 3.6.4. Uses standard sys calls so should function across all Python 3. 22 | 23 | * [pywal](https://github.com/dylanaraps/pywal) 24 | 25 | ## Use 26 | 27 | **Be sure you've run `wal` at least once to generate colors.json file.** 28 | 29 | Simply invoke `wal-vtop` 30 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """wal_vtop - setup.py""" 2 | import setuptools 3 | 4 | try: 5 | import wal_vtop 6 | except (ImportError): 7 | print("error: wal_vtop requires Python 3.5 or greater.") 8 | quit(1) 9 | 10 | VERSION = wal_vtop.VERSION 11 | DOWNLOAD = "https://github.com/elock37/wal_vtop/archive/%s.tar.gz" % VERSION 12 | 13 | 14 | setuptools.setup( 15 | name="wal_vtop", 16 | version=VERSION, 17 | author="Evan Lock", 18 | author_email="elock37@gmail.com", 19 | description=" Automate vtop theme creation from generated pywal colors", 20 | license="MIT", 21 | url="https://github.com/elock37/wal_vtop", 22 | download_url=DOWNLOAD, 23 | classifiers=[ 24 | "Environment :: X11 Applications", 25 | "License :: OSI Approved :: MIT License", 26 | "Operating System :: POSIX :: Linux", 27 | "Programming Language :: Python :: 3.5", 28 | "Programming Language :: Python :: 3.6", 29 | ], 30 | install_requires="pywal >= 0.6.7", 31 | scripts=['wal_vtop.py'], 32 | entry_points={ 33 | "console_scripts": ["wal-vtop=wal_vtop:main"] 34 | }, 35 | python_requires=">=3.5", 36 | include_package_data=True 37 | ) 38 | -------------------------------------------------------------------------------- /wal_vtop.py: -------------------------------------------------------------------------------- 1 | import os.path 2 | import json 3 | import sys 4 | import argparse 5 | 6 | # wal_vtop details 7 | VERSION = "0.1.1" 8 | 9 | # Get path for vtop themes 10 | vtop_file = "wal.json" 11 | 12 | def setConfig(): 13 | # Get host OS 14 | hostOS = getOS() 15 | # Get user home directory 16 | home_dir = os.getenv("HOME", os.getenv("USERPROFILE")) 17 | # Set wal colors file 18 | wal_colors = os.path.join(home_dir, ".cache", "wal", "colors.json") 19 | # Confirm wal export exists 20 | if not os.path.isfile(wal_colors): 21 | # Print error and exit if not found 22 | print("Wal colors could not be found. Try running `wal` again") 23 | sys.exit(1) 24 | # Set vtop directory by platform 25 | if hostOS == "linux": 26 | vtop_path = "/usr/lib/node_modules/vtop/themes" 27 | vtop_theme = os.path.join(vtop_path, vtop_file) 28 | elif hostOS == "win32": 29 | print("Windows platform not supported") 30 | sys.exit(1) 31 | elif hostOS == "darwin": 32 | vtop_path = "/usr/local/lib/node_modules/vtop/themes" 33 | vtop_theme = os.path.join(vtop_path, vtop_file) 34 | else: 35 | # Print error and exit if OS unsupported 36 | print("Unsupported operating system") 37 | sys.exit(1) 38 | # Return file paths as strings for wal color file and vtop theme file 39 | return wal_colors, vtop_theme 40 | 41 | def themeVtop(wal_colors_path, vtop_theme_path): 42 | # Open colors.json and load 43 | import_colors = json.load(open(wal_colors_path)) 44 | 45 | # Transfer wal colors to vtop theme json scheme 46 | walj = { 47 | "name": "Wal", 48 | "author": "epl", 49 | "title": { 50 | "fg": import_colors['colors']['color1'] 51 | }, 52 | "chart": { 53 | "fg": import_colors['colors']['color1'], 54 | "border": { 55 | "type": "line", 56 | "fg": import_colors['colors']['color1'] 57 | } 58 | }, 59 | "table": { 60 | "fg": import_colors['colors']['color15'], 61 | "items": { 62 | "selected": { 63 | "bg": import_colors['colors']['color1'], 64 | "fg": import_colors['colors']['color15'] 65 | }, 66 | "item": { 67 | "fg": import_colors['colors']['color1'] 68 | } 69 | }, 70 | "border": { 71 | "type": "line", 72 | "fg": import_colors['colors']['color1'] 73 | } 74 | }, 75 | "footer": { 76 | "fg": import_colors['colors']['color1'] 77 | } 78 | } 79 | 80 | # Write theme json to vtop themes directory 81 | try: 82 | with open(vtop_theme_path, 'w') as f: 83 | json.dump(walj, f) 84 | if os.path.isfile(vtop_theme_path): 85 | print("vtop theme written successfully. start vtop with `vtop --theme wal` to view") 86 | except: 87 | print("Error writing vtop theme file") 88 | sys.exit(1) 89 | 90 | def getOS(): 91 | # system call for user platform 92 | hostOS = sys.platform 93 | # return os as string: linux, win32, darwin 94 | return hostOS 95 | 96 | def getArgs(): 97 | # get the arguments with argparse 98 | description = "wal vtop" 99 | arg = argparse.ArgumentParser(description=description) 100 | 101 | arg.add_argument("-v", "--version", action="store_true", 102 | help="Print wal_vtop version.") 103 | 104 | return arg.parse_args() 105 | 106 | def main(): 107 | # Parse arguments 108 | arguments = getArgs() 109 | # Print app version 110 | if arguments.version: 111 | print("wal vtop", VERSION) 112 | sys.exit() 113 | # Set file paths 114 | wcp, vtp = setConfig() 115 | # Translate and write theme 116 | themeVtop(wcp, vtp) 117 | 118 | if __name__ == '__main__': 119 | main() 120 | --------------------------------------------------------------------------------