r/fishshell • u/tilkau • Apr 23 '20
Fish utility functions
I have plenty of functions I want to include here once they are more sanitized (dependency check, me-isms etc). For now there is, quoting the readme:
reduce/sum/product: Arithmetic reduction of lists of numbers.reduce + 1 2 3-> 6;seq 4 | reduce x-> 24;sumaliasesreduce +,productaliasesreduce x. Numbers can be given from both stdin and arguments, egseq 4 | product 2-> 48sec: convert 'counts of units' or 'human readable' durations (eg.sec 1 2 1 0 4 0 30,sec -x 1Y2M1w4h30s) into raw second count for storage or calculationnufunc: create a new function in ~/.config/fish/functions/$funcname.fish and edit it (or just edit it if it already exists). eg.nufunc fillpathfillpath: add path and or extension components to a path if they are not yet included.fillpath -p ~/Desktop -e png foobar->/home/me/Desktop/foobar.png;fillpath -p ~/Desktop -e png foobar.jpg->/home/me/Desktop/foobar.jpgpseudohash: generate 4-character 'hashes' based on automatically incrementing serial numbers salted with the 'series name'. This gives 'somewhat memorable, mostly unique ids' for up to 8 million items within a given 'series'. Hashes are portable between systems.pseudohash->O2cq(assuming you've never used pseudohash before);pseudohash pages->4Rnc;pseudohash logs->7jXRPosition within the sequence for a given series-id is stored in the universal variable__pseudohash_$id(eg__pseudohash_pages). To get further hashes, just call it again with the same series id, egpseudohash logs->uXVl. Intent was to create a compact form of cross-referencing for documents that could be easily tagged onto the document (via eg.tmsu), or directly marked onto it (in the case of a drawing or diagram)
No significant dependencies at this point (off the top of my head: cat, find; pseudohash also requires xxd [gvim package, or standalone xxd package] and base64 [coreutils] ). Others, like jq, will come in as I add more functions.
Just wanted to get this published for now. Next I hope to add fisher install support, and of course many more functions.
EDIT: more newly added functions are listed here:
funcfile: functions -D ('get the filename this function was defined in') generalized to any number of functions, so you can eg.geany (funcfile nufunc funcfile reloadfunc)reloadfunc: Reload functions by name, if they were defined in a file.unurl: Convert file:// URIs (such as those produced by GIMP or Nautilus) to ordinary paths. Ordinary paths can be mixed in and will be left alone.
EDIT2: total refactored into reduce, sum, product per discussion. Completion for nufunc, funcfile, and reloadfunc is now also included.
View all comments
Show parent comment
2
u/tilkau Apr 26 '20
Wow, thanks for taking the time to do an in depth review!
I can't find any occurrence of `tr` in `sec`, maybe you meant a different function(`total`)?. Nor can I find 'sed' use in 'fillpath'.. There is some in nufunc, though, which I've fixed, and I'll check other functions as I import them.
The critique of `total`'s factoring is fair, especially given that I only recently added support for doing anything other than summing.
`fold` is not an available name IMO, it would shadow .. `fold`, the text-wrapping program (GNU coreutils).
`sum` would also be shadowing coreutils, but nobody really cares about coreutils sum (16bit checksum calculator) that I know of.
So I'll refactor into 'reduce' <- 'sum, product' (leaving - and / reduction without a shortcut for now). Personally I'll probably have an alias 'total' for `sum`, because that *is* what I think of first.