mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 14:03:58 +00:00
1402bae7f4
Prior to this change, abbreviations were stored as fish variables, often universal. However we intend to add additional features to abbreviations which would be very awkward to shoe-horn into variables. Re-implement abbreviations using a builtin, managing them internally. Existing abbreviations stored in universal variables are still imported, for compatibility. However new abbreviations will need to be added to a function. A follow-up commit will add it. Now that abbr is a built-in, remove the abbr function; but leave the abbr.fish file so that stale files from past installs do not override the abbr builtin.
61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
from pexpect_helper import SpawnedProc
|
|
|
|
import re
|
|
|
|
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()
|
|
|
|
# ? prints the command line, bracketed by <>, then clears it.
|
|
sendline(r"""bind '?' 'echo "<$(commandline)>"; commandline ""'; """)
|
|
expect_prompt()
|
|
|
|
# Basic test.
|
|
# Default abbreviations expand only in command position.
|
|
sendline(r"abbr alpha beta")
|
|
expect_prompt()
|
|
|
|
send(r"alpha ?")
|
|
expect_str(r"<beta >")
|
|
|
|
send(r"echo alpha ?")
|
|
expect_str(r"<echo alpha >")
|
|
|
|
# Abbreviation expansions may have multiple words.
|
|
sendline(r"abbr --add emacsnw emacs -nw")
|
|
expect_prompt()
|
|
send(r"emacsnw ?")
|
|
expect_str(r"<emacs -nw >")
|
|
|
|
# Regression test that abbreviations still expand in incomplete positions.
|
|
sendline(r"""abbr --erase (abbr --list)""")
|
|
expect_prompt()
|
|
sendline(r"""abbr --add foo echo bar""")
|
|
expect_prompt()
|
|
sendline(r"if foo")
|
|
expect_str(r"if echo bar")
|
|
sendline(r"end")
|
|
expect_prompt(r"bar")
|
|
|
|
# Regression test that 'echo (' doesn't hang.
|
|
sendline(r"echo )")
|
|
expect_str(r"Unexpected ')' for unopened parenthesis")
|
|
send(r"?")
|
|
expect_str(r"<echo )>")
|
|
|
|
# Support position anywhere.
|
|
sendline(r"abbr alpha --position anywhere beta2")
|
|
|
|
send(r"alpha ?")
|
|
expect_str(r"<beta2 >")
|
|
|
|
send(r"echo alpha ?")
|
|
expect_str(r"<echo beta2 >")
|