Commit Graph

64 Commits

Author SHA1 Message Date
abhinav
2d114b3c14 PR lib/54510 - when user supplied completion function is there,
don't unescape the string to be completed.
2020-01-05 07:12:05 +00:00
tih
52de8937af Summary: Remove over-simplified extraneous test
The file name matching code in libedit tries to adjust to the presence
of explicit " or ' characters in the input line, but tries too hard.
Remove a conditional that goes overboard, and causes the completion
code to fail if a quoted string is seen before the filename to be
expanded, as in

	  grep 'foo' bar<TAB>

Before this change, the above would not expand any possible
completions, even if they existed, because it would choose to look for
files whose names started with " bar".
2020-01-05 00:03:27 +00:00
christos
5e9cbb1173 When 'attempted_completion_function' non-NULL, with a 'single_match'
match, the expected space is not being added. Problem observed with
"chronyc" and "sqlite3" tab completion. That functionality got
moved to escape_filename() for the !attempted_completion_function
case, but the non-NULL 'attempted_completion_function' case must
also be handled. (Lonnie Abelbeck)
2019-12-10 19:42:09 +00:00
christos
a47ebb18b3 add +1 to strlcpy's (Patrick Welche) 2019-10-09 14:31:07 +00:00
christos
3df2b62655 remore error(1) comment 2019-10-08 19:21:40 +00:00
christos
991f62167b Change strncpy to either memcpy (when we know the len), or strlcpy (when
we used to NUL terminate explicitly.
2019-10-08 19:17:57 +00:00
abhinav
c3d00a7d30 PR lib/54510: Fix file completion inside quotes which broke in rev 1.53
While there also fix handling character appending in the file completions when
inside quotes. For example when inside a quote, if the completion is a directory then
append a '/' but don't close the quote. On the other hand when inside a quote if the
completion is a file name and it is the only match then we can close the quote.
2019-09-08 05:50:58 +00:00
christos
272963ae08 PR/54415: Ricky Zhou: libedit stats completions for non-file completions
Use the proper completion function and account for the character appended
by the function when computing the number of columns.
2019-07-28 09:27:29 +00:00
christos
113f06a345 PR/54399: Sören Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
2019-07-23 10:18:52 +00:00
abhinav
63147cb59c PR lib/54131 - declare the loop variable outside the for loop 2019-04-20 08:44:10 +00:00
christos
7512edc245 PR/54117: Paavo Helde: Fix memory overrun: Account for the closing quote
in memory allocation if quoted.
2019-04-12 15:12:29 +00:00
abhinav
c93cba3ab2 Perform quoting of filename completions when there are multiple matches as well
Quoting of special characters in filename completion was implemented for single match
case, this enables it for multiple matches as well. For example:

$ touch 'foo bar'
$ touch 'foo baz'
$ ls fo<TAB>
autocompletes to =>
$ ls foo\ ba
hitting <TAB> again shows:
foo bar foo baz

This required unescaping escape sequences generated during last completion
in order to find the word to complete.

While there, also update the test to include cases for multiple matches.

Reviewed by christos
2019-03-31 03:04:57 +00:00
abhinav
e09538bda2 Only quote the completion matches if we are doing filename completion
If the user supplies a value for the attempted_completion_function parameter
then we cannot be sure if the completion is for filename or something else, in such
a case don't attempt to quote the completion matches.

Reviewed by christos

This should address PR lib/54067
2019-03-24 16:42:49 +00:00
christos
01f10711d4 fix uninitialized 2018-05-04 20:38:26 +00:00
abhinav
2afc179c8f Handle filename autocompletion when the cursor is at a backslash or quote character
For example, handle following case:
	$ touch 'foo bar'
	$ ls foo\<TAB> --> $ ls foo\ bar

Also add test cases for this.

Thanks to Christos for review
2018-05-04 16:39:14 +00:00
abhinav
b36e4c8fbf Add '*' and '[' to the list of characters which need escaping during autocompletion 2018-05-02 08:45:03 +00:00
abhinav
3c9fe72fbc Add NULL check after doing memory allocation at a couple of places
ok christos@
2017-10-27 18:16:09 +00:00
abhinav
fa61555626 Add support for escaping special characters when doing filename completion.
For instance if the file name is "foo bar":
$ ls foo<TAB>
should get autocompleted to:
$ ls foo\ bar

Works for similar other characters too, which need escaping.

Also, add an accompanying test program to ensure the escaping is correct
in various scenarios (within quotes, without quotes, with other special characeters)

Thanks to Christos for reviews, help and feedback.
2017-10-15 18:59:00 +00:00
abhinav
7a99333ffa Fix indentation (convert spaces to tab) 2017-09-16 20:40:34 +00:00
abhinav
3a89c5769a When doing filename autocompletion, append a trailing slash at the end of directory
names. We already do this when there is only one completion option but
in case of of multiple completion options, it wasn't being done.

ok christos@
2017-04-21 05:38:03 +00:00
abhinav
0551ffcf66 Fix file name auto completion in one specific case.
For example if you do
$mkdir -p /tmp/dir1/dir2

Then:
$ls /tmp/di <TAB> auto completes to
$ls /tmp/dir1/

Hitting <TAB> again auto completes to
$ls /tmp/dir1/dir2

Whereas it should auto complete to
$ls /tmp/dir1/dir2/


Essentially, in cases like above where you have to hit <TAB> twice to get
to the match and there is only one match (because only one file/sub-directory) then
auto complete doesn't work correctly. It doesn't append a trailing slash (in case
of directory) or a space (in case of a file) to the match name.

I have tested file name completion in sh(1) and symbol completion in gdb after
this change.
2016-10-31 17:46:32 +00:00
christos
0594af8028 Char -> wchar_t from Ingo Schwarze. 2016-04-11 00:50:13 +00:00
christos
0aefc7f9ad more macro WIDECHAR undoing from Ingo Schwarze. 2016-04-11 00:22:48 +00:00
christos
2dd09931ab Change some 0's to NULL's from Pedro Giffuni 2016-04-09 18:47:05 +00:00
christos
22383670cc whitespace and header sorting changes (Ingo Schwarze). No functional changes. 2016-02-17 19:47:49 +00:00
christos
e84df91e32 More header cleanups from Ingo Schwarze. 2016-02-16 22:53:14 +00:00
christos
747f681109 more include file cleanup (Ingo Schwarze) 2016-02-16 19:08:41 +00:00
christos
aefc1e4460 From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times.  That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
2016-02-16 15:53:48 +00:00
christos
f09cb8c626 cleanup chartype.h includes (Ingo Schwarze) 2016-02-16 14:08:25 +00:00
christos
40850369f8 cleanup inclusion of histedit.h (Ingo Schwarze) 2016-02-16 14:06:05 +00:00
riz
41482d7745 callers's -> caller's 2014-10-18 15:07:02 +00:00
snj
f0a7346d21 src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
2014-10-18 08:33:23 +00:00
christos
78dc8159da PR/48876: Dmitriy Grigoryev: Core dump in readline lib on attempted expansion
Make sure we have 2 matches before calling strcmp().
2014-06-05 22:07:42 +00:00
plunky
2b8aaed8cd NULL does not need a cast, here 2011-09-16 16:13:16 +00:00
christos
3d802cf59d re-enable -Wconversion 2011-08-16 16:25:15 +00:00
christos
c11bd863f5 pass -Wconversion 2011-07-29 23:44:44 +00:00
christos
1237974a30 - fix unused params
- unconditionalize vis.h
2011-07-29 20:58:07 +00:00
christos
b71bed95b3 KNF return (\1); -> return \1; 2011-07-29 15:16:33 +00:00
christos
a13cd75612 kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations. 2011-07-28 20:50:55 +00:00
christos
56eac9ea53 fix unused variable warnings on systems without _r functions 2011-07-28 17:33:55 +00:00
christos
b210596944 eliminate alloca for portability
portable getpw{nam,uid}
2011-07-28 00:50:23 +00:00
dholland
eb1ab8ee50 Improve previous to avoid changing the interface of an externally
exposed function. (But note that this function is neither documented
nor declared in any installed header file, and it probably should not
be externally exposed.) Related to PR 44183, closes PR 44186.
2010-12-06 00:05:38 +00:00
dholland
574c2fc5a2 add const, from PR 44183. 2010-12-02 04:42:46 +00:00
dholland
92417c82c1 Fix up bodgy code for printing completion matches; it used to sometimes
skip entries, print (null), run off the end of the array, or occasionally
receive SIGSEGV, and now will, hopefully at least, do none of that.

Based in part on the patch in PR 44183 from Sergio Acereda; I also
did some tidyup and fixed it to print top-to-bottom first like ls(1).
2010-12-02 04:35:17 +00:00
christos
a85c37d8d9 don't increment i twice in the loop. From Michael Byrnes 2010-11-15 21:24:31 +00:00
christos
cbd798c94b tidy up memory allocation and don't unnecessarily print "./" before names. 2010-06-01 18:20:26 +00:00
christos
081c24c702 PR/42637: Joachim Kuebart: Shell tab completion crashes due to libedit stack
smashing
2010-01-18 19:17:42 +00:00
christos
34e53048e6 Wide character support (UTF-8) from Johny Mattsson; currently disabled. 2009-12-30 22:37:40 +00:00
christos
b90e7198e7 improve on the listing display by printing only one character after the
filename not two, and no trailing blanks. I will revisit this when I write
the ls-F code.
2009-12-28 21:55:38 +00:00
christos
7939d24e16 fix sign compare issues. 2009-02-16 00:15:45 +00:00