@@ -163,9 +163,9 @@ private void ConfigAgentAction(string name, string editor)
163
163
164
164
Process . Start ( info ) ;
165
165
}
166
- else
166
+ else if ( OperatingSystem . IsMacOS ( ) )
167
167
{
168
- // On macOS and Linux , we just depend on the default editor.
168
+ // On macOS, we just depend on shell execute to open file in the default editor.
169
169
FileInfo fileInfo = new ( settingFile ) ;
170
170
if ( fileInfo . Exists )
171
171
{
@@ -189,6 +189,19 @@ private void ConfigAgentAction(string name, string editor)
189
189
info = new ( settingFile ) { UseShellExecute = true } ;
190
190
Process . Start ( info ) ;
191
191
}
192
+ else
193
+ {
194
+ ( string exe , string [ ] args ) = GetDefaultEditorForLinux ( ) ;
195
+
196
+ info = new ( exe ) ;
197
+ foreach ( string arg in args )
198
+ {
199
+ info . ArgumentList . Add ( arg ) ;
200
+ }
201
+
202
+ info . ArgumentList . Add ( settingFile ) ;
203
+ Process . Start ( info ) . WaitForExit ( ) ;
204
+ }
192
205
}
193
206
catch ( Exception ex )
194
207
{
@@ -228,6 +241,25 @@ internal static void AgentNotFound(string name, Shell shell)
228
241
string availableAgentNames = string . Join ( ", " , shell . Agents . Select ( AgentName ) ) ;
229
242
shell . Host . WriteErrorLine ( $ "Cannot find an agent with the name '{ name } '. Available agent(s): { availableAgentNames } .") ;
230
243
}
244
+
245
+ private static ( string editor , string [ ] args ) GetDefaultEditorForLinux ( )
246
+ {
247
+ string editor = Environment . GetEnvironmentVariable ( "EDITOR" ) ;
248
+ if ( string . IsNullOrWhiteSpace ( editor ) )
249
+ {
250
+ return ( "nano" , Array . Empty < string > ( ) ) ;
251
+ }
252
+
253
+ editor = editor . Trim ( ) ;
254
+ int index = editor . IndexOf ( ' ' ) ;
255
+ if ( index is - 1 )
256
+ {
257
+ return ( editor , Array . Empty < string > ( ) ) ;
258
+ }
259
+
260
+ string [ ] args = editor [ ( index + 1 ) ..] . Split ( ' ' , StringSplitOptions . RemoveEmptyEntries ) ;
261
+ return ( editor [ ..index ] , args ) ;
262
+ }
231
263
}
232
264
233
265
internal static partial class Interop
0 commit comments