diff --git a/changelog.md b/changelog.md index b395bd2e..b0db684c 100644 --- a/changelog.md +++ b/changelog.md @@ -9,6 +9,7 @@ Features * Rewrite bottom toolbar, showing more statuses, but staying compact. * Let `help ` list similar keywords when not found. * Optionally highlight fuzzy search previews. +* Make `\edit` synonymous with the `\e` command. Bug Fixes diff --git a/mycli/TIPS b/mycli/TIPS index d154432b..f6fe1ffc 100644 --- a/mycli/TIPS +++ b/mycli/TIPS @@ -50,7 +50,9 @@ 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 \edit! + +edit a query in an external editor using \edit ! \f lists favorite queries; \f executes a favorite! diff --git a/mycli/clibuffer.py b/mycli/clibuffer.py index c38aecad..70d7f17b 100644 --- a/mycli/clibuffer.py +++ b/mycli/clibuffer.py @@ -40,6 +40,7 @@ def _multiline_exception(text: str) -> bool: "\\g", "\\G", r"\e", + r"\edit", r"\clip", )) or diff --git a/mycli/packages/special/iocommands.py b/mycli/packages/special/iocommands.py index c92685a8..aebcccbd 100644 --- a/mycli/packages/special/iocommands.py +++ b/mycli/packages/special/iocommands.py @@ -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: @@ -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) diff --git a/mycli/packages/special/main.py b/mycli/packages/special/main.py index 3721564c..eba42b03 100644 --- a/mycli/packages/special/main.py +++ b/mycli/packages/special/main.py @@ -206,7 +206,12 @@ def quit_(*_args): @special_command( - "\\e", "\\e | \\e ", "Edit query with editor (uses $EDITOR).", arg_type=ArgType.NO_QUERY, case_sensitive=True + "\\edit", + "\\edit | \\edit ", + "Edit query with editor (uses $EDITOR).", + arg_type=ArgType.NO_QUERY, + case_sensitive=True, + aliases=['\\e'], ) @special_command("\\clip", "\\clip", "Copy query to the system clipboard.", arg_type=ArgType.NO_QUERY, case_sensitive=True) @special_command("\\G", "\\G", "Display query results vertically.", arg_type=ArgType.NO_QUERY, case_sensitive=True) diff --git a/test/features/fixture_data/help_commands.txt b/test/features/fixture_data/help_commands.txt index 816053ad..5a6a8c33 100644 --- a/test/features/fixture_data/help_commands.txt +++ b/test/features/fixture_data/help_commands.txt @@ -1,37 +1,37 @@ -+----------------+----------+------------------------------+-------------------------------------------------------------+ -| Command | Shortcut | Usage | Description | -+----------------+----------+------------------------------+-------------------------------------------------------------+ -| \G | | \G | Display query results vertically. | -| \bug | | \bug | File a bug on GitHub. | -| \clip | | \clip | Copy query to the system clipboard. | -| \dt | | \dt[+] [table] | List or describe tables. | -| \e | | \e | \e | Edit query with editor (uses $EDITOR). | -| \f | | \f [name [args..]] | List or execute favorite queries. | -| \fd | | \fd | Delete a favorite query. | -| \fs | | \fs | Save a favorite query. | -| \l | | \l | List databases. | -| \llm | \ai | \llm [arguments] | Interrogate an LLM. | -| \once | \o | \once [-o] | Append next result to an output file (overwrite using -o). | -| \pipe_once | \| | \pipe_once | 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 | | delimiter | 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 | | 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 | Change prompt format. | -| quit | \q | quit | Quit. | -| redirectformat | \Tr | redirectformat | Change the table format used to output redirected results. | -| rehash | \# | rehash | Refresh auto-completions. | -| source | \. | source | Execute commands from file. | -| status | \s | status | Get status information from the server. | -| system | | system | Execute a system shell commmand. | -| tableformat | \T | tableformat | Change the table format used to output interactive results. | -| tee | | tee [-o] | Append all results to an output file (overwrite using -o). | -| use | \u | use | Change to a new database. | -| warnings | \W | warnings | Enable automatic warnings display. | -| watch | | watch [seconds] [-c] | Executes the query every [seconds] seconds (by default 5). | -+----------------+----------+------------------------------+-------------------------------------------------------------+ ++----------------+----------+---------------------------------+-------------------------------------------------------------+ +| Command | Shortcut | Usage | Description | ++----------------+----------+---------------------------------+-------------------------------------------------------------+ +| \G | | \G | Display query results vertically. | +| \bug | | \bug | File a bug on GitHub. | +| \clip | | \clip | Copy query to the system clipboard. | +| \dt | | \dt[+] [table] | List or describe tables. | +| \edit | \e | \edit | \edit | Edit query with editor (uses $EDITOR). | +| \f | | \f [name [args..]] | List or execute favorite queries. | +| \fd | | \fd | Delete a favorite query. | +| \fs | | \fs | Save a favorite query. | +| \l | | \l | List databases. | +| \llm | \ai | \llm [arguments] | Interrogate an LLM. | +| \once | \o | \once [-o] | Append next result to an output file (overwrite using -o). | +| \pipe_once | \| | \pipe_once | 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 | | delimiter | 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 | | 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 | Change prompt format. | +| quit | \q | quit | Quit. | +| redirectformat | \Tr | redirectformat | Change the table format used to output redirected results. | +| rehash | \# | rehash | Refresh auto-completions. | +| source | \. | source | Execute commands from file. | +| status | \s | status | Get status information from the server. | +| system | | system | Execute a system shell commmand. | +| tableformat | \T | tableformat | Change the table format used to output interactive results. | +| tee | | tee [-o] | Append all results to an output file (overwrite using -o). | +| use | \u | use | Change to a new database. | +| warnings | \W | warnings | Enable automatic warnings display. | +| watch | | watch [seconds] [-c] | Executes the query every [seconds] seconds (by default 5). | ++----------------+----------+---------------------------------+-------------------------------------------------------------+ diff --git a/test/test_special_iocommands.py b/test/test_special_iocommands.py index 7d059f7e..f74fa040 100644 --- a/test/test_special_iocommands.py +++ b/test/test_special_iocommands.py @@ -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"