Skip to content

Commit 69f4e8e

Browse files
author
Mathieu Gascon-Lefebvre
committed
Add a configuration option to execute commands on startup.
1 parent 123e00a commit 69f4e8e

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
@@ -118,6 +118,7 @@ Contributors:
118118
* Miroslav Šedivý (eumiro)
119119
* Eric R Young (ERYoung11)
120120
* Paweł Sacawa (psacawa)
121+
* Mathieu Gascon-Lefebvre (mlefebvre)
121122

122123
Creator:
123124
--------

changelog.rst

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

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

1011
Bug fixes:
1112
----------

pgcli/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def __init__(
237237
self.float_format = c["data_formats"]["float"]
238238
self.initialize_keyring()
239239
self.show_bottom_toolbar = c["main"].as_bool("show_bottom_toolbar")
240+
self.startup_command = c["main"]["startup_command"]
240241

241242
self.pgspecial.pset_pager(
242243
self.config["main"].as_bool("enable_pager") and "on" or "off"
@@ -758,6 +759,10 @@ def run_cli(self):
758759
print("Home: http://pgcli.com")
759760

760761
try:
762+
if self.startup_command:
763+
print(f"Executing startup command: {self.startup_command}")
764+
self.handle_watch_command(self.startup_command)
765+
761766
while True:
762767
try:
763768
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)