Skip to content

Commit 79eb792

Browse files
author
Mathieu Gascon-Lefebvre
committed
Add a configuration option to execute commands on startup.
1 parent abc03c5 commit 79eb792

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Contributors:
122122
* Daniele Varrazzo
123123
* Daniel Kukula (dkuku)
124124
* Kian-Meng Ang (kianmeng)
125+
* Mathieu Gascon-Lefebvre (mlefebvre)
125126

126127
Creator:
127128
--------

changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Features:
4949

5050
* Add `max_field_width` setting to config, to enable more control over field truncation ([related issue](https://github.com/dbcli/pgcli/issues/1250)).
5151
* Re-run last query via bare `\watch`. (Thanks: `Saif Hakim`_)
52+
* Add a configuration option to execute commands on startup ([related issue](https://github.com/dbcli/pgcli/issues/247)).
5253

5354
Bug fixes:
5455
----------

pgcli/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def __init__(
241241
self.float_format = c["data_formats"]["float"]
242242
auth.keyring_initialize(c["main"].as_bool("keyring"), logger=self.logger)
243243
self.show_bottom_toolbar = c["main"].as_bool("show_bottom_toolbar")
244+
self.startup_command = c["main"]["startup_command"]
244245

245246
self.pgspecial.pset_pager(
246247
self.config["main"].as_bool("enable_pager") and "on" or "off"
@@ -778,6 +779,10 @@ def run_cli(self):
778779
print("Home: http://pgcli.com")
779780

780781
try:
782+
if self.startup_command:
783+
print(f"Executing startup command: {self.startup_command}")
784+
self.handle_watch_command(self.startup_command)
785+
781786
while True:
782787
try:
783788
text = self.prompt_app.prompt()

pgcli/pgclirc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ enable_pager = True
158158
# Use keyring to automatically save and load password in a secure manner
159159
keyring = True
160160

161+
# Command to run at startup. Multiple commands can be specified if separated by a semicolon.
162+
startup_command = ''
163+
161164
# Custom colors for the completion menu, toolbar, etc.
162165
[colors]
163166
completion-menu.completion.current = 'bg:#ffffff #000000'

0 commit comments

Comments
 (0)