lord63 / tldr.py

A python client for tldr: simplified and community-driven man pages.
MIT License
186 stars 18 forks source link

Custom commands pages #5

Closed tjoskar closed 8 years ago

tjoskar commented 8 years ago

Hi,

I have a few custom commands. Is it possible to have custom pages for these?

One could add a line in the config file:

custom_pages_directory: /home/lord63/code/custom_pages

And in cli.py we can just check if it exist a custom page for the current command:

(something like this:)

def find_page(command):
  ...
  custom_pages_directory = get_config()['custom_pages_directory']
  repo_directory = get_config()['repo_directory']
  default_platform = get_config()['platform']

  page_path = find_custom_page(custom_pages_directory, command)

  if not page_path:
    with io.open(path.join(repo_directory, 'pages/index.json'), encoding='utf-8') as f:
      index = json.load(f)
    ...

Or maybe better:

def render_page(command):
  page_path = find_page(command)
  output_lines = parse_page(page_path)
  click.echo(''.join(output_lines))

def find_page(command):
  custom_page = find_custom_page(command)
  return custom_page if custom_page else find_remote_page(command)

I can send you a pull request if you want.

lord63 commented 8 years ago

Do you mean that you want to add a custom page? You can just add it to the folder and rebuild the index.

For example, you want to add the command proxychains, add it to ~/your/tldrrepo/pages/linux/proxychains.md(for example), then rebuild the index, you can use it now.

I think there is no need to add another location, since tldr.py find the command via the /your/tldrrepo/pages/index.json.

tjoskar commented 8 years ago

Sure, but it becomes inconvenient if I want to push my custom pages to github or share them in some other way between my laptops.

I can of course add a new git-remote to the tldrrepo or add it in dropbox or something similar. – I will try that.

Great work with tldr.py by the way.

lord63 commented 8 years ago

No need for another repo, you can fork the official tldr repo and clone it to your laptop, then add the new pages, push them to your own github. On another laptop, you can clone your own repo instead of the official. Then you can share your custom page between your laptops. Right?

tjoskar commented 8 years ago

Yeah, exactly. That's what I meant. (origin can still point to the official tldr repo and then I can add a new remote and point to my fork on github). That is probably a better solution than adding a custom directory as I was aiming at before.

– Thanks.