@@ -52,7 +52,7 @@ function xlings_config_file_parse(filename)
5252 end
5353 }
5454 }
55-
55+
5656 if not file then
5757 cprint (" ${yellow}[xlings]: " .. err )
5858 os .sleep (1000 )
@@ -105,19 +105,47 @@ function xlings_save_config_to_file(config, file)
105105end
106106
107107function xlings_exec (cmd )
108- os .exec (platform .get_config_info ().cmd_wrapper .. tostring (cmd ))
108+ if is_host (" windows" ) then
109+ xlings_run_in_script (cmd )
110+ else
111+ os .exec (cmd )
112+ end
113+ end
114+
115+ function xlings_run_in_script (content , use_adnim )
116+ if is_host (" windows" ) then
117+ xlings_run_bat_script (content , use_adnim )
118+ else
119+ xlings_run_shell_script (content , use_adnim )
120+ end
109121end
110122
111123function xlings_run_bat_script (content , use_adnim ) -- only for windows
112124 local script_file = path .join (platform .get_config_info ().rcachedir , " win_tmp.bat" )
113- xlings_create_file_and_write (script_file , content )
125+ xlings_create_file_and_write (script_file , string.format ([[
126+ @echo off
127+
128+ ::dont modify this file, this file is generated by xlings
129+
130+ %s
131+ ]] , content or " " ))
114132 if use_adnim then
115133 os .exec ([[ powershell -Command "Start-Process ']] .. script_file .. [[ ' -Verb RunAs -Wait]] )
116134 else
117135 os .exec (script_file )
118136 end
119137end
120138
139+ function xlings_run_shell_script (content , use_adnim ) -- only for linux
140+ local script_file = path .join (platform .get_config_info ().rcachedir , " linux_tmp.sh" )
141+ xlings_create_file_and_write (script_file , content )
142+ if use_adnim then
143+ os .exec ([[ sudo bash ']] .. script_file .. [[ ']] )
144+ else
145+ os .exec (" bash " .. script_file )
146+ end
147+ end
148+
121149function xlings_python (file )
122150 if os .host () == " windows" then
123151 file = file :gsub (" /" , " \\ " )
@@ -212,13 +240,13 @@ function xlings_path_format(path)
212240 path = tostring (path )
213241
214242 path = path :gsub (" \\ " , " /" )
215-
243+
216244 -- remove ./
217245 path = path :gsub (" %./" , " " )
218-
246+
219247 -- remove ../
220248 -- path = path:gsub("%.%.%/", "")
221-
249+
222250 -- /// -> /
223251 path = path :gsub (" /+" , " /" )
224252
@@ -253,7 +281,7 @@ function get_linux_distribution()
253281 if os_release then
254282 local content = os_release :read (" *a" )
255283 os_release :close ()
256-
284+
257285 local id = content :match (' ID=["]*([^"\n ]+)["]*' )
258286 local version = content :match (' VERSION_ID=["]*([^"\n ]+)["]*' )
259287 local name = content :match (' PRETTY_NAME=["]*([^"\n ]+)["]*' )
@@ -263,7 +291,7 @@ function get_linux_distribution()
263291 name = name :lower ()
264292 name = name :gsub (" %s+%d[%d%.]*%s*.*$" , " " )
265293 end
266-
294+
267295 return {
268296 id = id or " unknown" ,
269297 version = version or " unknown" ,
0 commit comments