con-f-use / xontrib-histcpy

Useful aliases and shortcuts for extracting links and text from command output history in xonsh
https://pypi.org/project/xontrib-histcpy/
GNU General Public License v3.0
4 stars 3 forks source link

Improve the way special chars are handled in getouts #2

Open con-f-use opened 5 years ago

con-f-use commented 5 years ago

I do not like the lack of proper handling of "inner quotation" and special characters in the commands.

def _getouts_completer(prefix, line, begidx, endidx, ctx):
    if not line.lstrip().startswith('getout'):
        return set()
    # ToDo: handle quotation marks better
    def canonize(s):
        return "'"+s.replace('"', '\\"').replace("'", "\\'")+"'"
return {canonize(o) for o in _getoutputs().keys() if o.startswith(prefix)}