srsudar / eg

Useful examples at the command line.
MIT License
1.8k stars 98 forks source link

Recursive custom-dir #71

Closed clrh closed 6 years ago

clrh commented 6 years ago

Hi,

I would like to classify my md files in directories like:

~/eg
~/eg/glossary
~/eg/tech

and in my config file, just having something like:

custom-dir=~/eg

Actually, when a md file is in a subdirectory, it is not found. Is there a way to change that ?

Thanks.

srsudar commented 6 years ago

Hmm that is a good idea. I don't think there's any way to do that currently... I need to revisit how we resolve paths.

If there isn't a config file fix I will add it.

Your preferred way for it to work would be to just detect .md files anywhere in the directory tree?

A few complicating cases occur to me that I'll need to think through. Currently if you have ~/eg/find.md, running eg find will show the contents of your custom file before the contents of the find file that ships with eg. If multiple files with the same name are defined in your custom directory, eg something like:

~/eg/personal-machine/ssh.md
~/eg/work-machine/ssh.md

what behavior would you expect? Showing contents of both files and then the default ssh examples?

clrh commented 6 years ago

Thanks for the quick answer !

Yes, the preferred way would be to detect md file anywhere in the directory base path.

The simplest behaviour for me would be to have an alert at the begin of the output, something like "Warning: the command.md file occurs x times" and display after the x md files. Like that, the end user is able to clean (or not) his repository and wouldn't be prisoner of his data (nothing is blocked if there are duplicates).

As a user, I just explain the case: I use eg for plural use cases like commands examples (ok), glossary and definitions terms and quick memo files. Today, I try to categorize them with the file naming but it is really not comfortable. Tomorrow, I would be able to clone or have more directories and eg would detect what it find inside.

Regards and thanks for the tool ;)

srsudar commented 6 years ago

Can you clone the nested-dirs branch and see if it meets your needs? Run ./eg_exec.py find, for example, to use the repo's version of eg rather than the globally installed version.

It works like I imagine it, but I'd like your take.

clrh commented 6 years ago

It works like I imagine too, great \o/

So I kept my .egrc file like before, move a .md file in a subdirectory and found it : )

srsudar commented 6 years ago

Great. I have at least one more edge case to fix, at which point I will create a PR, merge, and close. I try to do releases on the 5th of each month, so I'll ship a new version around April 5th.

This was a great idea, thanks for the suggestion. Some tools and combinations of flags I want to use only at work, and I hadn't found a good way to put them in eg without running the risk of leaking them in my dotfiles repo. Nested directories is a great workaround.

For this reason I decided to show all files if you have more than one. So if you have:

~/eg/personal-machine/find.md
~/eg/work-machine/find.md

eg find will concatenate all three together, showing first the one in personal-machine/, then the one in work-machine/, and then the default examples that ship with eg.