mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-21 03:21:16 -03:00
Re-implement abbreviations as a built-in
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.
This commit is contained in:
@@ -1,29 +1,36 @@
|
||||
#RUN: %fish %s
|
||||
|
||||
# Universal abbreviations are imported.
|
||||
set -U _fish_abbr_cuckoo somevalue
|
||||
set fish (status fish-path)
|
||||
$fish -c abbr
|
||||
# CHECK: abbr -a -U -- cuckoo somevalue
|
||||
|
||||
# Test basic add and list of __abbr1
|
||||
abbr __abbr1 alpha beta gamma
|
||||
abbr | grep __abbr1
|
||||
# CHECK: abbr -a -U -- __abbr1 'alpha beta gamma'
|
||||
# CHECK: abbr -a -- __abbr1 'alpha beta gamma'
|
||||
|
||||
# Erasing one that doesn\'t exist should do nothing
|
||||
abbr --erase NOT_AN_ABBR
|
||||
abbr | grep __abbr1
|
||||
# CHECK: abbr -a -U -- __abbr1 'alpha beta gamma'
|
||||
# CHECK: abbr -a -- __abbr1 'alpha beta gamma'
|
||||
|
||||
# Adding existing __abbr1 should be idempotent
|
||||
abbr __abbr1 alpha beta gamma
|
||||
abbr | grep __abbr1
|
||||
# CHECK: abbr -a -U -- __abbr1 'alpha beta gamma'
|
||||
# CHECK: abbr -a -- __abbr1 'alpha beta gamma'
|
||||
|
||||
# Replacing __abbr1 definition
|
||||
abbr __abbr1 delta
|
||||
abbr | grep __abbr1
|
||||
# CHECK: abbr -a -U -- __abbr1 delta
|
||||
# CHECK: abbr -a -- __abbr1 delta
|
||||
|
||||
# __abbr1 -s and --show tests
|
||||
abbr -s | grep __abbr1
|
||||
abbr --show | grep __abbr1
|
||||
# CHECK: abbr -a -U -- __abbr1 delta
|
||||
# CHECK: abbr -a -U -- __abbr1 delta
|
||||
# CHECK: abbr -a -- __abbr1 delta
|
||||
# CHECK: abbr -a -- __abbr1 delta
|
||||
|
||||
# Test erasing __abbr1
|
||||
abbr -e __abbr1
|
||||
@@ -32,13 +39,13 @@ abbr | grep __abbr1
|
||||
# Ensure we escape special characters on output
|
||||
abbr '~__abbr2' '$xyz'
|
||||
abbr | grep __abbr2
|
||||
# CHECK: abbr -a -U -- '~__abbr2' '$xyz'
|
||||
# CHECK: abbr -a -- '~__abbr2' '$xyz'
|
||||
abbr -e '~__abbr2'
|
||||
|
||||
# Ensure we handle leading dashes in abbreviation names properly
|
||||
abbr -- --__abbr3 xyz
|
||||
abbr | grep __abbr3
|
||||
# CHECK: abbr -a -U -- --__abbr3 xyz
|
||||
# CHECK: abbr -a -- --__abbr3 xyz
|
||||
abbr -e -- --__abbr3
|
||||
|
||||
# Test that an abbr word containing spaces is rejected
|
||||
@@ -51,7 +58,7 @@ abbr __abbr4 omega
|
||||
abbr | grep __abbr5
|
||||
abbr -r __abbr4 __abbr5
|
||||
abbr | grep __abbr5
|
||||
# CHECK: abbr -a -U -- __abbr5 omega
|
||||
# CHECK: abbr -a -- __abbr5 omega
|
||||
abbr -e __abbr5
|
||||
abbr | grep __abbr4
|
||||
|
||||
@@ -77,7 +84,7 @@ abbr -r __abbr8 __abbr9 __abbr10
|
||||
abbr | grep __abbr8
|
||||
abbr | grep __abbr9
|
||||
abbr | grep __abbr10
|
||||
# CHECK: abbr -a -U -- __abbr8 omega
|
||||
# CHECK: abbr -a -- __abbr8 omega
|
||||
|
||||
# Test renaming to existing abbreviation
|
||||
abbr __abbr11 omega11
|
||||
@@ -106,3 +113,22 @@ echo $status
|
||||
abbr -q banana __abbr8 foobar
|
||||
echo $status
|
||||
# CHECK: 0
|
||||
|
||||
abbr --add grape --position nowhere juice
|
||||
echo $status
|
||||
# CHECKERR: abbr: Invalid position 'nowhere'
|
||||
# CHECKERR: Position must be one of: command, anywhere.
|
||||
# CHECK: 2
|
||||
|
||||
abbr --add grape --position anywhere juice
|
||||
echo $status
|
||||
# CHECK: 0
|
||||
|
||||
abbr --add grape --position command juice
|
||||
echo $status
|
||||
# CHECK: 0
|
||||
|
||||
abbr --query banana --position anywhere
|
||||
echo $status
|
||||
# CHECKERR: abbr: --position option requires --add
|
||||
# CHECK: 2
|
||||
|
||||
@@ -19,13 +19,13 @@ 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 >")
|
||||
|
||||
# Default abbreviations expand only in command position.
|
||||
send(r"echo alpha ?")
|
||||
expect_str(r"<echo alpha >")
|
||||
|
||||
@@ -50,3 +50,12 @@ 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 >")
|
||||
|
||||
Reference in New Issue
Block a user