wting / autojump

A cd command that learns - easily navigate directories from the command line

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with running autojump on Windows 10 and python 3.9

shanyutou opened this issue · comments

Traceback (most recent call last):
File "C:\Users\yixiu\AppData\Local\autojump\bin\autojump", line 342, in
sys.exit(main(parse_arguments()))
File "C:\Users\yixiu\AppData\Local\autojump\bin\autojump", line 332, in main
print_local(first(chain(
File "C:\Users\yixiu\AppData\Local\autojump\bin\autojump_utils.py", line 41, in first
return it.next()
File "C:\Users\yixiu\AppData\Local\autojump\bin\autojump_match.py", line 83, in
found = lambda entry: re.search(
File "E:\dev\Python\lib\re.py", line 201, in search
return _compile(pattern, flags).search(string)
File "E:\dev\Python\lib\re.py", line 304, in _compile
p = sre_compile.compile(pattern, flags)
File "E:\dev\Python\lib\sre_compile.py", line 764, in compile
p = sre_parse.parse(p, flags)
File "E:\dev\Python\lib\sre_parse.py", line 948, in parse
p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
File "E:\dev\Python\lib\sre_parse.py", line 443, in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
File "E:\dev\Python\lib\sre_parse.py", line 549, in _parse
raise source.error("unterminated character set",
re.error: unterminated character set at position 4

re.escape(os.sep) because on windows os.sep is \ and need escape #618

CMD works, but PowerShell can't find the path properly.

I followed this guide https://leetschau.github.io/autojump-in-windows-console.html and added these lines to bin/autojump_math.py:78-88:

sep = '\\\\' if os.sep == '\\' else os.sep
regex_no_sep = '[^' + sep + ']*'
regex_no_sep_end = regex_no_sep + '$'
regex_one_sep = regex_no_sep + sep + regex_no_sep

And I also had to add the /bin folder of the repo to the Environmental variables of windows. The install script didn't cut it (maybe because I was using it in PowerShell?)

I still however can't get it to work with PowerShell, but it works on command prompt 🤷

Using python version 3.9.2.

I can confirm the same traceback issue on Python 3.7.9 and the fix @JoiGud mentions works. In my case, I did

def match_consecutive(needles, haystack, ignore_case=False):
    """
    Matches consecutive needles at the end of a path.

    For example:
        needles = ['foo', 'baz']
        haystack = [
            (path='/foo/bar/baz', weight=10),
            (path='/foo/baz/moo', weight=10),
            (path='/moo/foo/baz', weight=10),
            (path='/foo/baz', weight=10),
        ]

        # We can't actually use re.compile because of re.UNICODE
        regex_needle = re.compile(r'''
            foo     # needle #1
            [^/]*   # all characters except os.sep zero or more times
            /       # os.sep
            [^/]*   # all characters except os.sep zero or more times
            baz     # needle #2
            [^/]*   # all characters except os.sep zero or more times
            $       # end of string
            ''')

        result = [
            (path='/moo/foo/baz', weight=10),
            (path='/foo/baz', weight=10),
        ]
    """
    sep = '\\\\' if os.sep == '\\' else os.sep
    regex_no_sep = '[^' + sep + ']*'
    regex_no_sep_end = regex_no_sep + '$'
    regex_one_sep = regex_no_sep + sep + regex_no_sep
    regex_needle = regex_one_sep.join(imap(re.escape, needles)) + regex_no_sep_end
    regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE
    found = lambda entry: re.search(
        regex_needle,
        entry.path,
        flags=regex_flags,
    )
    return ifilter(found, haystack)

could anyone tell me how to run autojump in powershell ? I can jump in cmd but nothing happend in powershell