# -*- python -*- # This example can be used to name a mode you want to use, # without having to use Blueshift's -c option and give a # pathname. You will only need to give a filename. In this # example, those modes are installed in the directory # `$XDG_CONFIG_HOME/blueshift-modes`, and the default mode # is named `default`. # Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import os # Name of default mode. mode = 'default' # Directory of mode scripts. modedir = '%s/blueshift-modes' modedir_ = os.environ['XDG_CONFIG_HOME'] if 'XDG_CONFIG_HOME' in os.environ else None if modedir_ is None: home = os.environ['HOME'] if 'HOME' in os.environ else None if home is None: import pwd home = pwd.getpwuid(os.getuid()).pw_dir modedir_ = '%s/.config' % home modedir = (modedir % modedir_) + '/' # Get selected mode. if 'mode' in conf_storage: mode = conf_storage['mode'] else: conf_opts[:] = conf_opts[1:] if len(conf_opts) > 0: if not (conf_opts[0].startswith('-') or conf_opts[0].startswith('+')): mode = conf_opts[0] conf_opts[:] = conf_opts[1:] conf_storage['mode'] = mode conf_opts[:0] = [mode] # Exec mode script. mode_file = modedir + mode code = None with open(mode_file, 'rb') as script: code = script.read() code = code.decode('utf-8', 'error') + '\n' code = compile(code, mode_file, 'exec') exec(code, globals())