Open peterhinch opened 5 years ago
This can be tried via my fork.
I think that the macro facility is a great idea.
In that case I'll submit a PR.
I'm already finding it useful, notably in projects using Python packages with a nested directory structure and long rshell commands.
The solution to the mv command would be safer if there were a fix to https://github.com/dhylands/rshell/issues/112.
This would add a facility to import a Python module containing a
dict
of macros. At the rshell prompt a macro would be expanded. For example, a user macrocopy
taking a filename argument would be expanded and run as follows:To include a user specified macro file rshell would be invoked with
which would cause it to import
my_macro_file.py
by searching the Python path in the usual way.A typical macro file might look like
A macro module exports a
dict
namedmacros
whose key is the macro name. The value is either a string or a 2-tuple. In the latter case element[0] is the expansion and element[1] is a help string. The latter would be accessed by theml
(macro list) commandThis would display the expansion string and the help string (if present). Issued with no args,
ml
would list all available macros.Note that arguments are supported by Python string
format
syntax so there can be any number with arbitrary placement in the expansion.Design
The macro facility is likely to be used by experienced programmers maintaining larger projects. The proposal therefore assumes competence in Python and prioritises flexibility over user friendliness.
There are potential issues over recursive macros and ones whose expansion contains newline characters. I would propose disallowing recursion and whitespace.
Macros would only be expanded at the
>
prompt. At the$
prompt the user would surely employ scripting. [EDIT] I have prototyped this successfully - I anticipate significant time savings.Comments welcome, in particular whether anyone else would find this useful.