Beni Cherniavsky wrote:
> Nice idea, but defining the scope of cd locality seems a bit tricky.
> E.g. currently "begin; ...; end" is equivalent to "if true; ...; end".
> So should "cd -l" also be local to "if"?  To any construct delimited by "end"?
> This is not always desired - consider::
> 
>   begin
>     if COND
>       cd SOME-DIR
>     else
>       cd OTHER-DIR
>     end
>     DO-SOMETHING-IN-DIR
>   end
> 
> where the "cd" should not be local to the "if" but should be local to
> the "begin".
> This is just an example.  I'm not sure it proves anything, but I fear
> there is no single clean and useful definition for the scope for "cd
> -l"...

use functional style. Admittedly it's a bit annoying in fish, but doable.

    begin
      cd -l (if COND
               echo SOME-DIR
             else
               echo OTHER-DIR
             end)
      DO-SOMETHING-IN-DIR
    end

or,

    begin
      set -l dir  #define the scope... of modifications to the var
      if COND
        set dir SOME-DIR
      else
        set dir OTHER-DIR
      end
      cd -l $dir
      DO-SOMETHING-IN-DIR
    end

But that makes me think it could be the same as

    begin
      cd -l   #define the scope... of modifications to the cwd
      if COND
        cd SOME-DIR
      else
        cd OTHER-DIR
      end
      DO-SOMETHING-IN-DIR
    end

which is actually equivalent in usage to what you suggest here:

> Alternative proposal: a new "saved [DIR]; ...; end" construct that
> explicitly saves and restores the working directory in that block
> (temporarily changing to DIR if given).

aka just like pushd/popd but more reliable.

> Alternative 2 (half-baked): some kind of "try..finally..end" construct
> to ensure the execution of things like "popd"?

I don't like it much.  I forget what kind of "exceptions" fish has. 
Depends if we come up with any other examples of things that have to be 
restored (and if we can also do the cleanup C++ RAII style, positioning 
the cleanup in the same place in the script code as where the thing that 
needs to be cleaned up is begun)


now, if only there were a good way to call back into fish from commands, 
e.g.

set FOOL foo
#imaginary parenthesis syntax to create a command not a string:
env FOOL=bar (echo 3; cd $FOOL; set FOOL $FOOL)
#where does the "3" go to?  Are we in the "bar" directory now?
#Does FOOL have its prior value, or "bar"?
#Fish hates the idea of subshells, remember...
sudo (cat $FOOL > /sys/wherever)

But I fear issues of variable scoping (environmental, cwd...) and pipes 
(stdout,stderr...) might make that too unintuitive no matter how it's done.

(if we did, we could perhaps just make more commands that didn't have to 
be part of the shell)

-Isaac

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to