Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with running autojump on Windows 10 and python 3.9 #628

Open
shanyutou opened this issue Feb 8, 2021 · 5 comments
Open

Problem with running autojump on Windows 10 and python 3.9 #628

shanyutou opened this issue Feb 8, 2021 · 5 comments

Comments

@shanyutou
Copy link

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

@shanyutou shanyutou changed the title Problem with installing autojump on Windows 10 and python 3.9 Problem with running autojump on Windows 10 and python 3.9 Feb 8, 2021
@shanyutou
Copy link
Author

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

@shanyutou
Copy link
Author

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

@JoiGud
Copy link

JoiGud commented Mar 1, 2021

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.

@ColinKennedy
Copy link

ColinKennedy commented Aug 18, 2021

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)

@ghost-lth
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants