Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Features
* Rewrite bottom toolbar, showing more statuses, but staying compact.
* Let `help <keyword>` list similar keywords when not found.
* Optionally highlight fuzzy search previews.
* Make `\edit` synonymous with the `\e` command.


Bug Fixes
Expand Down
4 changes: 3 additions & 1 deletion mycli/TIPS
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ copy a query to the clipboard using \clip at the end of the query!

\dt lists tables; \dt <table> describes <table>!

edit a query in an external editor using \e!
edit a query in an external editor using <query>\edit!

edit a query in an external editor using \edit <filename>!

\f lists favorite queries; \f <name> executes a favorite!

Expand Down
1 change: 1 addition & 0 deletions mycli/clibuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def _multiline_exception(text: str) -> bool:
"\\g",
"\\G",
r"\e",
r"\edit",
r"\clip",
))
or
Expand Down
11 changes: 8 additions & 3 deletions mycli/packages/special/iocommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,16 @@ def editor_command(command: str) -> bool:
"""
# It is possible to have `\e filename` or `SELECT * FROM \e`. So we check
# for both conditions.
return command.strip().endswith("\\e") or command.strip().startswith("\\e")
return (
command.strip().endswith("\\e")
or command.strip().startswith("\\e ")
or command.strip().endswith("\\edit")
or command.strip().startswith("\\edit ")
)


def get_filename(sql: str) -> str | None:
if sql.strip().startswith("\\e"):
if sql.strip().startswith("\\e ") or sql.strip().startswith("\\edit "):
command, _, filename = sql.partition(" ")
return filename.strip() or None
else:
Expand All @@ -169,7 +174,7 @@ def get_editor_query(sql: str) -> str:
# The reason we can't simply do .strip('\e') is that it strips characters,
# not a substring. So it'll strip "e" in the end of the sql also!
# Ex: "select * from style\e" -> "select * from styl".
pattern = re.compile(r"(^\\e|\\e$)")
pattern = re.compile(r"(\\e$|\\edit$)")
while pattern.search(sql):
sql = pattern.sub("", sql)

Expand Down
7 changes: 6 additions & 1 deletion mycli/packages/special/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ def quit_(*_args):


@special_command(
"\\e", "<query>\\e | \\e <filename>", "Edit query with editor (uses $EDITOR).", arg_type=ArgType.NO_QUERY, case_sensitive=True
"\\edit",
"<query>\\edit | \\edit <filename>",
"Edit query with editor (uses $EDITOR).",
arg_type=ArgType.NO_QUERY,
case_sensitive=True,
aliases=['\\e'],
)
@special_command("\\clip", "<query>\\clip", "Copy query to the system clipboard.", arg_type=ArgType.NO_QUERY, case_sensitive=True)
@special_command("\\G", "<query>\\G", "Display query results vertically.", arg_type=ArgType.NO_QUERY, case_sensitive=True)
Expand Down
74 changes: 37 additions & 37 deletions test/features/fixture_data/help_commands.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
+----------------+----------+------------------------------+-------------------------------------------------------------+
| Command | Shortcut | Usage | Description |
+----------------+----------+------------------------------+-------------------------------------------------------------+
| \G | <nope> | <query>\G | Display query results vertically. |
| \bug | <nope> | \bug | File a bug on GitHub. |
| \clip | <nope> | <query>\clip | Copy query to the system clipboard. |
| \dt | <nope> | \dt[+] [table] | List or describe tables. |
| \e | <nope> | <query>\e | \e <filename> | Edit query with editor (uses $EDITOR). |
| \f | <nope> | \f [name [args..]] | List or execute favorite queries. |
| \fd | <nope> | \fd <name> | Delete a favorite query. |
| \fs | <nope> | \fs <name> <query> | Save a favorite query. |
| \l | <nope> | \l | List databases. |
| \llm | \ai | \llm [arguments] | Interrogate an LLM. |
| \once | \o | \once [-o] <filename> | Append next result to an output file (overwrite using -o). |
| \pipe_once | \| | \pipe_once <command> | Send next result to a subprocess. |
| \timing | \t | \timing | Toggle timing of commands. |
| connect | \r | connect [database] | Reconnect to the server, optionally switching databases. |
| delimiter | <nope> | delimiter <string> | Change end-of-statement delimiter. |
| exit | \q | exit | Exit. |
| help | \? | help [term] | Show this help, or search for a term on the server. |
| nopager | \n | nopager | Disable pager, print to stdout. |
| notee | <nope> | notee | Stop writing results to an output file. |
| nowarnings | \w | nowarnings | Disable automatic warnings display. |
| pager | \P | pager [command] | Set pager to [command]. Print query results via pager. |
| prompt | \R | prompt <string> | Change prompt format. |
| quit | \q | quit | Quit. |
| redirectformat | \Tr | redirectformat <format> | Change the table format used to output redirected results. |
| rehash | \# | rehash | Refresh auto-completions. |
| source | \. | source <filename> | Execute commands from file. |
| status | \s | status | Get status information from the server. |
| system | <nope> | system <command> | Execute a system shell commmand. |
| tableformat | \T | tableformat <format> | Change the table format used to output interactive results. |
| tee | <nope> | tee [-o] <filename> | Append all results to an output file (overwrite using -o). |
| use | \u | use <database> | Change to a new database. |
| warnings | \W | warnings | Enable automatic warnings display. |
| watch | <nope> | watch [seconds] [-c] <query> | Executes the query every [seconds] seconds (by default 5). |
+----------------+----------+------------------------------+-------------------------------------------------------------+
+----------------+----------+---------------------------------+-------------------------------------------------------------+
| Command | Shortcut | Usage | Description |
+----------------+----------+---------------------------------+-------------------------------------------------------------+
| \G | <nope> | <query>\G | Display query results vertically. |
| \bug | <nope> | \bug | File a bug on GitHub. |
| \clip | <nope> | <query>\clip | Copy query to the system clipboard. |
| \dt | <nope> | \dt[+] [table] | List or describe tables. |
| \edit | \e | <query>\edit | \edit <filename> | Edit query with editor (uses $EDITOR). |
| \f | <nope> | \f [name [args..]] | List or execute favorite queries. |
| \fd | <nope> | \fd <name> | Delete a favorite query. |
| \fs | <nope> | \fs <name> <query> | Save a favorite query. |
| \l | <nope> | \l | List databases. |
| \llm | \ai | \llm [arguments] | Interrogate an LLM. |
| \once | \o | \once [-o] <filename> | Append next result to an output file (overwrite using -o). |
| \pipe_once | \| | \pipe_once <command> | Send next result to a subprocess. |
| \timing | \t | \timing | Toggle timing of commands. |
| connect | \r | connect [database] | Reconnect to the server, optionally switching databases. |
| delimiter | <nope> | delimiter <string> | Change end-of-statement delimiter. |
| exit | \q | exit | Exit. |
| help | \? | help [term] | Show this help, or search for a term on the server. |
| nopager | \n | nopager | Disable pager, print to stdout. |
| notee | <nope> | notee | Stop writing results to an output file. |
| nowarnings | \w | nowarnings | Disable automatic warnings display. |
| pager | \P | pager [command] | Set pager to [command]. Print query results via pager. |
| prompt | \R | prompt <string> | Change prompt format. |
| quit | \q | quit | Quit. |
| redirectformat | \Tr | redirectformat <format> | Change the table format used to output redirected results. |
| rehash | \# | rehash | Refresh auto-completions. |
| source | \. | source <filename> | Execute commands from file. |
| status | \s | status | Get status information from the server. |
| system | <nope> | system <command> | Execute a system shell commmand. |
| tableformat | \T | tableformat <format> | Change the table format used to output interactive results. |
| tee | <nope> | tee [-o] <filename> | Append all results to an output file (overwrite using -o). |
| use | \u | use <database> | Change to a new database. |
| warnings | \W | warnings | Enable automatic warnings display. |
| watch | <nope> | watch [seconds] [-c] <query> | Executes the query every [seconds] seconds (by default 5). |
+----------------+----------+---------------------------------+-------------------------------------------------------------+
7 changes: 6 additions & 1 deletion test/test_special_iocommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ def test_set_get_expanded_output():

def test_editor_command():
assert mycli.packages.special.editor_command(r"hello\e")
assert mycli.packages.special.editor_command(r"\ehello")
assert mycli.packages.special.editor_command(r"hello\edit")
assert mycli.packages.special.editor_command(r"\e hello")
assert mycli.packages.special.editor_command(r"\edit hello")

assert not mycli.packages.special.editor_command(r"hello")
assert not mycli.packages.special.editor_command(r"\ehello")
assert not mycli.packages.special.editor_command(r"\edithello")

assert mycli.packages.special.get_filename(r"\e filename") == "filename"

Expand Down