Loading ...
Sorry, an error occurred while loading the content.

Re: expand() and glob() too

Expand Messages
  • Dasn
    ... This kind of glob depends on your shell option, try csh instead whose glob command is better than the echo of POSIX sh. Or maybe you are interested
    Message 1 of 6 , Oct 31, 2007
    View Source
    • 0 Attachment
      On 31/10/07 17:43 +0100, Vladimir Marek wrote:
      >
      >============================ os_unix.c:6652 ============================
      > /* file names are separated with Space */
      > if (shell_style == STYLE_ECHO)
      > {
      > buffer[len] = '\n'; /* make sure the buffer ends in NL */
      > p = buffer;
      > for (i = 0; *p != '\n'; ++i) /* count number of entries */
      > {
      > while (*p != ' ' && *p != '\n')
      > ++p;
      > p = skipwhite(p); /* skip to next entry */
      > }
      > }
      >========================================================================
      >
      >and since the string was "/a/b/c 'd" it's separated to two files -
      >/a/b/c and 'd
      >
      >If I'm right with my investigation, I feel that the result is wrong. If
      >there is really file called "/a/b/c 'd" expand should return "/a/b/c 'd"
      >as one string.
      >
      >Thanks
      >

      This kind of glob depends on your 'shell' option, try 'csh' instead
      whose glob command is better than the 'echo' of POSIX sh.

      Or maybe you are interested in the patch I post to dev sometime ago.

      --
      Dasn


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Vladimir Marek
      [ ... ] ... I see now. The final goal is function which would tell me what files are in given directory. That s why I started to use glob. To be as correct as
      Message 2 of 6 , Nov 1, 2007
      View Source
      • 0 Attachment
        [ ... ]

        > This kind of glob depends on your 'shell' option, try 'csh' instead
        > whose glob command is better than the 'echo' of POSIX sh.
        >
        > Or maybe you are interested in the patch I post to dev sometime ago.

        I see now. The final goal is function which would tell me what files are
        in given directory. That's why I started to use glob. To be as correct
        as possible I started to write my wrapper function. So far it is:

        Unfortunately, it does not catch hidden files on windows :(

        fu! Glob(pattern)
        try
        if !has('unix')
        " Windows ... Can anything else fall here which is not apropriate ?
        let l:res=glob(a:pattern)
        break

        if match(&shell, '\(^\|/\)t\?csh$') >= 0
        " We do have (t)csh
        let l:res=glob(a:pattern)
        break
        endif

        if executable('csh') > 0 || executable('tcsh') > 0
        " We can reach (t)csh, so use it for a while
        let l:newsh='csh'
        if ( executable('csh') == 0 )
        let l:newsh='tcsh'
        endif

        let l:sh=&shell

        try
        exe "set shell=".l:newsh
        let l:res=glob(a:pattern)
        finally
        " Don't clobber the &shell variable
        exe "set shell=".l:sh
        endtry
        break
        endif

        if match(&shell, '\(^\|/\)bash$') >= 0
        " Bash way of getting all the files (works for bash 2 newer)
        let l:pat=substitute(a:pattern, '\([^[:alnum:]\*\?/_-]\)', '\\\1', "g")
        let l:res=system("shopt -s nullglob; for a in ".l:pat."; do echo \"$a\"; done")
        break
        endif

        if executable('python')
        " Python is common these days (Perl default glob implementation sucks)
        let l:res=system ('python', "import glob\nfor i in glob.glob('".escape(a:pattern,"'\\")."'):\n print i")
        break
        endif

        " Fallback to default
        let l:res=glob(a:pattern)
        endtry
        return split (l:res, "\n")
        endf

        I tested it on linux, solaris 8, solaris 10 and windows.

        Thank you for your input

        --
        Vlad
      Your message has been successfully submitted and would be delivered to recipients shortly.