1010from datetime import timedelta
1111from pathlib import Path
1212from subprocess import run
13- from tempfile import gettempdir
1413from tempfile import NamedTemporaryFile
1514from tempfile import TemporaryDirectory
15+ from tempfile import gettempdir
1616from typing import Dict
1717from typing import List
1818from typing import TextIO
2626from utils import run_cmd
2727
2828
29- class Shell () :
30- def __init__ (self , shell : str , deactivate_cmd : str , new_esp_idf_env : Dict [str ,str ]):
29+ class Shell :
30+ def __init__ (self , shell : str , deactivate_cmd : str , new_esp_idf_env : Dict [str , str ]):
3131 self .shell = shell
3232 self .deactivate_cmd = deactivate_cmd
3333 self .new_esp_idf_env = new_esp_idf_env
@@ -79,7 +79,7 @@ def spawn(self) -> None:
7979
8080
8181class UnixShell (Shell ):
82- def __init__ (self , shell : str , deactivate_cmd : str , new_esp_idf_env : Dict [str ,str ]):
82+ def __init__ (self , shell : str , deactivate_cmd : str , new_esp_idf_env : Dict [str , str ]):
8383 super ().__init__ (shell , deactivate_cmd , new_esp_idf_env )
8484
8585 with NamedTemporaryFile (dir = self .tmp_dir_path , delete = False , prefix = 'activate_' ) as fd :
@@ -100,8 +100,12 @@ def export_file(self, fd: TextIO) -> None:
100100 stdout = self .autocompletion () # type: ignore
101101 if stdout is not None :
102102 fd .write (f'{ stdout } \n ' )
103- fd .write ((f'echo "\n Done! You can now compile ESP-IDF projects.\n '
104- 'Go to the project directory and run:\n \n idf.py build"\n ' ))
103+ fd .write (
104+ (
105+ 'echo "\n Done! You can now compile ESP-IDF projects.\n '
106+ 'Go to the project directory and run:\n \n idf.py build"\n '
107+ )
108+ )
105109
106110 def export (self ) -> None :
107111 with open (self .script_file_path , 'w' , encoding = 'utf-8' ) as fd :
@@ -195,7 +199,7 @@ def spawn(self) -> None:
195199
196200
197201class FishShell (UnixShell ):
198- def __init__ (self , shell : str , deactivate_cmd : str , new_esp_idf_env : Dict [str ,str ]):
202+ def __init__ (self , shell : str , deactivate_cmd : str , new_esp_idf_env : Dict [str , str ]):
199203 super ().__init__ (shell , deactivate_cmd , new_esp_idf_env )
200204 self .new_esp_idf_env ['IDF_TOOLS_INSTALL_CMD' ] = os .path .join (conf .IDF_PATH , 'install.fish' )
201205 self .new_esp_idf_env ['IDF_TOOLS_EXPORT_CMD' ] = os .path .join (conf .IDF_PATH , 'export.fish' )
@@ -219,7 +223,7 @@ def spawn(self) -> None:
219223
220224
221225class PowerShell (Shell ):
222- def __init__ (self , shell : str , deactivate_cmd : str , new_esp_idf_env : Dict [str ,str ]):
226+ def __init__ (self , shell : str , deactivate_cmd : str , new_esp_idf_env : Dict [str , str ]):
223227 super ().__init__ (shell , deactivate_cmd , new_esp_idf_env )
224228
225229 with NamedTemporaryFile (dir = self .tmp_dir_path , delete = False , prefix = 'activate_' , suffix = '.ps1' ) as fd :
@@ -230,14 +234,16 @@ def __init__(self, shell: str, deactivate_cmd: str, new_esp_idf_env: Dict[str,st
230234 self .new_esp_idf_env ['IDF_TOOLS_EXPORT_CMD' ] = os .path .join (conf .IDF_PATH , 'export.ps1' )
231235
232236 def get_functions (self ) -> str :
233- return '\n ' .join ([
234- r'function idf.py { &python "$Env:IDF_PATH\tools\idf.py" $args }' ,
235- r'function global:esptool.py { &python -m esptool $args }' ,
236- r'function global:espefuse.py { &python -m espefuse $args }' ,
237- r'function global:espsecure.py { &python -m espsecure $args }' ,
238- r'function global:otatool.py { &python "$Env:IDF_PATH\components\app_update\otatool.py" $args }' ,
239- r'function global:parttool.py { &python "$Env:IDF_PATH\components\partition_table\parttool.py" $args }' ,
240- ])
237+ return '\n ' .join (
238+ [
239+ r'function idf.py { &python "$Env:IDF_PATH\tools\idf.py" $args }' ,
240+ r'function global:esptool.py { &python -m esptool $args }' ,
241+ r'function global:espefuse.py { &python -m espefuse $args }' ,
242+ r'function global:espsecure.py { &python -m espsecure $args }' ,
243+ r'function global:otatool.py { &python "$Env:IDF_PATH\components\app_update\otatool.py" $args }' ,
244+ r'function global:parttool.py { &python "$Env:IDF_PATH\components\partition_table\parttool.py" $args }' ,
245+ ]
246+ )
241247
242248 def export (self ) -> None :
243249 self .init_file ()
@@ -254,8 +260,12 @@ def init_file(self) -> None:
254260 fd .write (f'$Env:{ var } ="{ value } "\n ' )
255261 functions = self .get_functions ()
256262 fd .write (f'{ functions } \n ' )
257- fd .write ((f'echo "\n Done! You can now compile ESP-IDF projects.\n '
258- 'Go to the project directory and run:\n \n idf.py build\n "' ))
263+ fd .write (
264+ (
265+ 'echo "\n Done! You can now compile ESP-IDF projects.\n '
266+ 'Go to the project directory and run:\n \n idf.py build\n "'
267+ )
268+ )
259269
260270 def spawn (self ) -> None :
261271 self .init_file ()
@@ -266,7 +276,7 @@ def spawn(self) -> None:
266276
267277
268278class WinCmd (Shell ):
269- def __init__ (self , shell : str , deactivate_cmd : str , new_esp_idf_env : Dict [str ,str ]):
279+ def __init__ (self , shell : str , deactivate_cmd : str , new_esp_idf_env : Dict [str , str ]):
270280 super ().__init__ (shell , deactivate_cmd , new_esp_idf_env )
271281
272282 with NamedTemporaryFile (dir = self .tmp_dir_path , delete = False , prefix = 'activate_' , suffix = '.bat' ) as fd :
@@ -279,14 +289,16 @@ def __init__(self, shell: str, deactivate_cmd: str, new_esp_idf_env: Dict[str,st
279289 self .new_esp_idf_env ['IDF_TOOLS_PY_PATH' ] = conf .IDF_TOOLS_PY
280290
281291 def get_functions (self ) -> str :
282- return '\n ' .join ([
283- r'DOSKEY idf.py=python.exe "%IDF_PATH%\tools\idf.py" $*' ,
284- r'DOSKEY esptool.py=python.exe -m esptool $*' ,
285- r'DOSKEY espefuse.py=python.exe -m espefuse $*' ,
286- r'DOSKEY espsecure.py=python.exe -m espsecure $*' ,
287- r'DOSKEY otatool.py=python.exe "%IDF_PATH%\components\app_update\otatool.py" $*' ,
288- r'DOSKEY parttool.py=python.exe "%IDF_PATH%\components\partition_table\parttool.py" $*' ,
289- ])
292+ return '\n ' .join (
293+ [
294+ r'DOSKEY idf.py=python.exe "%IDF_PATH%\tools\idf.py" $*' ,
295+ r'DOSKEY esptool.py=python.exe -m esptool $*' ,
296+ r'DOSKEY espefuse.py=python.exe -m espefuse $*' ,
297+ r'DOSKEY espsecure.py=python.exe -m espsecure $*' ,
298+ r'DOSKEY otatool.py=python.exe "%IDF_PATH%\components\app_update\otatool.py" $*' ,
299+ r'DOSKEY parttool.py=python.exe "%IDF_PATH%\components\partition_table\parttool.py" $*' ,
300+ ]
301+ )
290302
291303 def export (self ) -> None :
292304 self .init_file ()
@@ -300,14 +312,18 @@ def init_file(self) -> None:
300312 fd .write (f'set { var } ={ value } \n ' )
301313 functions = self .get_functions ()
302314 fd .write (f'{ functions } \n ' )
303- fd .write ('\n ' .join ([
304- 'echo.' ,
305- 'echo Done! You can now compile ESP-IDF projects.' ,
306- 'echo Go to the project directory and run:' ,
307- 'echo.' ,
308- 'echo idf.py build' ,
309- 'echo.' ,
310- ]))
315+ fd .write (
316+ '\n ' .join (
317+ [
318+ 'echo.' ,
319+ 'echo Done! You can now compile ESP-IDF projects.' ,
320+ 'echo Go to the project directory and run:' ,
321+ 'echo.' ,
322+ 'echo idf.py build' ,
323+ 'echo.' ,
324+ ]
325+ )
326+ )
311327
312328 def spawn (self ) -> None :
313329 self .init_file ()
@@ -323,15 +339,22 @@ def spawn(self) -> None:
323339 'zsh' : ZshShell ,
324340 'fish' : FishShell ,
325341 'sh' : UnixShell ,
342+ # KornShell variants
326343 'ksh' : UnixShell ,
344+ 'ksh93' : UnixShell ,
345+ 'mksh' : UnixShell ,
346+ 'lksh' : UnixShell ,
347+ 'pdksh' : UnixShell ,
348+ 'oksh' : UnixShell ,
349+ 'loksh' : UnixShell ,
327350 'dash' : UnixShell ,
328351 'nu' : UnixShell ,
329352 'pwsh.exe' : PowerShell ,
330353 'pwsh' : PowerShell ,
331354 'powershell.exe' : PowerShell ,
332355 'powershell' : PowerShell ,
333356 'cmd.exe' : WinCmd ,
334- 'cmd' : WinCmd
357+ 'cmd' : WinCmd ,
335358}
336359
337360SUPPORTED_SHELLS = ' ' .join (SHELL_CLASSES .keys ())
0 commit comments