-
Notifications
You must be signed in to change notification settings - Fork 128
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
Support custom pages and patches #142
Conversation
1910018
to
fc81872
Compare
208d659
to
99277ff
Compare
tldr-master/pages.custom
c170d88
to
c7233c7
Compare
if the .md file is the same as one that already exists then the custom one gets appended to the original one Added TEALDEER_CUSTOM_PAGES_DIR env variable If set then tealdeer will search that directory for custom pages otherwise it will search "pages.custom"
c7233c7
to
e135101
Compare
2ade1d1
to
4c0ac7d
Compare
4c0ac7d
to
b5ab5cb
Compare
Hey, This looks very promising, is there any plan to merge anytime soon? 😇 Keep up the great work! 💯 |
Great to hear back from you @dvergeylen! 😊 I was just waiting on a code review, since I'm fairly new to Rust. I'm happy to make changes But if you don't have any suggestions then it should be good to merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dmaahs2017, sorry for the long delay, especially since this is your first open source contribution. I'm currently quite busy at work and with other projects, so that leaves less time for maintaining tealdeer 🙂
I left two comments!
.page files overwrite any and all other files. .patch files append to prexisting pages.
default is ~/.local/share/tealdeer_custom_pages, if HOME env var is not set, then it defaults to "".
1fa9bc6
to
2261105
Compare
next fallbacks are on ~/.local/share/custom_tldr_pages/ then /.local/share/custom_tldr_pages/ if no $HOME variable exists
`tldr --patch` to create/edit a new patch file. `tldr --overwrite` to create/edit a new page file. The logic of this is simply: use the $EDITOR variable to initiate an editor on CUSTOM_PAGES_DIR/page.{patch,page}, exentension is determined by which flag you pass. It also checks that CUSTOM_PAGES_DIR exists and creates it if it does not.
…dr_pages # Conflicts: # src/main.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, thank you! I have some suggestions that mostly involve moving code around and renaming things to better fit (my perception of) what is actually happening. I also suggested something about your last comment, but I am not sure it's the best thing to do and I would want to hear what @dbrgn thinks
Oh, and I think that if a patch and a custom page exist, both should be output, forgot to mention that. I don't think that it would be a great pain, because I would suggest looking for patches once in |
Hm, I'm not sure if I agree. I can't really think of a use case where a user would add both a custom page file and a patch file. I think I'd stick to rendering just the page, unless there's a compelling reason to apply the patch as well. As @dmaahs2017 wrote, the implementation with an early return for custom pages is more efficient, so I'd prefer that.
(Edit: Ah, @niklasmohrin already commented on that above 😄) |
@niklasmohrin and @dbrgn love the feedback. I'm learning a ton working on this 😊. Expect me to address the new reviews by Friday evening |
* Changed config for custom_dir to be an Option * Some refactoring and renaming * Moved the looping logic over PageLookupResult to be in the print_page function * Moved finding custom patch call into the find_page function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, you were a lot quicker than us 😅 I have added some small comments that should give this the final touch. Please also make sure to check CI (red cross next to your commit hash) when you push, clippy usually has some pretty nice suggestions too (it's insane what kind of stuff clippy can detect).
Other than that, great stuff! Keep it up 🚀
Note: I just bumped Rust and Clippy to 1.41 on master, so to successfully pass the CI you'll need to rebase your branch (or merge master into it). You can also run clippy locally: |
* Revert find_page_for_platform back to return PathBuf * find_page no longer takes the entire config as an argument * various other refactoring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet!
Yeah, I totally love these shorthand methods on Option
and Result
too, I think it absolutely worth it to scroll through the officials docs to see every one of them. I also saw this reddit post a while back.
Finally, the +1.41
syntax for cargo
means that the 1.41
toolchain from rustup
should be used instead of the default (probably stable
). For that to work, you have to have the 1.41
toolchain installed though (rustup toolchain install 1.41
). This only works if you have installed cargo
through rustup
(on Arch, you could install rustc
and cargo
alone; then this would not work). As you said, CI passes so that is a fine for this PR :)
(note to self and @dbrgn: don't forget to squash these 16 commits) |
Hey @dmaahs2017, casual reminder that we have not forgotten your PR 👍 @dbrgn Any chance we can merge this some time soon? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for your patience, @dmaahs2017 (and thanks @niklasmohrin for the reviews) 🙂 I really like how this PR turned out, especially the PageLookupResult
!
There are only three minor nitpicks left, and I'll merge it as soon as those are fixed!
We should also include the custom pages directory in the new --show-paths
option output, but that's probably best done in a separate PR, in order not to hold up this one.
Another issue for a new PR: Right now the patches need to be formatted like a full page, including a heading. Otherwise, the first line is interpreted as the heading, and skipped when printing (because the page and the patch are passed to separate tokenizer instances). However, I think that too can be fixed in a separate PR, I don't want to hold up this PR too long.
445c5dd
to
2827fb5
Compare
- Removed dev comment - rename maybe_config_dir -> custom_pages_dir
2827fb5
to
704234e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still great! I only now noticed that there are no tests for the new behavior, but I would honestly rather have this PR merged and have the tests in another PR
Oh yeah! I'll create myself an issue for that :) |
Feature implementation for issue #98
This is a feature that lets you create custom tldr pages locally.
You can set a directory where tealdeer will search for these local pages with the env variable
TEALDEER_CUSTOM_PAGES_DIR
. If this is not set then it will use thetldr-master/pages.custom
If you give a custom tldr page the same name as an existing one, then your custom one will be appended to it.
Example with existing tldr page:
Example with no existing tldr page:
I find the value added here is that overtime a person can build their own collection of common use-cases to a particular command that they use semi-frequently. I created this because I would create my own repository of command specific use-cases, and to document personalized scripts for myself.
Side note: This is my first real open-source contribution, and I'm not super familiar w/ the ins and outs of rust. Please leave suggestions for improvements 😄 .
Update, Dec 18. Implemented suggested changes from @dbrgn
CONFIGDIR/pages
Also added 2 flags,--patch
and--overwrite
. These commands create and or open the .page or .patch files in your$EDITOR
. I added this because I found it was annoying to constantly switch the the custom page directory. Also this enables people to very quickly make changes to their custom patches/pagesExample of a .patch file in work
Example of a new tldr page with a .page file
Example of overwriting an existing tldr page using a .page file
How the config looks now