@@ -11,29 +11,6 @@ namespace SourceGit.Native
1111 [ SupportedOSPlatform ( "linux" ) ]
1212 internal class Linux : OS . IBackend
1313 {
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-
3714 public void SetupApp ( AppBuilder builder )
3815 {
3916 builder . With ( new X11PlatformOptions ( )
@@ -47,6 +24,20 @@ public string FindGitExecutable()
4724 return FindExecutable ( "git" ) ;
4825 }
4926
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+
5041 public List < Models . ExternalTool > FindExternalTools ( )
5142 {
5243 var finder = new Models . ExternalToolsFinder ( ) ;
@@ -61,50 +52,40 @@ public string FindGitExecutable()
6152
6253 public void OpenBrowser ( string url )
6354 {
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 } \" ") ;
6856 }
6957
7058 public void OpenInFileManager ( string path , bool select )
7159 {
72- if ( string . IsNullOrEmpty ( _xdgOpenPath ) )
73- {
74- App . RaiseException ( "" , $ "Can NOT find `xdg-open` command!!!") ;
75- return ;
76- }
77-
7860 if ( Directory . Exists ( path ) )
7961 {
80- Process . Start ( _xdgOpenPath , $ "\" { path } \" ") ;
62+ Process . Start ( "xdg-open" , $ "\" { path } \" ") ;
8163 }
8264 else
8365 {
8466 var dir = Path . GetDirectoryName ( path ) ;
8567 if ( Directory . Exists ( dir ) )
86- Process . Start ( _xdgOpenPath , $ "\" { dir } \" ") ;
68+ Process . Start ( "xdg-open" , $ "\" { dir } \" ") ;
8769 }
8870 }
8971
9072 public void OpenTerminal ( string workdir )
9173 {
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 ) )
10275 {
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. ") ;
10477 return ;
10578 }
10679
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 } \" ") ;
10889 if ( proc != null )
10990 {
11091 proc . WaitForExit ( ) ;
@@ -130,51 +111,10 @@ private string FindExecutable(string filename)
130111 return string . Empty ;
131112 }
132113
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-
171114 private string FindJetBrainsFleet ( )
172115 {
173116 var path = $ "{ Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) } /JetBrains/Toolbox/apps/fleet/bin/Fleet";
174117 return File . Exists ( path ) ? path : FindExecutable ( "fleet" ) ;
175118 }
176-
177- private string _xdgOpenPath = null ;
178- private Terminal _terminal = null ;
179119 }
180120}
0 commit comments