The first thing that springs to mind is `fd <https://github.com/sharkdp/fd>`
available on almost all package managers which would enable you to write,
independently of which shell you are running:

```
fd -e gpg -x gpg --verify {}
```
i.e.:
`-e gpg` : find all files with extension `gpg`
`-x gpg --verify {}` : execute `gpg --verify {}` for each result where `{}`
is the file name of each result

If you give it a straight argument with no switch it will search by regex.
Also note it defaults to recursive search, so
`fd "\.gpg$" -x gpg --verify {}` is identical, but to avoid the recursive
search you may write:

```
fd -e gpg -d 1 -x gpg --verify {}
```
or glob with
```
fd -g "*.gpg" -d 1 -x gpg --verify {}
```
where `-d 1` sets the max-depth to 1 (current directory) which will give
you the same result as your for loop.

Note you can do the same thing with the slightly harder to understand, but
almost universally preinstalled, 'find' command
```
find . -iname "*.gpg" -depth 1 -exec gpg --verify {} \;
```

The syntactic sugar idea for fish is an interesting one. I had a similar
idea for while loops for processing text files, sick of writing inline
while loops in the bash terminal; I found that

```
alias wd='while read -r line; do'
```

enabled me to do things like

```
grep fish < somefile.txt | wd echo "Look what I found! $line"; done
```

which in your case could be
```
ls -1 *.gpg | wd gpg --verify "$line"; done
```

But I have not quite figured out how to translate this in to a working fish
alias.

If it is just the gpg --verify case that's clunky to write repeatedly, a
function is the obvious answer. But I expect you are just giving this as an
example for something that could be more flexible functionality.

On Tue, May 23, 2023 at 9:47 PM Bobby <pnpplpn...@gmail.com> wrote:

> There is a syntactic sugar feature I have wanted for my shell since I
> first started using one, and I'm wondering if it's possible in fish or
> anyone has ideas for implementing it.
>
> Basically, it would be really nice to be able to write an implicit for
> loop the way one would use the wildcard operator.
>
> For example, if I have in a folder the files:
> sig1.asc
> sig2.asc
>
> I can match them all with *.asc. But if I pass that to gpg, like:
> gpg --verify *.asc
>
> That expands to:
> gpg --verify sig1.asc sig2.asc
>
> Which fails. The solution is that I use a for loop, like so:
> for i in *.asc
>     gpg --verify $i
> end
>
> But it would be really nice to type something like:
> gpg --verify ***.asc
>
> And have my shell do the same thing as the for loop above.
>
> Any ideas?
> _______________________________________________
> Fish-users mailing list
> Fish-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/fish-users
>
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to