expect script execute and then detach from child process

I am using expect script to switch to sudo user and then run some custom commands. I am using zsh + Tilix terminal.


set timeout 60
spawn sudo su
expect ": "
sleep .5
send "passwordr"
expect "u0007"
sleep .5
send "cd /path/to/a/folder && source some_scriptr"

As I understand, everything I type after interact instruction runs as a child process of the expect process. This causes some weird autocompletion problem in zsh configuration while copy-pasting a long command. The history navigation with up or down arrow keys causes the command overlapping e.g. when I type the command

echo "Wikipedia is a multilingual online encyclopedia created and maintained as an open collaboration project by a community of volunteer editors using a wiki-based editing system." 

and pressed the up-arrow key, the resulting command looks like
enter image description here

The above problem does not occur when I manually enter the expect script commands.

So, Is there any way to execute expect script with switching user and detach from expect process completely? Or any idea on resolving the above problem?

Go to Source
Author: Mohit Kumar Jangid