File: complete.py

package info (click to toggle)
fish 4.2.1-3.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,976 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (92 lines) | stat: -rw-r--r-- 2,267 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
from pexpect_helper import SpawnedProc, control

sp = SpawnedProc()
send, sendline, sleep, expect_prompt, expect_re, expect_str = (
    sp.send,
    sp.sendline,
    sp.sleep,
    sp.expect_prompt,
    sp.expect_re,
    sp.expect_str,
)
expect_prompt()

# Verify COMPLETE_AUTO_SPACE behavior
sendline("complete -x -c monster -a truck")
expect_prompt()
sendline("complete -x -c monster -a energy=")
expect_prompt()
send("monster t")
sleep(0.1)
send("\t")
sleep(0.1)
send("!")
expect_str("monster truck !")  # space
send("\b" * 64)
send("monster e")
sleep(0.1)
send("\t")
sleep(0.1)
send("!")
expect_str("monster energy=!")  # no space
send("\b" * 64)

sendline(
    """
    # Make sure this function does nothing
    function my_is; :; end
    complete -c my_is -n 'test (count (commandline -xpc)) = 1' -xa arg
    complete -c my_is -n '__fish_seen_subcommand_from not' -xa '(
	set -l cmd (commandline -xpc) (commandline -ct)
	set cmd (string join " " my_is $cmd[3..-1])" "
	commandline --replace --current-process $cmd
	complete -C"$cmd"
    )'
"""
)

send("my_is not \t")
send("still.alive")
expect_re(".*still.alive")
sendline("")

# Check cancelling completion acceptance
# (bind cancel to something else so we don't have to mess with the escape delay)
sendline("bind ctrl-g cancel")
sendline("complete -c echo -x -a 'foooo bar'")
send("echo fo\t")
send("\x07")
sendline("bar")
expect_re("bar")
sendline("echo fo\t")
expect_re("foooo")

# As soon as something after the "complete" happened,
# cancel should not undo.
# In this case that's the space after the tab!
send("echo fo\t ")
send("\x07")
sendline("bar")
expect_re("foooo bar")

sendline("bind ctrl-g 'commandline -f cancel; commandline \"\"'")
send("echo fo\t")
expect_re("foooo")
send("\x07")
sendline("echo bar")
expect_re("\n.*bar")
sendline("echo fo\t")
expect_re("foooo")

# Custom completions that access the command line.
sendline("complete -e :; complete : -a '(echo (commandline -ct)-completed)'")
send(": abcd" + control("b") * 2 + "\t")
expect_str(": abcd-completed")
send(control("u"))
# Another one.
sendline("mkdir -p foo/bar; touch foo/bar/baz.fish")
send("source foo/b/baz.fish")
send(control("b") * 9 + "\t")
expect_str("source foo/bar/baz.fish")
send(control("u"))