Skip to content
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

F1 shows man page for current query #1456

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

serpent7776
Copy link

Description

Make F1 key launch man page for current query. E.g. I have CREATE TABLE foo as my query and I press F1. The man page CREATE_TABLE is launched. This requires man pages to be installed locally, I'm not sure they're always installed. I have it on my manjaro, but I don't see man pages on ubuntu, only the html docs.

This is currently just a scratch implementation, let me know if you're interested in having such functionality.

Also, I'm not a python dev, any suggestions welcomed.

Checklist

  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install), and ran black on my code.
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

@j-bennet
Copy link
Contributor

Nice. :) If this is useful to you, it's useful to other people.

@serpent7776
Copy link
Author

I implemented a simple heuristic that should work for most cases.

Two cases that are not supported are:

  • CREATE TABLE AS
  • SELECT INTO

These cases are too complex to come up with a heuristic. An actual SQL parser would need to be used to support these.

Now I have an issue with showing SQL query after man page quits. The user entered query should be re-desplayed, but I don't know how to do that. I tried click.clear(), event.app.invalidate() and get_app().current_buffer.reset(), but none of them work.
Maybe man page should be displayed in separate window? I don't know how to do that though.

@j-bennet
Copy link
Contributor

j-bennet commented May 3, 2024

@jonathanslenders can you advise?

def try_man(page):
try:
subprocess.run(
f"man -I 7 {page}", shell=True, check=True, universal_newlines=True

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input Medium

This f-string which depends on
library input
is later used in a
shell command
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants