-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement: Write fish_plugins in alphabetical order #689
Comments
I'm not sure that's something easy to implement in just Fish, but maybe you've thought of something? It would be nice to be able to keep Fisher 100% pure Fish. |
Fish shows usage of I do see you use e.g. |
Let's collect more feedback here before introducing this change. 🙏 |
I experienced the same issue, which led me to this issue. I think it's safe to assume nearly every machine has |
I agree, sort seems fine to me as well. Plus, as @evanrelf said you can just skip it if sort isn’t on the host for some reason. |
Does anyone how to reproduce this? Can't seem to get them jumbled up no matter how many times I run |
For me just running a regular update did it. But it doesn't happen every time. Not sure yet what's responsible for the entries getting reordered. edit: it seems like this is where the changes to the plugins are being persisted to the plugin file right: https://github.com/jorgebucaran/fisher/blob/main/functions/fisher.fish#L187? I've not gone through it in depth, but I can imagine that this would cause plugins to be reordered. It doesn't seem like there's any logic there to prevent the existing order from being changed. Or am I reading it wrong? |
One thing you could do if you want to avoid
That way, it resolves the original issue: i.e., not messing up the order for an update. And then if the user wants to sort the plugins they are free to do so themselves and fisher will leave it intact. Basically, fisher shouldn't touch the plugins file for an update. Would that work? |
@jorgebucaran Having said that, in skimming through the code it seems like the logic for installation is somewhat mixed with that for updating. I can imagine that the simplest solution would be to just check if sort is available here: https://github.com/jorgebucaran/fisher/blob/main/functions/fisher.fish#L187, and use that if it exists. That way it will degrade gracefully if sort can't be found. And if it can be found, the plugins will be sorted for both installations and updates, which seems nice. That seems like a practical way forward. |
Without a native native sort solution in Fish, I see this feature unlikely to land here anytime soon, but I'm still open to ideas. |
@jorgebucaran let's see what they say: fish-shell/fish-shell#9013 What is the reluctance to check if |
@jorgebucaran apparently it already exists soonish, but it'd require users to have a specific version of fish. See fish-shell/fish-shell#8958 You can use Seems to land in fish 3.5 which seems very close to being finalized: https://github.com/fish-shell/fish-shell/milestone/32 |
My take on pure™️ fish function naive_sort
test (count $argv) != 0 || return
set -l dir (mktemp -d)
mkdir -p $dir/$argv
set -l glob (string replace -a $dir/ "" $dir/**)
set -l sorted
for i in $argv
test -n "$i" && set sorted[(contains -i $i $glob)] $i
end
string match -v "" $sorted
rm -r $dir
end
function naive_sort_slashed
set -l slashed (string replace -rf "^/(.)" '$1' $argv)
test (count $slashed) != 0 && printf /%s\n (dump_sort $slashed)
dump_sort (string match -v "/*" $argv)
end
$ naive_sort_slashed jorgebucaran/fisher ilancosman/tide@v5 jorgebucaran/nvm.fish /home/jb/path/to/plugin
/home/jb/path/to/plugin
ilancosman/tide@v5
jorgebucaran/fisher
jorgebucaran/nvm.fish Alright, just joking. However this can be made shorter and has better compatibility with older fish than the upcoming Footnotes
|
I don't think that would work. If you add a new plugin (one currently not installed) to your |
I feel like the correct solution to the problem is not writing out plugins in alphabetical order, but preserving plugin order. |
Meanwhile, here's a (rather slow) quicksort in Fish—just for fun. function ord --description "Convert a string to decimal values"
printf %d\n '"'$argv
end
function fish_sort --argument-names head --description "Non-in-place, recursive pure Fish slow quicksort"
count $argv >/dev/null || return
set --local lesser
set --local greater
for elem in $argv[2..-1]
set --local elem_dec (ord (string split -- "" $elem))
set --local head_dec (ord (string split -- "" $head))
set --local len (math "min("(count $elem_dec)","(count $head_dec)")")
for j in (seq $len)
test $elem_dec[$j] -eq $head_dec[$j] &&
test $len -eq $j && set --append lesser $elem && continue
test $elem_dec[$j] -lt $head_dec[$j] &&
set --append lesser $elem || set --append greater $elem
break
end
end
printf "%s\n" (qsort $lesser) $head (qsort $greater)
end |
@jorgebucaran preserving order is what main problem has been (at least for me) all time along, and probably others reading this thread. So I think that is a good approach to take if you can fix that. Though in general I like sorting of strings as it makes it quick to find things in large lists, but that is not as important. |
I am afraid I still can't reproduce this. Any tips? What OS are you using? Are you sure the diff you saw was not a result of interactively removing and re-installing a plugin, therefore changing its position in |
> fisher update jethrokuan/fzf
> chezmoi diff
diff --git a/.config/fish/fish_plugins b/.config/fish/fish_plugins
index d0249f506bff85af351d66e91e14fc234f8f777b..3cab39bfee10f237cd2c536a92b571973a4a9b8e 100664
--- a/.config/fish/fish_plugins
+++ b/.config/fish/fish_plugins
@@ -1,4 +1,4 @@
+jethrokuan/fzf
jorgebucaran/fisher
thernstig/fish-ssh-agent
jorgebucaran/nvm.fish
-jethrokuan/fzf See how |
Nice @jorgebucaran :) |
It would be nice if fish_plugins could be written in alphabetical order.
It is a small thing and the reason is that anyone using dotfile managers to persist state (the config) for fish plugins, the fish_plugins shows as changed in diffs since it jumbles the file every time a
fisher update X
is run for a plugin. So it is a quality of life improvement for some of us.The text was updated successfully, but these errors were encountered: