fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
58e7a50de
master
1#!/usr/bin/env python3 2from pexpect_helper import SpawnedProc ,control 3 4sp = SpawnedProc () 5send ,sendline ,sleep ,expect_prompt = ( 6sp .send , 7sp .sendline , 8sp .sleep , 9sp .expect_prompt , 10) 11 12 13def use_suggestion (* ,delay = 0.1 ): 14sleep (delay ) 15send ("\033[C" ) 16sendline ("" ) 17 18 19def run (cmd :str ): 20sendline (cmd ) 21expect_prompt () 22 23 24expect_prompt () 25 26run ("echo Hello" ) 27 28# basic samecase history suggestion 29send ("echo He" ) 30use_suggestion () 31expect_prompt (">echo Hello\r\nHello" ) 32 33# case-correcting history suggestion 34send ("echo he" ) 35use_suggestion () 36expect_prompt (">echo Hello\r\nHello" ) 37 38# prefer samecase history suggestions, even if older 39run ("echo hello" ) 40send ("echo He" ) 41use_suggestion () 42expect_prompt (">echo Hello\r\nHello" ) 43 44# case-correcting command suggestion 45send ("Tru" ) 46use_suggestion (delay = 2.0 ) 47expect_prompt (">true \r\n" ) 48 49# the motivating example: prefer icase history suggestions over icase completion suggestions 50run ("mkdir -p Projects/myproject Projects/wrongproject" ) 51 52# (prerequisite: without any relevant history, and with more than one subdir, fish can't suggest deeper than Projects/) 53send ("cd pro" ) 54use_suggestion (delay = 0.5 ) 55expect_prompt (">cd Projects/\r\n" ) 56 57run ("cd .." ) 58 59# (and now the actual test) 60run ("cd Projects/myproject" ) 61run ("cd ../.." ) 62 63send ("cd pro" ) 64use_suggestion () 65expect_prompt (">cd Projects/myproject\r\n" ) 66 67run ("cd ../.." ) 68 69# BUT prefer samecase completion suggestions over icase history suggestions 70run ("mkdir problems" ) 71 72send ("cd pro" ) 73use_suggestion (delay = 0.5 ) 74expect_prompt (">cd problems/\r\n" ) 75 76send (control ("c" )) 77run ("touch configure && chmod +x configure" ) 78run ("echo clean &&\n./configure" ) 79run ("rm configure" ) 80send ("./con" ) 81use_suggestion () 82expect_prompt (">./con\r\n" ) 83 84send (control ("c" )) 85run ("touch somecommand" ) 86run ("chmod +x somecommand" ) 87run ('echo "multiline-token\n./somecommand arg1 arg2"' ) 88send ("./some" ) 89use_suggestion () 90expect_prompt (">./somecommand \r\n" )