summary refs log tree commit diff stats
path: root/examples/plugin_new_macro.py
blob: ec0c487cdacbffc3ee6daadcbf205213a98fe97f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# This plugin adds the new macro %date which is substituted with the current
# date in commands that allow macros.  You can test it with the command
# ":shell echo %date; read"

# Save the original macro function
import ranger.core.actions
old_get_macros = ranger.core.actions.Actions._get_macros

# Define a new macro function
import time
def get_macros_with_date(self):
       macros = old_get_macros(self)
       macros['date'] = time.strftime('%m/%d/%Y')
       return macros

# Overwrite the old one
ranger.core.actions.Actions._get_macros = get_macros_with_date
9;__main__': from __init__ import init; init() from unittest import TestCase, main class Test(TestCase): def test_wrapper(self): from ranger.keyapi import Wrapper class dummyfm(object): def move(relative): return "I move down by {0}".format(relative) class commandarg(object): def __init__(self): self.fm = dummyfm self.n = None arg = commandarg() do = Wrapper('fm') command = do.move(relative=4) self.assertEqual(command(arg), 'I move down by 4') if __name__ == '__main__': main()