It is in theory better implemented as a StructMap because it is a transparent
data type. However, the reflection-based algorithm for StructMap will create a
"kind" field for it, and we don't want to remove the custom kind of Pipe yet, so
this has to be a PseudoStructMap now.
In light of the preceding change to address staticcheck lint warnings I
ran this:
grep 'errors\.New("' **.go |
sed -e 's/^.*errors\.New("\([^"]*\)".*/\1/' |
sort | uniq -c | sort -n
Which caused me to notice two errors associated with the builtin `sleep`
command have multiple definitions. It is questionable whether the negative
duration error is justified. I think it should be replaced by the invalid
duration error but decided not to do that in order to limit the scope of
this change.
Fix two issues found by `staticcheck -tests=false ./...`:
pkg/eval/go_fn.go:155:5: var errNoOptions is unused (U1000)
pkg/persistent/hashmap/hashmap.go:321:2: only the first constant in this group has an explicit type (SA9004)
I was looking at "TODO" comments that could be eliminated and noticed the
one preceding the sole use of `isDrive()`. Which caused me to notice its
implementation is broken. The `s[1] < 'z'` test should be `s[0] < 'z'`
I noticed that testutil.MustPipe was not covered by any unit tests. This
converts the handful of places that should use it to do so. This changes
the coverage of pkg/testutil/must.go from 61.5% to 73.1%. There isn't
any way to increase that further without explicitly testing the panic
paths.
This is useful when piping the output into a program like `fzf` and more
efficient than dealing with the map. This takes 180.32 ms on my system
(best of five runs):
```
time { edit:command-history &dedup &newest-first | each [hist-entry]{ print $hist-entry[cmd]"\000" } >/dev/null }
```
This option reduces the time to 156.12 ms:
```
time { edit:command-history &dedup &newest-first &cmd-only | each [cmd]{ print $cmd"\000" } >/dev/null }
```
It's not a huge difference but is 13% faster, and should be considerably
faster when combined with a hypothetical `to-lines &null` option I intend
to implement.
Related #1053
This implements `&dedup` and `&newest-first` options for
`edit:command-history`. This makes it noticably cheaper to feed unique
command history into external commands like `fzf`.
Related #1053Fixes#568
I was trying to add a `fn` created function to a list but was unable to
get it working. I suspected using just `name` wasn't correct and tried
`$name` and other attempts but was not successful. Finally was pointed to
`$name~` by @krader1961. I was able to find where this was documented in the
spec, but I missed it since it was just one line at the bottom of the section.
I think an example would have called out the special variable name better and
is just good to have anyway.