diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-03-19 03:32:37 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-03-19 03:32:37 +0100 |
commit | bddb70af344aad17d3579d59a613a403842e6ccb (patch) | |
tree | a87adb4ef314fd7ace9bf0f8c06d99989fe068c1 /examples | |
parent | bump version (diff) | |
download | blueshift-bddb70af344aad17d3579d59a613a403842e6ccb.tar.gz blueshift-bddb70af344aad17d3579d59a613a403842e6ccb.tar.bz2 blueshift-bddb70af344aad17d3579d59a613a403842e6ccb.tar.xz |
add modes example
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/modes | 63 |
1 files changed, 63 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. + +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()) + |