diff --git a/changelog.md b/changelog.md index 5b5e68a5..9ced9f21 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ TBD Features -------- * Options to limit size of LLM prompts; cache LLM prompt data. +* Add startup usage tips. Bug Fixes diff --git a/mycli/TIPS b/mycli/TIPS new file mode 100644 index 00000000..144af9e9 --- /dev/null +++ b/mycli/TIPS @@ -0,0 +1,103 @@ +set "less_chatty = True" in ~/.myclirc to turn off these tips! + +set a fancy table format like "table_format = psql_unicode" in ~/.myclirc! + +change the string for NULLs with "null_string = " in ~/.myclirc! + +interact with an LLM using the \llm command! + +display query result vertically using \G at the end of a query! + +copy a query to the clipboard using \clip at the end of the query! + +\dt lists tables; \dt describes
! + +edit a query in an external editor using \e! + +edit a query in an external editor using keystrokes control-x + control-e! + +toggle smart completion using keystroke F2! + +toggle multi-line mode using keystroke F3! + +toggle vi mode using keystroke F4! + +complete at cursor using the tab key! + +prettify a query using keystrokes control-x + p! + +un-prettify a query using keystrokes control-x + u! + +insert the current date using keystrokes control-o + d! + +insert the quoted current date using keystrokes control-o + control-d! + +insert the current datetime using keystrokes control-o + t! + +insert the quoted current date using keystrokes control-o + control-t! + +search query history using keystroke control-r! + +\f lists favorite queries; \f executes a favorite! + +\fs saves a favorite query! + +\fd deletes a saved favorite query! + +\l lists databases! + +\once appends the next result to ! + +\| sends the next result to a subprocess! + +\t toggles timing of commands! + +\r or "connect" reconnects to the server! + +\delimiter changes the SQL delimiter! + +\q, "quit", or "exit" exits from the prompt! + +\? or "help" for help! + +\n or "nopager" to disable the pager! + +use "tee"/"notee" to write/stop-writing results to a output file! + +\W or "warnings" enables automatic warnings display! + +\w or "nowarnings" disables automatic warnings display! + +\P or "pager" sets the pager. Try "pager less"! + +\R or "prompt" changes the prompt format! + +\Tr or "redirectformat" changes the table format for redirects! + +\# or "rehash" refreshes autocompletions! + +\. or "source" executes queries from a file! + +\s or "status" requests status information from the server! + +use "system " to execute a shell command! + +\T or "tableformat" changes the interactive table format! + +\u or "use" changes to a new database! + +the "watch" command executes a query every N seconds! + +redirect query output to a shell command with "$| "! + +redirect query output to a file with "$> "! + +append query output to a file with "$>> "! + +choose a color theme with "syntax_style" in ~/.myclirc! + +design a prompt with the "prompt" option in ~/.myclirc! + +save passwords in the system keyring with "use_keyring" in ~/.myclirc! + +check your ~/.myclirc settings using the --checkup flag! diff --git a/mycli/main.py b/mycli/main.py index d5a3db81..5c1ce7cf 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -5,6 +5,7 @@ from io import TextIOWrapper import logging import os +import random import re import shutil import sys @@ -821,7 +822,10 @@ def run_cli(self) -> None: print(sqlexecute.server_info) print("mycli", __version__) print(SUPPORT_INFO) - print("Thanks to the contributor -", thanks_picker()) + if random.random() <= 0.5: + print("Thanks to the contributor —", thanks_picker()) + else: + print("Tip —", tips_picker()) def get_message() -> ANSI: prompt = self.get_prompt(self.prompt_format) @@ -2206,11 +2210,17 @@ def thanks_picker() -> str: import mycli lines: str = "" - with resources.files(mycli).joinpath("AUTHORS").open('r') as f: - lines += f.read() + try: + with resources.files(mycli).joinpath("AUTHORS").open('r') as f: + lines += f.read() + except FileNotFoundError: + pass - with resources.files(mycli).joinpath("SPONSORS").open('r') as f: - lines += f.read() + try: + with resources.files(mycli).joinpath("SPONSORS").open('r') as f: + lines += f.read() + except FileNotFoundError: + pass contents = [] for line in lines.split("\n"): @@ -2219,6 +2229,22 @@ def thanks_picker() -> str: return choice(contents) if contents else 'our sponsors' +def tips_picker() -> str: + import mycli + + tips = [] + + try: + with resources.files(mycli).joinpath('TIPS').open('r') as f: + for line in f: + if tip := line.strip(): + tips.append(tip) + except FileNotFoundError: + pass + + return choice(tips) if tips else r'\? or "help" for help!' + + @prompt_register("edit-and-execute-command") def edit_and_execute(event: KeyPressEvent) -> None: """Different from the prompt-toolkit default, we want to have a choice not diff --git a/pyproject.toml b/pyproject.toml index fca04495..f9238209 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,7 +67,7 @@ dev = [ mycli = "mycli.main:cli" [tool.setuptools.package-data] -mycli = ["myclirc", "AUTHORS", "SPONSORS"] +mycli = ["myclirc", "AUTHORS", "SPONSORS", "TIPS"] [tool.setuptools.packages.find] include = ["mycli*"]