Created
December 25, 2019 11:31
-
-
Save rbtylee/225564776ef182e1084c3ee183232c9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# elm_icon | |
# | |
# Copyright (c) Robert Wiley <ylee@bodhilinux.com> | |
# The WTFPL License [http://www.wtfpl.net/] | |
# This work is free. You can redistribute it and/or modify it under the | |
# terms of the Do What The Fuck You Want To Public License, Version 2, | |
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. | |
''' | |
elm_icon - set the elementary icon theme. | |
USAGE: elm_icon [OPTION] or | |
elm_icon [theme_name] | |
elm_icon -- theme_name | |
DESCRIPTION: | |
A simple cli script to set the icon theme elementary apps are using. | |
This avoids the need to open elementary_config to make such a change. | |
OPTIONS: | |
-h, --help | |
Show this help screen | |
-a, --all | |
List all available icon themes | |
-v, --version | |
Show program version | |
-l, --license | |
Show program license | |
[theme_name] | |
Sets the elementary icon theme if the theme exists. | |
If theme name is '_elm', the icon theme is set the icon theme | |
defined by the current elementary theme. | |
If no options and no theme is specified, prints the current | |
elementary icon theme and exits. | |
''' | |
import os | |
import sys | |
from efl import elementary as elm | |
__version__ = "0.0.1" | |
__license__ = 'WTFPLv2 (c) Robert Wiley <ylee@bodhilinux.com> ' | |
def parse_args(args): | |
'''Parse cli arguments''' | |
if len(args) == 1: | |
show(elm.Configuration().icon_theme, 0) | |
elif len(args) > 2 and args[1] != '--': | |
show(__doc__, 1) | |
elif args[1] == '-h' or args[1] == '--help': | |
show(__doc__, 0) | |
elif args[1] == '-v' or args[1] == '--version': | |
show(f'{args[0]} v{__version__}', 0) | |
elif args[1] == '-l' or args[1] == '--license': | |
show(__license__, 0) | |
elif args[1] == '-a' or args[1] == '--all': | |
show('\n'.join(icon_themes()), 0) | |
elif args[1] == '--' and len(args) == 3: | |
args[1] = args[2] | |
elif len(args) > 3: | |
show(__doc__, 1) | |
if args[1] != '_elm' and args[1] not in icon_themes(): | |
show(f'Error: unable to find theme: "{args[1]}".', 1) | |
return "_Elementary_Icon_Theme" if args[1] == "_elm" else args[1] | |
def show(msg, ret): | |
'''Show message and exit.''' | |
print(msg) | |
exit(ret) | |
def icon_themes(): | |
'''Return a string of all icon themes found.''' | |
icon_paths = ['/usr/share/icons', '~/.icons', '~/.local/share/icons'] | |
d_list = ['_Elementary_Icon_Theme'] | |
for path in icon_paths: | |
icon_path = os.path.expanduser(path) | |
try: | |
for folder in os.listdir(icon_path): | |
f_path = os.path.join(icon_path, folder) | |
if os.path.isdir(f_path): | |
# Simple validation to ensure f_path is icon folder | |
if os.path.isfile(os.path.join(f_path, 'index.theme')): | |
d_list.append(folder) | |
except OSError: | |
pass | |
d_list.sort(key=str.lower) | |
return d_list | |
if __name__ == "__main__": | |
THEME = parse_args(sys.argv) | |
elm.Configuration().icon_theme = THEME | |
elm.Configuration().all_flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment