@@ -11,29 +11,6 @@ namespace SourceGit.Native
11
11
[ SupportedOSPlatform ( "linux" ) ]
12
12
internal class Linux : OS . IBackend
13
13
{
14
- class Terminal
15
- {
16
- public string FilePath { get ; set ; }
17
- public string OpenArgFormat { get ; set ; }
18
-
19
- public Terminal ( string exec , string fmt )
20
- {
21
- FilePath = exec ;
22
- OpenArgFormat = fmt ;
23
- }
24
-
25
- public void Open ( string dir )
26
- {
27
- Process . Start ( FilePath , string . Format ( OpenArgFormat , dir ) ) ;
28
- }
29
- }
30
-
31
- public Linux ( )
32
- {
33
- _xdgOpenPath = FindExecutable ( "xdg-open" ) ;
34
- _terminal = FindTerminal ( ) ;
35
- }
36
-
37
14
public void SetupApp ( AppBuilder builder )
38
15
{
39
16
builder . With ( new X11PlatformOptions ( )
@@ -47,6 +24,20 @@ public string FindGitExecutable()
47
24
return FindExecutable ( "git" ) ;
48
25
}
49
26
27
+ public string FindTerminal ( Models . ShellOrTerminal shell )
28
+ {
29
+ var pathVariable = Environment . GetEnvironmentVariable ( "PATH" ) ?? string . Empty ;
30
+ var pathes = pathVariable . Split ( Path . PathSeparator , StringSplitOptions . RemoveEmptyEntries ) ;
31
+ foreach ( var path in pathes )
32
+ {
33
+ var test = Path . Combine ( path , shell . Exec ) ;
34
+ if ( File . Exists ( test ) )
35
+ return test ;
36
+ }
37
+
38
+ return string . Empty ;
39
+ }
40
+
50
41
public List < Models . ExternalTool > FindExternalTools ( )
51
42
{
52
43
var finder = new Models . ExternalToolsFinder ( ) ;
@@ -61,50 +52,40 @@ public string FindGitExecutable()
61
52
62
53
public void OpenBrowser ( string url )
63
54
{
64
- if ( string . IsNullOrEmpty ( _xdgOpenPath ) )
65
- App . RaiseException ( "" , $ "Can NOT find `xdg-open` command!!!") ;
66
- else
67
- Process . Start ( _xdgOpenPath , $ "\" { url } \" ") ;
55
+ Process . Start ( "xdg-open" , $ "\" { url } \" ") ;
68
56
}
69
57
70
58
public void OpenInFileManager ( string path , bool select )
71
59
{
72
- if ( string . IsNullOrEmpty ( _xdgOpenPath ) )
73
- {
74
- App . RaiseException ( "" , $ "Can NOT find `xdg-open` command!!!") ;
75
- return ;
76
- }
77
-
78
60
if ( Directory . Exists ( path ) )
79
61
{
80
- Process . Start ( _xdgOpenPath , $ "\" { path } \" ") ;
62
+ Process . Start ( "xdg-open" , $ "\" { path } \" ") ;
81
63
}
82
64
else
83
65
{
84
66
var dir = Path . GetDirectoryName ( path ) ;
85
67
if ( Directory . Exists ( dir ) )
86
- Process . Start ( _xdgOpenPath , $ "\" { dir } \" ") ;
68
+ Process . Start ( "xdg-open" , $ "\" { dir } \" ") ;
87
69
}
88
70
}
89
71
90
72
public void OpenTerminal ( string workdir )
91
73
{
92
- var dir = string . IsNullOrEmpty ( workdir ) ? "~" : workdir ;
93
- if ( _terminal == null )
94
- App . RaiseException ( dir , $ "Only supports gnome-terminal/konsole/xfce4-terminal/lxterminal/deepin-terminal/mate-terminal/foot!") ;
95
- else
96
- _terminal . Open ( dir ) ;
97
- }
98
-
99
- public void OpenWithDefaultEditor ( string file )
100
- {
101
- if ( string . IsNullOrEmpty ( _xdgOpenPath ) )
74
+ if ( string . IsNullOrEmpty ( OS . ShellOrTerminal ) || ! File . Exists ( OS . ShellOrTerminal ) )
102
75
{
103
- App . RaiseException ( "" , $ "Can NOT find `xdg-open` command!!! ") ;
76
+ App . RaiseException ( workdir , $ "Can not found terminal! Please confirm that the correct shell/terminal has been configured. ") ;
104
77
return ;
105
78
}
106
79
107
- var proc = Process . Start ( _xdgOpenPath , $ "\" { file } \" ") ;
80
+ var startInfo = new ProcessStartInfo ( ) ;
81
+ startInfo . WorkingDirectory = string . IsNullOrEmpty ( workdir ) ? "~" : workdir ;
82
+ startInfo . FileName = OS . ShellOrTerminal ;
83
+ Process . Start ( startInfo ) ;
84
+ }
85
+
86
+ public void OpenWithDefaultEditor ( string file )
87
+ {
88
+ var proc = Process . Start ( "xdg-open" , $ "\" { file } \" ") ;
108
89
if ( proc != null )
109
90
{
110
91
proc . WaitForExit ( ) ;
@@ -130,51 +111,10 @@ private string FindExecutable(string filename)
130
111
return string . Empty ;
131
112
}
132
113
133
- private Terminal FindTerminal ( )
134
- {
135
- var pathVariable = Environment . GetEnvironmentVariable ( "PATH" ) ?? string . Empty ;
136
- var pathes = pathVariable . Split ( Path . PathSeparator , StringSplitOptions . RemoveEmptyEntries ) ;
137
- foreach ( var path in pathes )
138
- {
139
- var test = Path . Combine ( path , "gnome-terminal" ) ;
140
- if ( File . Exists ( test ) )
141
- return new Terminal ( test , "--working-directory=\" {0}\" " ) ;
142
-
143
- test = Path . Combine ( path , "konsole" ) ;
144
- if ( File . Exists ( test ) )
145
- return new Terminal ( test , "--workdir \" {0}\" " ) ;
146
-
147
- test = Path . Combine ( path , "xfce4-terminal" ) ;
148
- if ( File . Exists ( test ) )
149
- return new Terminal ( test , "--working-directory=\" {0}\" " ) ;
150
-
151
- test = Path . Combine ( path , "lxterminal" ) ;
152
- if ( File . Exists ( test ) )
153
- return new Terminal ( test , "--working-directory=\" {0}\" " ) ;
154
-
155
- test = Path . Combine ( path , "deepin-terminal" ) ;
156
- if ( File . Exists ( test ) )
157
- return new Terminal ( test , "--work-directory \" {0}\" " ) ;
158
-
159
- test = Path . Combine ( path , "mate-terminal" ) ;
160
- if ( File . Exists ( test ) )
161
- return new Terminal ( test , "--working-directory=\" {0}\" " ) ;
162
-
163
- test = Path . Combine ( path , "foot" ) ;
164
- if ( File . Exists ( test ) )
165
- return new Terminal ( test , "--working-directory=\" {0}\" " ) ;
166
- }
167
-
168
- return null ;
169
- }
170
-
171
114
private string FindJetBrainsFleet ( )
172
115
{
173
116
var path = $ "{ Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) } /JetBrains/Toolbox/apps/fleet/bin/Fleet";
174
117
return File . Exists ( path ) ? path : FindExecutable ( "fleet" ) ;
175
118
}
176
-
177
- private string _xdgOpenPath = null ;
178
- private Terminal _terminal = null ;
179
119
}
180
120
}
0 commit comments