2013-12-30 15:20:05 +01:00
|
|
|
#include "completion.hh"
|
|
|
|
#include "file.hh"
|
|
|
|
#include "context.hh"
|
2018-05-26 02:01:26 +02:00
|
|
|
#include "option_types.hh"
|
2016-11-29 00:53:50 +01:00
|
|
|
#include "regex.hh"
|
2013-12-30 15:20:05 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
Completions shell_complete(const Context& context, CompletionFlags flags,
|
2014-04-18 15:02:14 +02:00
|
|
|
StringView prefix, ByteCount cursor_pos)
|
2013-12-30 15:20:05 +01:00
|
|
|
{
|
|
|
|
ByteCount word_start = 0;
|
|
|
|
ByteCount word_end = 0;
|
|
|
|
|
2014-01-03 21:47:49 +01:00
|
|
|
bool command = true;
|
2013-12-30 15:20:05 +01:00
|
|
|
const ByteCount len = prefix.length();
|
2017-10-25 05:26:03 +02:00
|
|
|
for (ByteCount pos = 0; pos < cursor_pos and pos < len;)
|
2013-12-30 15:20:05 +01:00
|
|
|
{
|
2014-01-03 23:28:49 +01:00
|
|
|
command = (pos == 0 or prefix[pos-1] == ';' or prefix[pos-1] == '|' or
|
|
|
|
(pos > 1 and prefix[pos-1] == '&' and prefix[pos-2] == '&'));
|
2015-04-15 01:34:00 +02:00
|
|
|
while (pos != len and is_horizontal_blank(prefix[pos]))
|
2013-12-30 15:20:05 +01:00
|
|
|
++pos;
|
|
|
|
word_start = pos;
|
2015-04-15 01:34:00 +02:00
|
|
|
while (pos != len and not is_horizontal_blank(prefix[pos]))
|
2013-12-30 15:20:05 +01:00
|
|
|
++pos;
|
|
|
|
word_end = pos;
|
|
|
|
}
|
|
|
|
Completions completions{word_start, word_end};
|
2014-01-03 21:47:49 +01:00
|
|
|
if (command)
|
2013-12-30 15:20:05 +01:00
|
|
|
completions.candidates = complete_command(prefix.substr(word_start, word_end),
|
|
|
|
cursor_pos - word_start);
|
|
|
|
else
|
|
|
|
completions.candidates = complete_filename(prefix.substr(word_start, word_end),
|
2015-11-19 16:31:00 +01:00
|
|
|
context.options()["ignored_files"].get<Regex>(),
|
2013-12-30 15:20:05 +01:00
|
|
|
cursor_pos - word_start);
|
|
|
|
return completions;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|