1212from functools import lru_cache , partial
1313
1414from kitty .bash import decode_ansi_c_quoted_string
15- from kitty .constants import kitty_base_dir , shell_integration_dir , terminfo_dir
15+ from kitty .constants import kitten_exe , kitty_base_dir , shell_integration_dir , terminfo_dir
1616from kitty .fast_data_types import CURSOR_BEAM , CURSOR_BLOCK , CURSOR_UNDERLINE
1717from kitty .shell_integration import setup_bash_env , setup_fish_env , setup_zsh_env
1818
@@ -48,7 +48,7 @@ def basic_shell_env(home_dir):
4848 return ans
4949
5050
51- def safe_env_for_running_shell (argv , home_dir , rc = '' , shell = 'zsh' ):
51+ def safe_env_for_running_shell (argv , home_dir , rc = '' , shell = 'zsh' , with_kitten = False ):
5252 ans = basic_shell_env (home_dir )
5353 if shell == 'zsh' :
5454 argv .insert (1 , '--noglobalrcs' )
@@ -64,10 +64,14 @@ def safe_env_for_running_shell(argv, home_dir, rc='', shell='zsh'):
6464 print (rc + '\n ' , file = f )
6565 setup_fish_env (ans , argv )
6666 elif shell == 'bash' :
67- setup_bash_env (ans , argv )
68- ans ['KITTY_BASH_INJECT' ] += ' posix'
69- ans ['KITTY_BASH_POSIX_ENV' ] = os .path .join (home_dir , '.bashrc' )
70- with open (ans ['KITTY_BASH_POSIX_ENV' ], 'w' ) as f :
67+ bashrc = os .path .join (home_dir , '.bashrc' )
68+ if with_kitten :
69+ ans ['KITTY_RUNNING_BASH_INTEGRATION_TEST' ] = bashrc
70+ else :
71+ setup_bash_env (ans , argv )
72+ ans ['KITTY_BASH_INJECT' ] += ' posix'
73+ ans ['KITTY_BASH_POSIX_ENV' ] = bashrc
74+ with open (bashrc , 'w' ) as f :
7175 # ensure LINES and COLUMNS are kept up to date
7276 print ('shopt -s checkwinsize' , file = f )
7377 if rc :
@@ -77,13 +81,17 @@ def safe_env_for_running_shell(argv, home_dir, rc='', shell='zsh'):
7781
7882class ShellIntegration (BaseTest ):
7983
84+ with_kitten = False
85+
8086 @contextmanager
8187 def run_shell (self , shell = 'zsh' , rc = '' , cmd = '' , setup_env = None ):
8288 home_dir = self .home_dir = os .path .realpath (tempfile .mkdtemp ())
8389 cmd = cmd or shell
8490 cmd = shlex .split (cmd .format (** locals ()))
85- env = (setup_env or safe_env_for_running_shell )(cmd , home_dir , rc = rc , shell = shell )
91+ env = (setup_env or safe_env_for_running_shell )(cmd , home_dir , rc = rc , shell = shell , with_kitten = self . with_kitten )
8692 try :
93+ if self .with_kitten :
94+ cmd = [kitten_exe (), 'run-shell' , '--shell' , shlex .join (cmd )]
8795 pty = self .create_pty (cmd , cwd = home_dir , env = env )
8896 i = 10
8997 while i > 0 and not pty .screen_contents ().strip ():
@@ -325,9 +333,10 @@ def redrawn():
325333
326334 # test startup file sourcing
327335
328- def setup_env (excluded , argv , home_dir , rc = '' , shell = 'bash' ):
336+ def setup_env (excluded , argv , home_dir , rc = '' , shell = 'bash' , with_kitten = self . with_kitten ):
329337 ans = basic_shell_env (home_dir )
330- setup_bash_env (ans , argv )
338+ if not with_kitten :
339+ setup_bash_env (ans , argv )
331340 for x in {'profile' , 'bash.bashrc' , '.bash_profile' , '.bash_login' , '.profile' , '.bashrc' , 'rcfile' } - excluded :
332341 with open (os .path .join (home_dir , x ), 'w' ) as f :
333342 if x == '.bashrc' and rc :
@@ -381,3 +390,7 @@ def run_test(argv, *expected, excluded=(), rc='', wait_string='PROMPT $', assert
381390 }.items ():
382391 q = q + "'"
383392 self .ae (decode_ansi_c_quoted_string (q , 0 )[0 ], e , f'Failed to decode: { q !r} ' )
393+
394+
395+ class ShellIntegrationWithKitten (ShellIntegration ):
396+ with_kitten = True
0 commit comments