33
33
from trogon .widgets .command_tree import CommandTree
34
34
from trogon .widgets .form import CommandForm
35
35
from trogon .widgets .multiple_choice import NonFocusableVerticalScroll
36
+ from subprocess import run
36
37
37
38
if sys .version_info >= (3 , 8 ):
38
39
from importlib import metadata
@@ -44,7 +45,8 @@ class CommandBuilder(Screen):
44
45
COMPONENT_CLASSES = {"version-string" , "prompt" , "command-name-syntax" }
45
46
46
47
BINDINGS = [
47
- Binding (key = "ctrl+r" , action = "close_and_run" , description = "Close & Run" ),
48
+ Binding (key = "ctrl+r" , action = "close_and_run" , description = "Run Command" ),
49
+ Binding (key = "ctrl+y" , action = "copy_command_string" , description = "Copy Command" ),
48
50
Binding (
49
51
key = "ctrl+t,escape" , action = "focus_command_tree" , description = "Focus Command Tree"
50
52
),
@@ -131,6 +133,26 @@ def action_close_and_run(self) -> None:
131
133
self .app .execute_on_exit = True
132
134
self .app .exit ()
133
135
136
+ def action_copy_command_string (self ) -> None :
137
+ cmd : list [str ] = (
138
+ ["copy" ]
139
+ if sys .platform == 'win32'
140
+ else ["pbcopy" ]
141
+ if sys .platform == 'darwin'
142
+ else ["xclip" , "-selection" , "clipboard" ]
143
+ # if linux
144
+ )
145
+
146
+ run (
147
+ cmd ,
148
+ input = self .app_name + " " + " " .join (
149
+ shlex .quote (str (x ))
150
+ for x in self .command_data .to_cli_args (redact_secret = True )
151
+ ),
152
+ text = True ,
153
+ check = False ,
154
+ )
155
+
134
156
def action_exit (self ) -> None :
135
157
self .app .exit ()
136
158
0 commit comments