Thursday, May 26, 2011

Re: Previewing files in localhost on Mac

>> map <F1> :w<CR>:!open -a Google\ Chrome `echo
>> http://localhost/${PWD\#*/*/*/*/*/}/%`<CR>
[...]
>> Also, is there someone out there willing to break down this
>> piece of code for me: ${PWD\#*/*/*/*/*/}. It manages to strip
>> directories from the left of the string, but how? So far I
>> looked here but it didn't shed any light:
>> http://www.gnu.org/software/bash/manual/bashref.html#Word-Spl
>> itting
>
> it appears to be parameter expansion -- see that same html,
> search on ${parameter#word}, but because the '#' is escaped it
> looks like an error to me, and gives a 'bad substitution'
> error if i try to echo that thing on the command line

The # isn't escaped as far as bash is concerned; it's only escaped for
Vim (so it isn't interpreted as the alternate file name). Vim sees

:!open -a Chrome `echo http://localhost/${PWD\#*/*/*/*/*/}/%`

and bash sees

:!open -a Chrome `echo http://localhost/${PWD#*/*/*/*/*/}/somefile`

> for all i know mac has their own flavor of shell that's
> disturbingly different from linux bash

The Mac uses bash as its default shell. It is slightly modified, I
think, but not much. Just your usual kind of distro modifications, e.g.
slightly different startup file behaviour/locations, etc..

I do have a bit of a solution to your actual problem, but it'll have to
wait till a bit later to be shared, I'm afraid.

Ben.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment