Skip to content

Commit

Permalink
Merge pull request #107 from rakitzis/fix-history-slash
Browse files Browse the repository at this point in the history
Fix treatment of slashes (path separator) by history command
  • Loading branch information
rakitzis authored Aug 24, 2024
2 parents 43a03c2 + 48fbbc7 commit 4540368
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ version.h: Makefile .git/index
@echo "CC $@"
$(CC) $(_CPPFLAGS) $(_CFLAGS) -o $@ $<

check: trip
check: trip testhist

trip: rc tripping
./rc -p <"$(srcdir)/trip.rc"

testhist: history
cd "$(srcdir)/test-history" && make

acutest.h:; wget --compression=gzip https://raw.githubusercontent.com/mity/acutest/master/include/acutest.h

test-bestline.o: test-bestline.c edit-bestline.c acutest.h
Expand Down
3 changes: 2 additions & 1 deletion history.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ again: s = last;
for (t = s; *t != '\0'; ++t)
if (*t == me) {
char *u = t - 1;
if (u < s || *u == '/')
goto again;
while (u >= s && (*u == ' ' || *u == '\t'))
--u;
if (u < s)
Expand All @@ -256,7 +258,6 @@ again: s = last;
case '`': case '@':
case '(': case ')':
case '{': case '|':
case '/':
goto again;
default:
break;
Expand Down
40 changes: 40 additions & 0 deletions test-history/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
all: -p --p \
ignore_me.test \
match_me_no_syntax.test \
match_me_slash_whitespace.test \
delete_char.test \
delete_char_stepwise.test \
insert_char.test \
insert_char_skip_tabs.test \
replace_space.test \
append_char.test \
truncate_and_append.test \
skip_match.test

ignore_me.test: force
@cp $(@:.test=) $@
history=$@ ./-p | cmp -n `sed 1q $@ | wc -c` - $@
@rm $@

match_me_no_syntax.test \
match_me_slash_whitespace.test: force
@cp $(@:.test=) $@
history=$@ ./-p > $(@:.test=.out) && sed -n 2p $@ | cmp - $(@:.test=.out)
@rm $@ $(@:.test=.out)

delete_char.test \
delete_char_stepwise.test \
insert_char.test \
insert_char_skip_tabs.test \
replace_space.test \
append_char.test \
truncate_and_append.test \
skip_match.test: force
@cp $(@:.test=) $@
sed -n -e /EOF/q -e 1d -e p $@ | history=$@ ./--p >$(@:.test=.out) 2>/dev/null && sed 1q $@ | cmp - $(@:.test=.out)
@rm $@ $(@:.test=.out)

-p --p: ../history
cp ../history ./$@

force:
5 changes: 5 additions & 0 deletions test-history/append_char
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
append the second the
+ the

EOF
append the second
5 changes: 5 additions & 0 deletions test-history/delete_char
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
delete the second the
####

EOF
delete the the second the
8 changes: 8 additions & 0 deletions test-history/delete_char_stepwise
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
delete the second the
#
#
#
#

EOF
delete the the second the
57 changes: 57 additions & 0 deletions test-history/ignore_me
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
the cases below should all be ignored
-
--
-p
--p
./-
./--
./-p
./--p
-
--
-p
--p
./-
./--
./-p
./--p
{-}
{--}
{-p}
{--p}
{ -}
{ --}
{ -p}
{ --p}
(-)
(--)
(-p)
(--p)
( -)
( --)
( -p)
( --p)
()-
()--
()-p
()--p
@-
@--
@-p
@--p
@ -
@ --
@ -p
@ --p
|-
|--
|-p
|--p
`-
`--
`-p
`--p
` -
` --
` -p
` --p
5 changes: 5 additions & 0 deletions test-history/insert_char
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
insert the first the
^the

EOF
insert first the
5 changes: 5 additions & 0 deletions test-history/insert_char_skip_tabs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
insert after a combination of spaces and tabs near the last position
^near the last

EOF
insert after a combination of spaces and tabs position
2 changes: 2 additions & 0 deletions test-history/match_me_no_syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
this should match
echo -- -n
2 changes: 2 additions & 0 deletions test-history/match_me_slash_whitespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
this should match
find / -- -ls
5 changes: 5 additions & 0 deletions test-history/replace_space
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
replace spaces
%%%

EOF
replace the spaces
9 changes: 9 additions & 0 deletions test-history/skip_match
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
append the second the
-
-
+ the

EOF
append the second
skip this line
skip this line, too
5 changes: 5 additions & 0 deletions test-history/truncate_and_append
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
truncate and append
$ and append

EOF
truncate this old stuff

0 comments on commit 4540368

Please sign in to comment.