From bddb70af344aad17d3579d59a613a403842e6ccb Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 19 Mar 2014 03:32:37 +0100 Subject: add modes example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- examples/modes | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 examples/modes (limited to 'examples/modes') diff --git a/examples/modes b/examples/modes new file mode 100644 index 0000000..8cac965 --- /dev/null +++ b/examples/modes @@ -0,0 +1,63 @@ +# -*- python -*- + +# This example can be used to name a mode you want to use, +# and load the script, without having the 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()) + -- cgit v1.2.3-70-g09d2