Tuesday, June 16, 2015

Re: extglob unset when filtering/writing text lines to bash

2015-06-17 8:31 GMT+03:00 Nikolay Pavlov <zyx.vim@gmail.com>:
> 2015-06-16 4:55 GMT+03:00 Paul <paul.domaskis@gmail.com>:
>> On Monday, June 15, 2015 at 9:11:12 PM UTC-4, Gary Johnson wrote:
>>> I had the same problem a while back, but in my case I could verify
>>> that my ~/.bashrc was _not_ being sourced when Vim executed bash.
>>>
>>>On 2015-06-15, Paul wrote:
>>>> To track down the cause, I created the dummy text line
>>>>
>>>> shopt -p extglob
>>>>
>>>> and used diagnostic echo commands to ensure that the above 2
>>>> invocations of bash actually execute ~/.bashrc and ~/.alias.bash
>>>> (they do). For both bash invocations, extglob is unset.
>>>
>>> Your observation that extglob is not set contradicts your claim that
>>> ~/.bashrc is being sourced.
>>
>> Indeed, that's part of the puzzle.
>>
>>> As you say later, it should not be.
>>> How did you determine that ~/.bashrc is being sourced?
>>
>> In each of.bashrc and .alias.bash, I put echo statements saying that
>> the files is being run. In all my tests so far, they have run, though
>> as I said, I'm not sure why. They're not suppose to as far as I
>> understand (which is not a very high bar!).
>>
>>> Having determined in my case that ~/.bashrc was not being sourced
>>> when Vim invoked bash (except as :sh), and not really wanting it to
>>> be sourced in that case because of the overhead, I found two
>>> solutions.
>>>
>>> One is to put the following in my ~/.vimrc:
>>>
>>> set shellcmdflag=-O\ extglob\ -c
>>
>> Based on your post, I tried each of the following:
>>
>> set shellcmdflag=-i\ -c
>> set shellcmdflag=-O\ extglob\ -c
>>
>> For each setting, I rested the cursor on the following text line:
>>
>> shopt -p extglob
>>
>> and tried each of the following:
>>
>> !!bash
>> :. w !bash
>>
>> For each test, both ~/.bashrc and ~/.alias.bash ran, but extglob was
>> unset.
>
> Of course. You run bash *inside* bash -i -c configured by
> &shellcmdflag and *that* bash is doing execution. It is absolutely
> irrelevant what &shell* settings are in this case: you can have `set
> shell=fish` and get exactly the same result with exactly the same fix:
> use `!!bash -i -c`.

Without `-c`, `-c` is for &shellcmdflag.

>
> ~/.bashrc is run in the *outer* bash which is run by Vim. If
> everything is OK it should be run twice: once for outer bash run by
> Vim and once for inner bash run at your request by bash.
>
>>
>>> The other, which I currently use, is to create a file,
>>> ~/.vim/bash_env.sh, which contains the following:
>>>
>>> shopt -s extglob # Enable !(pattern-list).
>>>
>>> and then put this in my ~/.vimrc:
>>>
>>> if !exists("$BASH_ENV") || $BASH_ENV == ""
>>> if filereadable($HOME . "/.vim/bash_env.sh")
>>> let $BASH_ENV = "$HOME/.vim/bash_env.sh"
>>> endif
>>> endif
>>>
>>> The second seems more robust to me in part because I use the same
>>> ~/.vimrc on a variety of machines and OSes and the first solution
>>> doesn't work on Vims older that 7.3.269.
>>
>> I looked up BASH_ENV, and I see what you're doing. However, my vimrc
>> (which is confirmed to run) explicitly does shopt -s extglob. In
>
> If *vimrc* is doing `shopt -s extglob` then these setting will
> disappear immediately because it persist only as long as shell is run.
>
>> fact, I added an immediately subsequent shopt -p extglob, which
>
> The only reason this may work is that you have `-i` in flags and
> bashrc is setting shopt.
>
>> confirms that extglob was successfully enabled. That's great when
>> ~/.bashrc is running, but once that's done, it seems that it doesn't
>> persist to the point where the code banged out from vim is run. Very,
>> very weird.
>>
>> It's late, but I've got your example code above to try when I get a
>> few extra moments. It's obvious that the shopt setting of extglob
>> gets dropped sometime between completion of ~/.bashrc and execution of
>> the code that is banged out from vim. BASH_ENV may solve the problem
>> because it is persistent, and may get picked up by whatever bash
>> process actually ends up running the banged out code.
>>
>> Thanks.
>>
>> --
>> --
>> 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
>>
>> ---
>> You received this message because you are subscribed to the Google Groups "vim_use" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment