In your "set" command, you're letting the shell expand the glob pattern and
passing all the paths to your function.

If you want to delay expanding the pattern, then "eval" is your friend

append_to_path_if_exists "~/.gem/ruby/*/bin"
"/Applications/ghc-*.app/Contents/bin"

function append_to_path_if_exists
    for arg in $argv
        eval set dirs $arg
        for dir in $dirs
            do something with $dir
        end
    end
end

​Obviously take care: eval is a loaded gun

append_to_path_if_exists "(touch this_can_be_evil)"
​

On Tue, Jul 12, 2016 at 5:18 PM, Michael Stillwell <m...@beebo.org> wrote:

> Actually assigning to a temporary variable to avoid the unmatched glob
> error is quite a bit nicer:
>
>   set d /Applications/ghc-*.app/Contents/bin
>   append_to_path_if_exists $d
>
>
>
>
> Michael
>
> On Tue, Jul 12, 2016 at 9:39 PM, Michael Stillwell <m...@beebo.org> wrote:
> > Is there any way to force fish to perform parameter expansion on a
> > variable? That is, if a variable is equal to "*.txt", how can that be
> > expanded to "bar.txt baz.txt" or "" or whatever it actually matches?
> >
> > The motivation for this is so that it's possible to write a function
> > "append_to_path_if_exists" that appends its argument to
> > fish_user_paths if and only if the argument actually exists as a
> > directory. So I want to be able to do:
> >
> > append_to_path_if_exists "/Applications/ghc-*.app/Contents/bin"
> > append_to_path_if_exists "~/.gem/ruby/*/bin"
> > append_to_path_if_exists "/usr/lib/go-*/bin"
> >
> > Without the quotes, fish (now) whines if these directories don't
> > exist, but with the quotes, I can't figure out a good way to actually
> > expand the argument within the append_to_path_if_exists function.
> >
> > This is sort of possible via a subshell, but it's hardly ideal:
> >
> > function glob
> >   echo (fish -c "count $argv > /dev/null ; and echo $argv")
> > end
> >
> > $ glob "*.txt"
> > bar.txt baz.txt
> > $ glob "jjj*"
> >
> > (Also doesn't work with multiple arguments.)
> >
> > Am I going about this the wrong way?
> >
> >
> >
> >
> > Michael
>
>
> ------------------------------------------------------------------------------
> What NetFlow Analyzer can do for you? Monitors network bandwidth and
> traffic
> patterns at an interface-level. Reveals which users, apps, and protocols
> are
> consuming the most bandwidth. Provides multi-vendor support for NetFlow,
> J-Flow, sFlow and other flows. Make informed decisions using capacity
> planning
> reports.http://sdm.link/zohodev2dev
> _______________________________________________
> Fish-users mailing list
> Fish-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/fish-users
>



-- 
*Glenn Jackman*
Senior Software Developer

*Pythian - Love your data*
jack...@pythian.com
Tel: +1 613 565 8696 Ext. 1478
Mobile: +1 613 808 4984
www.pythian.com

-- 


--



------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to