Ultra Portable Scripts for fish
I really like this part of pkgx: https://docs.pkgx.sh/pkgx/scripting#ultra-portable-scripts
And while I do prefer writing bash for scripts, I use fish as my terminal shell.
So I'd like to be able to do the following when implementing my fish aliases/functions:
function xc
eval "$(pkgx +aria2c@latest +xcodes@latest)" # whatever the equivalent of this is in fish
if test (count $argv) -ge 2; and test $argv[1] = runtimes; and test $argv[2] = install
sudo xcodes $argv
else
xcodes $argv
end
end
Effectively, I want to be able to declare all my local function dependencies at the very top and not have to worry about how to invoke them throughout my implemention.
Is this feasable?
It seems feasible. If you look at the output of that pkgx command, it's just spitting out a bunch of variable exports. Making into a bunch of set commands for fish isn't the hard part. I can see three levels of possible solution:
- make pkgx detect fish shell and change it's output.
- add a --fish flag to do the same.
- write a mash wrapper (
pkgx_fish?) that is a literal passthrough but runssedon the output.
The third one should be trivial. The first one is the "hardest", though it might not be hard at all. The second clutters the command, and is probably disfavored.
A fully personal workaround involves a fish function called export: https://stackoverflow.com/posts/29387647/revisions
I'm not sure that is handling lists properly, but it shouldn't be hard to extend, and is basically the mash script in fish.
First option would be ideal. I've tried doing the export trick but the problem is some PATH components use ${} syntax incompatible with fish, e.g:
$ pkgx +git
LD_LIBRARY_PATH="/Users/davdroman/.pkgx/curl.se/v8.15.0/lib:/Users/davdroman/.pkgx/zlib.net/v1.3.1/lib:/Users/davdroman/.pkgx/perl.org/v5.42.0/lib:/Users/davdroman/.pkgx/tukaani.org/xz/v5.8.1/lib:/Users/davdroman/.pkgx/libexpat.github.io/v2.7.1/lib:/Users/davdroman/.pkgx/gnu.org/gettext/v0.21.1/lib:/Users/davdroman/.pkgx/openssl.org/v1.1.1w/lib:/Users/davdroman/.pkgx/gnome.org/libxml2/v2.13.8/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
So I'm thinking it needs to be a tad more sophisticated than simply parsing the output. Ideally pkgx would produce the correct syntax based on $SHELL.
A PR to output in fish syntax if we detect fish would be nice.