mirror of
https://github.com/gryf/weechat-replacer.git
synced 2025-12-18 12:00:18 +01:00
Adapt to the upcoming way for WeeChat store configuration.
In version of 3.2 of WeeChat, the default way of storing the configuration and data, will be the XDG one. Let's adopt to this. Map file will be stored on different location depending of the version of weechat, but also, if mapping file would be spotted on one of the defined locations, it would be used. Whatever version of the weechat you have preferences are: $XDG_DATA_HOME/weechat/replacement_map.json $XDG_CONFIG_HOME/weechat/replacement_map.json ~/.weechat/weechat/replacement_map.json whatever $XDG_somethinig is pointed to, or where weechat_config_dir/weechat_data_dir are pointing. Those values are retrieved from WeeChat, so you should know, where the replacement_map should go.
This commit is contained in:
29
README.rst
29
README.rst
@@ -1,12 +1,12 @@
|
||||
weechat-replacer
|
||||
================
|
||||
|
||||
Weechat plugin for replacing user defined keywords with specified text.
|
||||
WeeChat plugin for replacing user defined keywords with specified text.
|
||||
|
||||
Installation and configuration
|
||||
------------------------------
|
||||
|
||||
In order to use it, you have to have Weechat with Python plugin support
|
||||
In order to use it, you have to have WeeChat with Python plugin support
|
||||
compiled in. Than, copy ``replacer.py`` to ``~/.weechat/python/``. You can use
|
||||
any of the Python version - both Python2 and Python3 are supported. You can
|
||||
optionally create symbolic link to this script:
|
||||
@@ -45,6 +45,31 @@ some replacement words, and text which would those words replaced with:
|
||||
and than, when you type ``foo`` word and press ``tab`` key, you should get
|
||||
``bar`` word instead.
|
||||
|
||||
|
||||
Upgrade to WeeChat 3.2
|
||||
----------------------
|
||||
|
||||
Starting from WeeChat 3.2 full XDG paths were implemented, so that there
|
||||
potentially will be a need to move your replacement definition file to move to
|
||||
the new location.
|
||||
|
||||
For now, you can do nothing, replacer data file will be still looked in old
|
||||
location, or you can move it to the new location.
|
||||
|
||||
If you decide to the migration, default location for the replacement map
|
||||
file will be the ``$weechat_data_dir`` which in most of the cases would be
|
||||
``~/.local/share/weechat``, unless you;re using ``--dir`` or ``--temp-dir``
|
||||
weechats params.
|
||||
|
||||
Anyway, if you plan to do the full migration to XDG, and you had your
|
||||
replacement definition file in ``~/.weechat/replacement_map.json``, and want to
|
||||
move to the XDG location, than you'll want to move your configuration to
|
||||
``$XDG_DATA_HOME/weechat``, which usually is ``~/.local/share/weechat`` before
|
||||
removing old location. Note, that migrating instructions only applies to the
|
||||
replacer plugin. For WeeChat itself, you'll need to consult WeeChat
|
||||
documentation.
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
|
||||
29
replacer.py
29
replacer.py
@@ -27,7 +27,7 @@ import weechat
|
||||
|
||||
NAME = 'replacer'
|
||||
AUTHOR = 'Roman Dobosz <gryf73@gmail.com>'
|
||||
VERSION = '1.2'
|
||||
VERSION = '1.3'
|
||||
LICENSE = 'Apache 2'
|
||||
DESC = 'Word replacer for WeeChat'
|
||||
COMMAND = 'replacer'
|
||||
@@ -61,13 +61,32 @@ class Replacer(object):
|
||||
# one, so it also could be global, but globals are bad, mkay?
|
||||
self_object = None
|
||||
|
||||
def __init__(self, path=None):
|
||||
def __init__(self):
|
||||
"""Initialize plugin"""
|
||||
self.replacement_map = {}
|
||||
self._path = path
|
||||
self._path = None
|
||||
|
||||
map_file = "replacement_map.json"
|
||||
data_dirs = (weechat.info_get("weechat_data_dir", ""),
|
||||
weechat.info_get("weechat_config_dir", ""),
|
||||
weechat.string_eval_path_home("%h", {}, {}, {}))
|
||||
|
||||
for path in data_dirs:
|
||||
if os.path.exists(os.path.join(path, map_file)):
|
||||
self._path = os.path.join(path, map_file)
|
||||
break
|
||||
|
||||
version = weechat.info_get("version_number", "") or 0
|
||||
|
||||
# nothing found. so there is no replacement file. let's assume the
|
||||
# right file path.
|
||||
if not path:
|
||||
path = '%h/replacement_map.json'
|
||||
self._path = weechat.string_eval_path_home(path, {}, {}, {})
|
||||
if version < 0x3020000: # < 3.2.0
|
||||
path = '%h/' + map_file
|
||||
self.path = weechat.string_eval_path_home(path, {}, {}, {})
|
||||
else:
|
||||
self.path = os.path.join(weechat.info_get("weechat_data_dir",
|
||||
""), map_file)
|
||||
self._get_replacement_map()
|
||||
|
||||
def _get_replacement_map(self):
|
||||
|
||||
Reference in New Issue
Block a user