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

folder listing (menu m-l) not working for my locale #883

Closed
jadero opened this issue Sep 8, 2018 · 3 comments
Closed

folder listing (menu m-l) not working for my locale #883

jadero opened this issue Sep 8, 2018 · 3 comments
Assignees

Comments

@jadero
Copy link

jadero commented Sep 8, 2018

Problem

Hitting m-l on a folder in NERDTree gives me 'shell command failed'. I tracked down the error to
FINDSTR "^[012][0-9]/[0-3][0-9]/[12][0-9][0-9][0-9]"
in file fs_menu.vim, function NERDTreeListNodeWin32(). The system date format for my Windows installation is set to yyyy-MM-dd, whereas the regular expression searches for MM-dd-yyyy.

Environment

Vim 8.1.1 with latest NERDTree, Windows 10 set to English language

@jadero
Copy link
Author

jadero commented Sep 8, 2018

Not sure about the corresponding linux function. This might need a fix too.

@jadero
Copy link
Author

jadero commented Sep 8, 2018

I hacked together the following code which seems to do the job:

" FUNCTION: NERDTreeListNodeWin32() {{{1
function! NERDTreeListNodeWin32()
    let l:node = g:NERDTreeFileNode.GetSelected()

    if !empty(l:node)

        let l:save_shell = &shell
        set shell&

        if exists('+shellslash')
            let l:save_shellslash = &shellslash
            set noshellslash
        endif

        " try different short date formats...
        let l:short_date_regex = [
            \ '^[01][0-9][/-][0-3][0-9][/-][12][0-9][0-9][0-9]',
            \ '^[0-3][0-9][/-][01][0-9][/-][12][0-9][0-9][0-9]',
            \ '^[12][0-9][0-9][0-9][/-][01][0-9][/-][0-3][0-9]',
            \ '^[01][0-9][/-][0-3][0-9][/-][0-9][0-9]',
            \ '^[0-3][0-9][/-][01][0-9][/-][0-9][0-9]',
            \ '^[0-9][0-9][/-][01][0-9][/-][0-3][0-9]'
        \]

        for regex in l:short_date_regex
            let l:command = 'DIR /Q '
                        \ . shellescape(l:node.path.str())
                        \ . ' | FINDSTR ' . regex

            let l:metadata = split(system(l:command), "\n")

            if v:shell_error == 0
                break
            endif
        endfor

        if v:shell_error == 0
            call nerdtree#echo(l:metadata[0])
        else
            call nerdtree#echoError('shell command failed')
        endif

        let &shell = l:save_shell

        if exists('l:save_shellslash')
            let &shellslash = l:save_shellslash
        endif

        return
    endif

    call nerdtree#echo('node not recognized')
endfunction

@jadero
Copy link
Author

jadero commented Sep 8, 2018

Further tweaked code which makes use of vim-misc plugin to prevent cmd window popups in the background (maybe a no-go but hey it workes nicely):

" FUNCTION: NERDTreeListNodeWin32() {{{1
function! NERDTreeListNodeWin32()
    let l:node = g:NERDTreeFileNode.GetSelected()

    if !empty(l:node)

        let l:save_shell = &shell
        set shell&

        if exists('+shellslash')
            let l:save_shellslash = &shellslash
            set noshellslash
        endif

        " try different short date formats...
        let l:short_date_regex = [
            \ '^[01][0-9][/-][0-3][0-9][/-][12][0-9][0-9][0-9]',
            \ '^[0-3][0-9][/-][01][0-9][/-][12][0-9][0-9][0-9]',
            \ '^[12][0-9][0-9][0-9][/-][01][0-9][/-][0-3][0-9]',
            \ '^[01][0-9][/-][0-3][0-9][/-][0-9][0-9]',
            \ '^[0-3][0-9][/-][01][0-9][/-][0-9][0-9]',
            \ '^[0-9][0-9][/-][01][0-9][/-][0-3][0-9]'
            \]

        let l:command = 'DIR /Q '
                    \ . shellescape(l:node.path.str())
                    \ . ' | FINDSTR '

        for regex in l:short_date_regex

            " Use xolox#misc#os#exec() from vim-misc plugin which has the
            " advantage of suppressing the cmd window popup in the background
            " (this happens with the Vim builtin system() function).
            let l:listNode = xolox#misc#os#exec({
                \ 'command': l:command.regex,
                \ 'async': 0,
                \ 'check': 0
                \})

            if l:listNode['exit_code'] == 0
                break
            endif
        endfor

        if l:listNode['exit_code'] == 0
            call nerdtree#echo(l:listNode['stdout'][0])
        else
            call nerdtree#echoError('shell command failed')
        endif

        let &shell = l:save_shell

        if exists('l:save_shellslash')
            let &shellslash = l:save_shellslash
        endif

        return
    endif

    call nerdtree#echo('node not recognized')
endfunction

@PhilRunninger PhilRunninger self-assigned this Sep 15, 2018
@PhilRunninger PhilRunninger added the in progress Work on resolving this issue has started. label Sep 15, 2018
@PhilRunninger PhilRunninger added PR Under Review Coding is finished, and a pull request has been created and is being reviewed. and removed in progress Work on resolving this issue has started. labels Sep 15, 2018
@PhilRunninger PhilRunninger removed the PR Under Review Coding is finished, and a pull request has been created and is being reviewed. label Oct 11, 2018
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

2 participants