Skip to content

Commit

Permalink
the pattern ^s1^s2^ can't ignore the last ^.
Browse files Browse the repository at this point in the history
The space will expand-abbr, show the `s2` will expand when it has a space.
So we want the last `^` to confirm the `s2` has finished
  • Loading branch information
tenfyzhong committed Jan 31, 2024
1 parent 31d43b4 commit 9b5743d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions conf.d/bang.fish
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
# !%
# ^string1^string2^

set -gx _bang_regex '^!(?<cmdp>!|-?\d+|\w+|\?[^?]+\?|#)(?<wordp>:?\^|:?\$|:?\*|:?-|:?%|:\d+-\d+|:\d+\*|:-\d+|:\d+-|:\d+|:s\^[^^]+\^[^^]+\^?)?$'
set -gx _bang_regex '^!(?<cmdp>!|-?\d+|\w+|\?[^?]+\?|#)(?<wordp>:?\^|:?\$|:?\*|:?-|:?%|:\d+-\d+|:\d+\*|:-\d+|:\d+-|:\d+|:s\^[^^]+\^[^^]+\^)?$'
abbr -a _bang -r $_bang_regex --position anywhere --function _bang

set -gx _bang_special_regex '^!\^|!\$|!\*|!%$'
abbr -a _bang_special -r $_bang_special_regex --position anywhere --function _bang

set -gx _bang_gsub_regex '^\^(?<s1>[^^]+)\^(?<s2>[^^]+)\^?$'
set -gx _bang_gsub_regex '^\^(?<s1>[^^]+)\^(?<s2>[^^]+)\^$'
abbr -a _bang_gsub -r $_bang_gsub_regex --position anywhere --function _bang

bind -M default \r expand-abbr execute
Expand Down
48 changes: 26 additions & 22 deletions tests/bang.fish
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,21 @@ set output (_bang '!mv:6*')
set output (_bang '!mv:s^foo^hello^')
@test 'test !mv:s^foo^hello^' "$output" = 'mv hello bar hellobar barhello hellobarhello'

@test 'test regex match !mv:s^foo^hello' (string match -q -r $_bang_regex '!mv:s^foo^hello') $status -eq 0
set output (_bang '!mv:s^foo^hello')
@test 'test !mv:s^foo^hello' "$output" = 'mv hello bar hellobar barhello hellobarhello'
@test 'test regex match !mv:s^foo bar^hello world^' (string match -q -r $_bang_regex '!mv:s^foo bar ^hello world^') $status -eq 0
set output (_bang '!mv:s^foo bar^hello world^')
@test 'test !mv:s^foo bar^hello world^' "$output" = 'mv hello world foobar barfoo foobarfoo'

# @test 'test regex match !mv:s^foo^hello' (string match -q -r $_bang_regex '!mv:s^foo^hello') $status -eq 0
# set output (_bang '!mv:s^foo^hello')
# @test 'test !mv:s^foo^hello' "$output" = 'mv hello bar hellobar barhello hellobarhello'

@test 'test regex match !mv:s^foo1^hello^' (string match -q -r $_bang_regex '!mv:s^foo1^hello^') $status -eq 0
set output (_bang '!mv:s^foo1^hello^')
@test 'test !mv:s^foo^hello^' "$output" = 'mv foo bar foobar barfoo foobarfoo'

@test 'test regex match !mv:s^foo1^hello' (string match -q -r $_bang_regex '!mv:s^foo1^hello') $status -eq 0
set output (_bang '!mv:s^foo1^hello')
@test 'test !mv:s^foo^hello^' "$output" = 'mv foo bar foobar barfoo foobarfoo'
# @test 'test regex match !mv:s^foo1^hello' (string match -q -r $_bang_regex '!mv:s^foo1^hello') $status -eq 0
# set output (_bang '!mv:s^foo1^hello')
# @test 'test !mv:s^foo^hello^' "$output" = 'mv foo bar foobar barfoo foobarfoo'

@test 'test regex match test !mv:a*' (string match -q -r $_bang_regex '!mv:a*') $status -ne 0
@test 'test !mv:a*' (_bang '!mv:a*') "$status" -eq 1
Expand Down Expand Up @@ -507,33 +511,33 @@ set output (_bang '!#:s^hello^world^')
@test 'test !#:s^hello^world^' "$output" = 'cd world go sdk world'
demock_commandline

@test 'test regex match !#:s^hello^world' (string match -q -r $_bang_regex '!#:s^hello^world') $status -eq 0
mock_commandline 'cd hello go sdk world !#:s^hello^world'
set output (_bang '!#:s^hello^world')
@test 'test !#:s^hello^world' "$output" = 'cd world go sdk world'
demock_commandline
# @test 'test regex match !#:s^hello^world' (string match -q -r $_bang_regex '!#:s^hello^world') $status -eq 0
# mock_commandline 'cd hello go sdk world !#:s^hello^world'
# set output (_bang '!#:s^hello^world')
# @test 'test !#:s^hello^world' "$output" = 'cd world go sdk world'
# demock_commandline

@test 'test regex match !#:s^hello1^world' (string match -q -r $_bang_regex '!#:s^hello1^world') $status -eq 0
mock_commandline 'cd hello go sdk world !#:s^hello1^world'
set output (_bang '!#:s^hello1^world')
@test 'test !#:s^hello1^world' "$output" = 'cd hello go sdk world'
demock_commandline
# @test 'test regex match !#:s^hello1^world' (string match -q -r $_bang_regex '!#:s^hello1^world') $status -eq 0
# mock_commandline 'cd hello go sdk world !#:s^hello1^world'
# set output (_bang '!#:s^hello1^world')
# @test 'test !#:s^hello1^world' "$output" = 'cd hello go sdk world'
# demock_commandline

@test 'test regex match test ^three^ten^' (string match -q -r $_bang_gsub_regex '^three^ten^') $status -eq 0
set output (_bang '^three^ten^')
@test 'test ^three^ten^' "$output" = 'cd ten four five six seven'

@test 'test regex match test ^three^ten' (string match -q -r $_bang_gsub_regex '^three^ten') $status -eq 0
set output (_bang '^three^ten')
@test 'test ^three^ten' "$output" = 'cd ten four five six seven'
# @test 'test regex match test ^three^ten' (string match -q -r $_bang_gsub_regex '^three^ten') $status -eq 0
# set output (_bang '^three^ten')
# @test 'test ^three^ten' "$output" = 'cd ten four five six seven'

@test 'test regex match test ^three1^ten^' (string match -q -r $_bang_gsub_regex '^three1^ten^') $status -eq 0
set output (_bang '^three1^ten^')
@test 'test ^three1^ten^' "$output" = 'cd three four five six seven'

@test 'test regex match test ^three1^ten' (string match -q -r $_bang_gsub_regex '^three1^ten') $status -eq 0
set output (_bang '^three1^ten')
@test 'test ^three1^ten' "$output" = 'cd three four five six seven'
# @test 'test regex match test ^three1^ten' (string match -q -r $_bang_gsub_regex '^three1^ten') $status -eq 0
# set output (_bang '^three1^ten')
# @test 'test ^three1^ten' "$output" = 'cd three four five six seven'

deinit

Expand Down

0 comments on commit 9b5743d

Please sign in to comment.