fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
a0d8d27f4
master
1#!/usr/bin/env python3 2from pexpect_helper import SpawnedProc 3import os 4import signal 5import tempfile 6 7# Ensure that on-exit handlers run even if we get SIGHUP. 8with tempfile .NamedTemporaryFile (mode = "r" ,encoding = "utf8" )as tf : 9sp = SpawnedProc () 10fish_pid = sp .spawn .pid 11sp .expect_prompt () 12sp .sendline ( 13"function myexit --on-event fish_exit; command echo $fish_pid > {filename}; end" .format ( 14filename = tf .name 15 ) 16 ) 17sp .expect_prompt () 18os .kill (fish_pid ,signal .SIGHUP ) 19# Note that fish's SIGHUP handling in interactive mode races with the call to select. 20# So actually close its stdin, like a terminal emulator would do. 21sp .spawn .close (force = False ) 22sp .spawn .wait () 23tf .seek (0 ) 24line = tf .readline ().strip () 25if line != str (fish_pid ): 26colors = sp .colors () 27"""{RED}Failed to find pid written by exit handler{RESET}""" .format ( 29** colors 30 ) 31 ) 32"""Expected '{}', found '{}'""" .format (fish_pid ,line ))