Closed soraxas closed 3 years ago
Thank you for creating a new POC, but I just closed #635 stating that I will not be adding comment support for now.
BTW, I think you forgot to string escape
in your implementation to encode plugin names.
@soraxas Renabling support for top-level .fish
files in this PR was uncalled for. Please take a break.
This PR aims to implement a simple comment system to address #635.
Commit 11eb085 had linked #524 of deprecating
fishfile
forfish_plugins
, which is nice but comments supports are dropped, perheps due to the previousfilefile
's complexity.This PR aims to introduce a simple and easy to maintain comment system back to
fish_plugins
(partly based on ae770fc). Currently, this commit works on both full line comments and inline comments (where there should be at least one whitespace before the first # character), using only built-in fish-shell string regex.Explaination:
The following
can essentially strip away any full or inline comments as it captures from the beginning of the line to the first non-whitespace non-# character.
Then, in the logic of writing back to
$fish_plugins
, we first useto construct a regex with the installed active plugins to filter out the content of
$fish_plugins
. The regex only match fullline comments ('^\s*#.*$
), active plugins, and an optional inline-comment capture group ((?:\s+#.*)?
) after the active plugins. Note that we had checked$_fisher_plugins[1]
to be defined so the string join should always has at least one item.Finally,
first strips away any full/inline comments from
$new_content
, then performs an exact inverse match so that any newly installed plugins in$_fisher_plugins
that are currently not present in$fish_plugins
would be added to$new_content
. As an added bonus, the contents and comments in$fish_plugins
will be order-preserved with this approach, and newly installed plugins are appended at the end of the file.