mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 21:35:04 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
9bcd4a6811
|
@ -284,7 +284,7 @@ doc/refman.pdf: doc
|
|||
|
||||
test: $(PROGRAMS) fish_tests
|
||||
./fish_tests
|
||||
cd tests; ../fish <test.fish;
|
||||
cd tests; ../fish -c 'set -x fish_function_path "$$PWD"/../share/functions dummy; source' <test.fish;
|
||||
.PHONY: test
|
||||
|
||||
|
||||
|
|
172
builtin.cpp
172
builtin.cpp
|
@ -1053,6 +1053,87 @@ static int builtin_emit(parser_t &parser, wchar_t **argv)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
Implementation of the builtin 'command'. Actual command running is handled by
|
||||
the parser, this just processes the flags.
|
||||
*/
|
||||
static int builtin_command(parser_t &parser, wchar_t **argv)
|
||||
{
|
||||
int argc=builtin_count_args(argv);
|
||||
int print_path=0;
|
||||
|
||||
woptind=0;
|
||||
|
||||
static const struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{ L"search", no_argument, 0, 's' },
|
||||
{ L"help", no_argument, 0, 'h' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
while (1)
|
||||
{
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = wgetopt_long(argc,
|
||||
argv,
|
||||
L"svh",
|
||||
long_options,
|
||||
&opt_index);
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case 0:
|
||||
if (long_options[opt_index].flag != 0)
|
||||
break;
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
|
||||
case 'h':
|
||||
builtin_print_help(parser, argv[0], stdout_buffer);
|
||||
return STATUS_BUILTIN_OK;
|
||||
|
||||
case 's':
|
||||
case 'v':
|
||||
print_path=1;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!print_path)
|
||||
{
|
||||
builtin_print_help(parser, argv[0], stdout_buffer);
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
int found=0;
|
||||
|
||||
for (int idx = woptind; argv[idx]; ++idx)
|
||||
{
|
||||
const wchar_t *command_name = argv[idx];
|
||||
wcstring path;
|
||||
if (path_get_path(command_name, &path))
|
||||
{
|
||||
append_format(stdout_buffer, L"%ls\n", path.c_str());
|
||||
++found;
|
||||
}
|
||||
}
|
||||
return found ? STATUS_BUILTIN_OK : STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
A generic bultin that only supports showing a help message. This is
|
||||
only a placeholder that prints the help message. Useful for
|
||||
|
@ -2233,6 +2314,7 @@ static int builtin_read(parser_t &parser, wchar_t **argv)
|
|||
int exit_res=STATUS_BUILTIN_OK;
|
||||
const wchar_t *mode_name = READ_MODE_NAME;
|
||||
int shell = 0;
|
||||
int array = 0;
|
||||
|
||||
woptind=0;
|
||||
|
||||
|
@ -2277,6 +2359,10 @@ static int builtin_read(parser_t &parser, wchar_t **argv)
|
|||
L"shell", no_argument, 0, 's'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"array", no_argument, 0, 'a'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"help", no_argument, 0, 'h'
|
||||
}
|
||||
|
@ -2291,7 +2377,7 @@ static int builtin_read(parser_t &parser, wchar_t **argv)
|
|||
|
||||
int opt = wgetopt_long(argc,
|
||||
argv,
|
||||
L"xglUup:c:hm:s",
|
||||
L"xglUup:c:hm:sa",
|
||||
long_options,
|
||||
&opt_index);
|
||||
if (opt == -1)
|
||||
|
@ -2346,6 +2432,10 @@ static int builtin_read(parser_t &parser, wchar_t **argv)
|
|||
shell = 1;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
array = 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
builtin_print_help(parser, argv[0], stdout_buffer);
|
||||
return STATUS_BUILTIN_OK;
|
||||
|
@ -2378,6 +2468,14 @@ static int builtin_read(parser_t &parser, wchar_t **argv)
|
|||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
if (array && woptind+1 != argc)
|
||||
{
|
||||
append_format(stderr_buffer, _(L"%ls: --array option requires a single variable name.\n"), argv[0]);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
Verify all variable names
|
||||
*/
|
||||
|
@ -2512,18 +2610,70 @@ static int builtin_read(parser_t &parser, wchar_t **argv)
|
|||
wchar_t *state;
|
||||
|
||||
env_var_t ifs = env_get_string(L"IFS");
|
||||
if (ifs.missing())
|
||||
ifs = L"";
|
||||
|
||||
nxt = wcstok(buff, (i<argc-1)?ifs.c_str():L"", &state);
|
||||
|
||||
while (i<argc)
|
||||
if (ifs.missing_or_empty())
|
||||
{
|
||||
env_set(argv[i], nxt != 0 ? nxt: L"", place);
|
||||
/* Every character is a separate token */
|
||||
size_t bufflen = wcslen(buff);
|
||||
if (array)
|
||||
{
|
||||
if (bufflen > 0)
|
||||
{
|
||||
wcstring chars(bufflen+(bufflen-1), ARRAY_SEP);
|
||||
for (size_t j=0; j<bufflen; ++j)
|
||||
{
|
||||
chars[j*2] = buff[j];
|
||||
}
|
||||
env_set(argv[i], chars.c_str(), place);
|
||||
}
|
||||
else
|
||||
{
|
||||
env_set(argv[i], NULL, place);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t j = 0;
|
||||
for (; i+1 < argc; ++i)
|
||||
{
|
||||
if (j < bufflen) {
|
||||
wchar_t buffer[2] = {buff[j], 0};
|
||||
env_set(argv[i], buffer, place);
|
||||
}
|
||||
else {
|
||||
env_set(argv[i], L"", place);
|
||||
}
|
||||
if (j < bufflen) ++j;
|
||||
}
|
||||
if (i < argc) env_set(argv[i], &buff[j], place);
|
||||
}
|
||||
}
|
||||
else if (array)
|
||||
{
|
||||
wcstring tokens;
|
||||
tokens.reserve(wcslen(buff));
|
||||
bool empty = true;
|
||||
|
||||
i++;
|
||||
if (nxt != 0)
|
||||
nxt = wcstok(0, (i<argc-1)?ifs.c_str():L"", &state);
|
||||
for (nxt = wcstok(buff, ifs.c_str(), &state); nxt != 0; nxt = wcstok(0, ifs.c_str(), &state))
|
||||
{
|
||||
if (! tokens.empty()) tokens.push_back(ARRAY_SEP);
|
||||
tokens.append(nxt);
|
||||
empty = false;
|
||||
}
|
||||
env_set(argv[i], empty ? NULL : tokens.c_str(), place);
|
||||
}
|
||||
else
|
||||
{
|
||||
nxt = wcstok(buff, (i<argc-1)?ifs.c_str():L"", &state);
|
||||
|
||||
while (i<argc)
|
||||
{
|
||||
env_set(argv[i], nxt != 0 ? nxt: L"", place);
|
||||
|
||||
i++;
|
||||
if (nxt != 0)
|
||||
nxt = wcstok(0, (i<argc-1)?ifs.c_str():L"", &state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3726,7 +3876,7 @@ static const builtin_data_t builtin_datas[]=
|
|||
{ L"builtin", &builtin_builtin, N_(L"Run a builtin command instead of a function") },
|
||||
{ L"case", &builtin_generic, N_(L"Conditionally execute a block of commands") },
|
||||
{ L"cd", &builtin_cd, N_(L"Change working directory") },
|
||||
{ L"command", &builtin_generic, N_(L"Run a program instead of a function or builtin") },
|
||||
{ L"command", &builtin_command, N_(L"Run a program instead of a function or builtin") },
|
||||
{ L"commandline", &builtin_commandline, N_(L"Set or get the commandline") },
|
||||
{ L"complete", &builtin_complete, N_(L"Edit command specific completions") },
|
||||
{ L"contains", &builtin_contains, N_(L"Search for a specified string in a list") },
|
||||
|
|
|
@ -326,7 +326,7 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv)
|
|||
|
||||
int opt = wgetopt_long(argc,
|
||||
argv,
|
||||
L"abijpctwforhI:CLSs",
|
||||
L"abijpctwforhI:CLSsP",
|
||||
long_options,
|
||||
&opt_index);
|
||||
if (opt == -1)
|
||||
|
|
|
@ -166,7 +166,7 @@ static int my_env_set(const wchar_t *key, const wcstring_list_t &val, int scope)
|
|||
|
||||
case ENV_INVALID:
|
||||
{
|
||||
append_format(stderr_buffer, _(L"%ls: Unknown error"), L"set");
|
||||
append_format(stderr_buffer, _(L"%ls: Tried to set the special variable '%ls' to an invalid value\n"), L"set", key);
|
||||
retcode=1;
|
||||
break;
|
||||
}
|
||||
|
|
30
complete.cpp
30
complete.cpp
|
@ -1884,7 +1884,7 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
|
|||
//const wcstring prev_token(prev_begin, prev_token_len);
|
||||
|
||||
parse_node_tree_t tree;
|
||||
parse_tree_from_string(cmd, parse_flag_continue_after_error | parse_flag_accept_incomplete_tokens, &tree, NULL);
|
||||
parse_tree_from_string(cmd, parse_flag_continue_after_error | parse_flag_accept_incomplete_tokens | parse_flag_include_comments, &tree, NULL);
|
||||
|
||||
/* Find any plain statement that contains the position. We have to backtrack past spaces (#1261). So this will be at either the last space character, or after the end of the string */
|
||||
size_t adjusted_pos = pos;
|
||||
|
@ -1896,9 +1896,31 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
|
|||
const parse_node_t *plain_statement = tree.find_node_matching_source_location(symbol_plain_statement, adjusted_pos, NULL);
|
||||
if (plain_statement == NULL)
|
||||
{
|
||||
/* Not part of a plain statement. This could be e.g. a for loop header, case expression, etc. Do generic file completions (#1309). If we had to backtrack, it means there was whitespace; don't do an autosuggestion in that case. */
|
||||
bool no_file = (flags & COMPLETION_REQUEST_AUTOSUGGESTION) && (adjusted_pos < pos);
|
||||
completer.complete_param_expand(current_token, ! no_file);
|
||||
/* Not part of a plain statement. This could be e.g. a for loop header, case expression, etc. Do generic file completions (#1309). If we had to backtrack, it means there was whitespace; don't do an autosuggestion in that case. Also don't do it if we are just after a pipe, semicolon, or & (#1631), or in a comment.
|
||||
|
||||
Overall this logic is a total mess. A better approach would be to return the "possible next token" from the parse tree directly (this data is available as the first of the sequence of nodes without source locations at the very end of the parse tree). */
|
||||
bool do_file = true;
|
||||
if (flags & COMPLETION_REQUEST_AUTOSUGGESTION)
|
||||
{
|
||||
if (adjusted_pos < pos)
|
||||
{
|
||||
do_file = false;
|
||||
}
|
||||
else if (pos > 0)
|
||||
{
|
||||
// If the previous character is in one of these types, we don't do file suggestions
|
||||
parse_token_type_t bad_types[] = {parse_token_type_pipe, parse_token_type_end, parse_token_type_background, parse_special_type_comment};
|
||||
for (size_t i=0; i < sizeof bad_types / sizeof *bad_types; i++)
|
||||
{
|
||||
if (tree.find_node_matching_source_location(bad_types[i], pos - 1, NULL))
|
||||
{
|
||||
do_file = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
completer.complete_param_expand(current_token, do_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
\section command command - run a program
|
||||
|
||||
\subsection command-synopsis Synopsis
|
||||
<tt>command COMMANDNAME [OPTIONS...]</tt>
|
||||
<tt>command [OPTIONS] COMMANDNAME [ARGS...]</tt>
|
||||
|
||||
\subsection command-description Description
|
||||
|
||||
\c command forces the shell to execute the program \c COMMANDNAME and ignore any functions or builtins with the same name.
|
||||
|
||||
\subsection command-example Example
|
||||
The following options are available:
|
||||
- \c -h or \c --help prints help and then exits.
|
||||
- \c -s or \c --search returns the name of the disk file that would be executed, or nothing if no file with the specified name could be found in the <tt>$PATH</tt>.
|
||||
|
||||
With the \c -s option, \c command treats every argument as a separate command to look up and sets the exit status to 0 if any of the specified commands were found, or 1 if no commands could be found.
|
||||
|
||||
For basic compatibility with POSIX <tt>command</tt>, the \c -v flag is recognized as an alias for <tt>-s</tt>.
|
||||
|
||||
\subsection command-example Examples
|
||||
|
||||
<tt>command ls</tt> causes fish to execute the \c ls program, even if an 'ls' function exists.
|
||||
|
||||
<tt>command -s ls</tt> returns the path to the \c ls program.
|
||||
|
|
|
@ -603,7 +603,7 @@ command. If a parameter contains a set of parenthesis, the text enclosed by the
|
|||
parenthesis will be interpreted as a list of commands. On expansion,
|
||||
this list is executed, and substituted by the output. If the output is
|
||||
more than one line long, each line will be expanded to a new
|
||||
parameter.
|
||||
parameter. Setting \c IFS to the empty string will disable line splitting.
|
||||
|
||||
The exit status of the last run command substitution is available in the <a
|
||||
href='#variables-status'>status</a> variable.
|
||||
|
@ -620,6 +620,9 @@ The command <code>for i in *.jpg; convert $i (basename $i .jpg).png;
|
|||
end</code> will convert all JPEG files in the current directory to the
|
||||
PNG format using the \c convert program.
|
||||
|
||||
The command <code>begin; set -l IFS; set data (cat data.txt); end</code>
|
||||
will set the \c data variable to the contents of 'data.txt' without
|
||||
splitting it into an array.
|
||||
|
||||
\subsection expand-brace Brace expansion
|
||||
|
||||
|
@ -1005,10 +1008,11 @@ values of most of these variables.
|
|||
- \c _, the name of the currently running command.
|
||||
- \c argv, an array of arguments to the shell or function. \c argv is only defined when inside a function call, or if fish was invoked with a list of arguments, like 'fish myscript.fish foo bar'. This variable can be changed by the user.
|
||||
- \c history, an array containing the last commands that were entered.
|
||||
- \c HOME, the user's home directory. This variable can only be changed by the root user.
|
||||
- \c HOME, the user's home directory. This variable can be changed by the user.
|
||||
- \c IFS, the internal field separator that is used for word splitting with the <a href="commands.html#read">read builtin</a>. Setting this to the empty string will also disable line splitting in <a href="#expand-command-substitution">command substitution</a>. This variable can be changed by the user.
|
||||
- \c PWD, the current working directory.
|
||||
- \c status, the <a href="#variables-status">exit status</a> of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number.
|
||||
- \c USER, the current username. This variable can only be changed by the root user.
|
||||
- \c USER, the current username. This variable can be changed by the user.
|
||||
- \c CMD_DURATION, the runtime of the last command in milliseconds.
|
||||
|
||||
The names of these variables are mostly derived from the csh family of
|
||||
|
@ -1413,9 +1417,9 @@ directory, or install them in /etc.
|
|||
If you have a question not answered by this documentation, there are
|
||||
several avenues for help:
|
||||
|
||||
-# The official mailing list at <a href='fish-users@lists.sf.net'>fish-users@lists.sf.net</a>
|
||||
-# The official mailing list at <a href='https://lists.sf.net/lists/listinfo/fish-users'>fish-users@lists.sf.net</a>
|
||||
-# The Internet Relay Chat channel, \c #fish on \c irc.oftc.net
|
||||
-# The <a href="http://github.com/fish-shell/fish-shell/">project GitHub page</a>
|
||||
-# The <a href="https://github.com/fish-shell/fish-shell/">project GitHub page</a>
|
||||
|
||||
If you have an improvement for fish, you can submit it via the mailing list
|
||||
or the GitHub page.
|
||||
|
|
|
@ -19,11 +19,17 @@ The following options are available:
|
|||
- <code>-u</code> or <code>--unexport</code> prevents the variables from being exported to child processes (default behaviour).
|
||||
- <code>-U</code> or <code>--universal</code> causes the specified shell variable to be made universal.
|
||||
- <code>-x</code> or <code>--export</code> exports the variables to child processes.
|
||||
- <code>-a</code> or <code>--array</code> stores the result as an array.
|
||||
|
||||
\c read reads a single line of input from stdin, breaks it into tokens
|
||||
based on the <tt>IFS</tt> shell variable, and then assigns one
|
||||
token to each variable specified in <tt>VARIABLES</tt>. If there are more
|
||||
tokens than variables, the complete remainder is assigned to the last variable.
|
||||
As a special case, if \c IFS is set to the empty string, each character of the
|
||||
input is considered a separate token.
|
||||
|
||||
If \c -a or \c --array is provided, only one variable name is allowed and the
|
||||
tokens are stored as an array in this variable.
|
||||
|
||||
See the documentation for \c set for more details on the scoping rules for
|
||||
variables.
|
||||
|
|
|
@ -12,9 +12,10 @@ The following options are available:
|
|||
- \c -h or \c --help prints help and then exits.
|
||||
- \c -a or \c --all prints all of possible definitions of the specified names.
|
||||
- \c -f or \c --no-functions suppresses function and builtin lookup.
|
||||
- \c -t or \c --type prints <tt>keyword</tt>, <tt>function</tt>, <tt>builtin</tt>, or <tt>file</tt> if \c NAME is a shell reserved word, function, builtin, or disk file, respectively.
|
||||
- \c -t or \c --type prints <tt>function</tt>, <tt>builtin</tt>, or <tt>file</tt> if \c NAME is a shell function, builtin, or disk file, respectively.
|
||||
- \c -p or \c --path returns the name of the disk file that would be executed, or nothing if 'type -t name' would not return 'file'.
|
||||
- \c -P or \c --force-path returns the name of the disk file that would be executed, or nothing no file with the specified name could be found in the <tt>$PATH</tt>.
|
||||
- \c -P or \c --force-path returns the name of the disk file that would be executed, or nothing if no file with the specified name could be found in the <tt>$PATH</tt>.
|
||||
- \c -q or \c --quiet suppresses all output; this is useful when testing the exit status.
|
||||
|
||||
\c type sets the exit status to 0 if the specified command was found,
|
||||
and 1 if it could not be found.
|
||||
|
|
6
env.cpp
6
env.cpp
|
@ -655,10 +655,12 @@ int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t var_mode)
|
|||
if (!errno && (!*end) && (mask <= 0777) && (mask >= 0))
|
||||
{
|
||||
umask(mask);
|
||||
/* Do not actually create a umask variable, on env_get, it will be calculated dynamically */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* Do not actually create a umask variable, on env_get, it will be calculated dynamically */
|
||||
return 0;
|
||||
|
||||
return ENV_INVALID;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
2
env.h
2
env.h
|
@ -80,7 +80,7 @@ void env_init(const struct config_paths_t *paths = NULL);
|
|||
|
||||
* ENV_PERM, can only be returned when setting as a user, e.g. ENV_USER is set. This means that the user tried to change a read-only variable.
|
||||
* ENV_SCOPE, the variable cannot be set in the given scope. This applies to readonly/electric variables set from the local or universal scopes, or set as exported.
|
||||
* ENV_INVALID, the variable name or mode was invalid
|
||||
* ENV_INVALID, the variable value was invalid. This applies only to special variables.
|
||||
*/
|
||||
|
||||
int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t mode);
|
||||
|
|
11
exec.cpp
11
exec.cpp
|
@ -1548,16 +1548,7 @@ static int exec_subshell_internal(const wcstring &cmd, wcstring_list_t *lst, boo
|
|||
|
||||
if (! ifs.missing_or_empty())
|
||||
{
|
||||
if (ifs.at(0) < 128)
|
||||
{
|
||||
sep = '\n';//ifs[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
sep = 0;
|
||||
debug(0, L"Warning - invalid command substitution separator '%lc'. Please change the first character of IFS", ifs[0]);
|
||||
}
|
||||
|
||||
sep = '\n';
|
||||
}
|
||||
|
||||
is_subshell=1;
|
||||
|
|
220
expand.cpp
220
expand.cpp
|
@ -953,8 +953,11 @@ void expand_variable_error(parser_t &parser, const wcstring &token, size_t token
|
|||
|
||||
/**
|
||||
Parse an array slicing specification
|
||||
Returns 0 on success.
|
||||
If a parse error occurs, returns the index of the bad token.
|
||||
Note that 0 can never be a bad index because the string always starts with [.
|
||||
*/
|
||||
static int parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &idx, std::vector<size_t> &source_positions, size_t array_size)
|
||||
static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &idx, std::vector<size_t> &source_positions, size_t array_size)
|
||||
{
|
||||
wchar_t *end;
|
||||
|
||||
|
@ -981,7 +984,7 @@ static int parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &
|
|||
tmp = wcstol(&in[pos], &end, 10);
|
||||
if ((errno) || (end == &in[pos]))
|
||||
{
|
||||
return 1;
|
||||
return pos;
|
||||
}
|
||||
// debug( 0, L"Push idx %d", tmp );
|
||||
|
||||
|
@ -999,7 +1002,7 @@ static int parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &
|
|||
long tmp1 = wcstol(&in[pos], &end, 10);
|
||||
if ((errno) || (end == &in[pos]))
|
||||
{
|
||||
return 1;
|
||||
return pos;
|
||||
}
|
||||
pos = end-in;
|
||||
|
||||
|
@ -1046,21 +1049,24 @@ static int parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &
|
|||
fewer string scans and overall just less work. But until that
|
||||
happens, don't edit it unless you know exactly what you are doing,
|
||||
and do proper testing afterwards.
|
||||
|
||||
This function operates on strings backwards, starting at last_idx.
|
||||
*/
|
||||
static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::vector<completion_t> &out, long last_idx, parse_error_list_t *errors);
|
||||
|
||||
static int expand_variables2(parser_t &parser, const wcstring &instr, std::vector<completion_t> &out, long last_idx, parse_error_list_t *errors)
|
||||
static int expand_variables(parser_t &parser, const wcstring &instr, std::vector<completion_t> &out, long last_idx, parse_error_list_t *errors)
|
||||
{
|
||||
wchar_t *in = wcsdup(instr.c_str());
|
||||
int result = expand_variables_internal(parser, in, out, last_idx, errors);
|
||||
free(in);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::vector<completion_t> &out, long last_idx, parse_error_list_t *errors)
|
||||
{
|
||||
int is_ok= 1;
|
||||
int empty=0;
|
||||
// We permit last_idx to be beyond the end of the string if and only if the string is empty
|
||||
assert(instr.empty() || (last_idx >= 0 && (size_t)last_idx < instr.size()));
|
||||
|
||||
// Make this explicit
|
||||
if (instr.empty())
|
||||
{
|
||||
append_completion(out, instr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_ok = true;
|
||||
bool empty = false;
|
||||
const size_t insize = instr.size();
|
||||
|
||||
wcstring var_tmp;
|
||||
|
||||
|
@ -1074,7 +1080,7 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
|
|||
|
||||
for (long i=last_idx; (i>=0) && is_ok && !empty; i--)
|
||||
{
|
||||
const wchar_t c = in[i];
|
||||
const wchar_t c = instr.at(i);
|
||||
if ((c == VARIABLE_EXPAND) || (c == VARIABLE_EXPAND_SINGLE))
|
||||
{
|
||||
long start_pos = i+1;
|
||||
|
@ -1084,12 +1090,15 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
|
|||
|
||||
stop_pos = start_pos;
|
||||
|
||||
while (1)
|
||||
while (stop_pos < insize)
|
||||
{
|
||||
if (!(in[stop_pos ]))
|
||||
const wchar_t nc = instr.at(stop_pos);
|
||||
if (nc == VARIABLE_EXPAND_EMPTY)
|
||||
{
|
||||
stop_pos++;
|
||||
break;
|
||||
if (!(iswalnum(in[stop_pos]) ||
|
||||
(wcschr(L"_", in[stop_pos])!= 0)))
|
||||
}
|
||||
if (!wcsvarchr(nc))
|
||||
break;
|
||||
|
||||
stop_pos++;
|
||||
|
@ -1101,14 +1110,22 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
|
|||
|
||||
if (var_len == 0)
|
||||
{
|
||||
expand_variable_error(parser, in, stop_pos-1, -1, errors);
|
||||
expand_variable_error(parser, instr, stop_pos-1, -1, errors);
|
||||
|
||||
is_ok = 0;
|
||||
is_ok = false;
|
||||
break;
|
||||
}
|
||||
|
||||
var_tmp.append(in + start_pos, var_len);
|
||||
env_var_t var_val = expand_var(var_tmp.c_str());
|
||||
var_tmp.append(instr, start_pos, var_len);
|
||||
env_var_t var_val;
|
||||
if (var_len == 1 && var_tmp[0] == VARIABLE_EXPAND_EMPTY)
|
||||
{
|
||||
var_val = env_var_t::missing_var();
|
||||
}
|
||||
else
|
||||
{
|
||||
var_val = expand_var(var_tmp.c_str());
|
||||
}
|
||||
|
||||
if (! var_val.missing())
|
||||
{
|
||||
|
@ -1117,20 +1134,22 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
|
|||
|
||||
if (is_ok)
|
||||
{
|
||||
tokenize_variable_array(var_val.c_str(), var_item_list);
|
||||
tokenize_variable_array(var_val, var_item_list);
|
||||
|
||||
const size_t slice_start = stop_pos;
|
||||
if (in[slice_start] == L'[')
|
||||
if (slice_start < insize && instr.at(slice_start) == L'[')
|
||||
{
|
||||
wchar_t *slice_end;
|
||||
size_t bad_pos;
|
||||
all_vars=0;
|
||||
|
||||
if (parse_slice(in + slice_start, &slice_end, var_idx_list, var_pos_list, var_item_list.size()))
|
||||
const wchar_t *in = instr.c_str();
|
||||
bad_pos = parse_slice(in + slice_start, &slice_end, var_idx_list, var_pos_list, var_item_list.size());
|
||||
if (bad_pos != 0)
|
||||
{
|
||||
append_syntax_error(errors,
|
||||
stop_pos,
|
||||
stop_pos + bad_pos,
|
||||
L"Invalid index value");
|
||||
is_ok = 0;
|
||||
is_ok = false;
|
||||
break;
|
||||
}
|
||||
stop_pos = (slice_end-in);
|
||||
|
@ -1142,15 +1161,15 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
|
|||
for (size_t j=0; j<var_idx_list.size(); j++)
|
||||
{
|
||||
long tmp = var_idx_list.at(j);
|
||||
size_t var_src_pos = var_pos_list.at(j);
|
||||
/* Check that we are within array bounds. If not, truncate the list to exit. */
|
||||
if (tmp < 1 || (size_t)tmp > var_item_list.size())
|
||||
{
|
||||
size_t var_src_pos = var_pos_list.at(j);
|
||||
/* The slice was parsed starting at stop_pos, so we have to add that to the error position */
|
||||
append_syntax_error(errors,
|
||||
slice_start + var_src_pos,
|
||||
ARRAY_BOUNDS_ERR);
|
||||
is_ok=0;
|
||||
is_ok = false;
|
||||
var_idx_list.resize(j);
|
||||
break;
|
||||
}
|
||||
|
@ -1169,12 +1188,21 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
|
|||
|
||||
if (is_ok)
|
||||
{
|
||||
|
||||
if (is_single)
|
||||
{
|
||||
in[i]=0;
|
||||
wcstring res = in;
|
||||
res.push_back(INTERNAL_SEPARATOR);
|
||||
wcstring res(instr, 0, i);
|
||||
if (i > 0)
|
||||
{
|
||||
if (instr.at(i-1) != VARIABLE_EXPAND_SINGLE)
|
||||
{
|
||||
res.push_back(INTERNAL_SEPARATOR);
|
||||
}
|
||||
else if (var_item_list.empty() || var_item_list.front().empty())
|
||||
{
|
||||
// first expansion is empty, but we need to recursively expand
|
||||
res.push_back(VARIABLE_EXPAND_EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t j=0; j<var_item_list.size(); j++)
|
||||
{
|
||||
|
@ -1186,15 +1214,16 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
|
|||
res.append(next);
|
||||
}
|
||||
}
|
||||
res.append(in + stop_pos);
|
||||
is_ok &= expand_variables2(parser, res, out, i, errors);
|
||||
assert(stop_pos <= insize);
|
||||
res.append(instr, stop_pos, insize - stop_pos);
|
||||
is_ok &= expand_variables(parser, res, out, i, errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t j=0; j<var_item_list.size(); j++)
|
||||
{
|
||||
const wcstring &next = var_item_list.at(j);
|
||||
if (is_ok && (i == 0) && (!in[stop_pos]))
|
||||
if (is_ok && (i == 0) && stop_pos == insize)
|
||||
{
|
||||
append_completion(out, next);
|
||||
}
|
||||
|
@ -1204,18 +1233,23 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
|
|||
if (is_ok)
|
||||
{
|
||||
wcstring new_in;
|
||||
new_in.append(instr, 0, i);
|
||||
|
||||
if (start_pos > 0)
|
||||
new_in.append(in, start_pos - 1);
|
||||
|
||||
// at this point new_in.size() is start_pos - 1
|
||||
if (start_pos>1 && new_in[start_pos-2]!=VARIABLE_EXPAND)
|
||||
if (i > 0)
|
||||
{
|
||||
new_in.push_back(INTERNAL_SEPARATOR);
|
||||
if (instr.at(i-1) != VARIABLE_EXPAND)
|
||||
{
|
||||
new_in.push_back(INTERNAL_SEPARATOR);
|
||||
}
|
||||
else if (next.empty())
|
||||
{
|
||||
new_in.push_back(VARIABLE_EXPAND_EMPTY);
|
||||
}
|
||||
}
|
||||
assert(stop_pos <= insize);
|
||||
new_in.append(next);
|
||||
new_in.append(in + stop_pos);
|
||||
is_ok &= expand_variables2(parser, new_in, out, i, errors);
|
||||
new_in.append(instr, stop_pos, insize - stop_pos);
|
||||
is_ok &= expand_variables(parser, new_in, out, i, errors);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1227,38 +1261,70 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
|
|||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
Expand a non-existing variable
|
||||
*/
|
||||
// even with no value, we still need to parse out slice syntax
|
||||
// Behave as though we had 1 value, so $foo[1] always works.
|
||||
const size_t slice_start = stop_pos;
|
||||
if (slice_start < insize && instr.at(slice_start) == L'[')
|
||||
{
|
||||
const wchar_t *in = instr.c_str();
|
||||
wchar_t *slice_end;
|
||||
size_t bad_pos;
|
||||
|
||||
bad_pos = parse_slice(in + slice_start, &slice_end, var_idx_list, var_pos_list, 1);
|
||||
if (bad_pos != 0)
|
||||
{
|
||||
append_syntax_error(errors,
|
||||
stop_pos + bad_pos,
|
||||
L"Invalid index value");
|
||||
is_ok = 0;
|
||||
return is_ok;
|
||||
}
|
||||
stop_pos = (slice_end-in);
|
||||
|
||||
// validate that the parsed indexes are valid
|
||||
for (size_t j=0; j<var_idx_list.size(); j++)
|
||||
{
|
||||
long tmp = var_idx_list.at(j);
|
||||
if (tmp != 1)
|
||||
{
|
||||
size_t var_src_pos = var_pos_list.at(j);
|
||||
append_syntax_error(errors,
|
||||
slice_start + var_src_pos,
|
||||
ARRAY_BOUNDS_ERR);
|
||||
is_ok = 0;
|
||||
return is_ok;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Expand a non-existing variable */
|
||||
if (c == VARIABLE_EXPAND)
|
||||
{
|
||||
/*
|
||||
Regular expansion, i.e. expand this argument to nothing
|
||||
*/
|
||||
empty = 1;
|
||||
/* Regular expansion, i.e. expand this argument to nothing */
|
||||
empty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
Expansion to single argument.
|
||||
*/
|
||||
/* Expansion to single argument. */
|
||||
wcstring res;
|
||||
in[i] = 0;
|
||||
res.append(in);
|
||||
res.append(in + stop_pos);
|
||||
res.append(instr, 0, i);
|
||||
if (i > 0 && instr.at(i-1) == VARIABLE_EXPAND_SINGLE)
|
||||
{
|
||||
res.push_back(VARIABLE_EXPAND_EMPTY);
|
||||
}
|
||||
assert(stop_pos <= insize);
|
||||
res.append(instr, stop_pos, insize - stop_pos);
|
||||
|
||||
is_ok &= expand_variables2(parser, res, out, i, errors);
|
||||
is_ok &= expand_variables(parser, res, out, i, errors);
|
||||
return is_ok;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty)
|
||||
{
|
||||
append_completion(out, in);
|
||||
append_completion(out, instr);
|
||||
}
|
||||
|
||||
return is_ok;
|
||||
|
@ -1435,11 +1501,14 @@ static int expand_cmdsubst(parser_t &parser, const wcstring &input, std::vector<
|
|||
{
|
||||
std::vector<long> slice_idx;
|
||||
std::vector<size_t> slice_source_positions;
|
||||
const wchar_t * const slice_begin = tail_begin;
|
||||
wchar_t *slice_end;
|
||||
size_t bad_pos;
|
||||
|
||||
if (parse_slice(tail_begin, &slice_end, slice_idx, slice_source_positions, sub_res.size()))
|
||||
bad_pos = parse_slice(slice_begin, &slice_end, slice_idx, slice_source_positions, sub_res.size());
|
||||
if (bad_pos != 0)
|
||||
{
|
||||
append_syntax_error(errors, SOURCE_LOCATION_UNKNOWN, L"Invalid index value");
|
||||
append_syntax_error(errors, slice_begin - in + bad_pos, L"Invalid index value");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
|
@ -1451,8 +1520,9 @@ static int expand_cmdsubst(parser_t &parser, const wcstring &input, std::vector<
|
|||
long idx = slice_idx.at(i);
|
||||
if (idx < 1 || (size_t)idx > sub_res.size())
|
||||
{
|
||||
size_t pos = slice_source_positions.at(i);
|
||||
append_syntax_error(errors,
|
||||
SOURCE_LOCATION_UNKNOWN,
|
||||
slice_begin - in + pos,
|
||||
ARRAY_BOUNDS_ERR);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1739,7 +1809,7 @@ int expand_string(const wcstring &input, std::vector<completion_t> &output, expa
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!expand_variables2(parser, next, *out, next.size() - 1, errors))
|
||||
if (!expand_variables(parser, next, *out, next.size() - 1, errors))
|
||||
{
|
||||
return EXPAND_ERROR;
|
||||
}
|
||||
|
@ -1803,12 +1873,10 @@ int expand_string(const wcstring &input, std::vector<completion_t> &output, expa
|
|||
|
||||
for (i=0; i < in->size(); i++)
|
||||
{
|
||||
wcstring next_str = in->at(i).completion;
|
||||
wcstring next = in->at(i).completion;
|
||||
int wc_res;
|
||||
|
||||
remove_internal_separator(next_str, (EXPAND_SKIP_WILDCARDS & flags) ? true : false);
|
||||
const wchar_t *next = next_str.c_str();
|
||||
|
||||
remove_internal_separator(next, (EXPAND_SKIP_WILDCARDS & flags) ? true : false);
|
||||
const bool has_wildcard = wildcard_has(next, 1);
|
||||
|
||||
if (has_wildcard && (flags & EXECUTABLES_ONLY))
|
||||
|
@ -1818,12 +1886,12 @@ int expand_string(const wcstring &input, std::vector<completion_t> &output, expa
|
|||
else if (((flags & ACCEPT_INCOMPLETE) && (!(flags & EXPAND_SKIP_WILDCARDS))) ||
|
||||
has_wildcard)
|
||||
{
|
||||
const wchar_t *start, *rest;
|
||||
wcstring start, rest;
|
||||
|
||||
if (next[0] == '/')
|
||||
{
|
||||
start = L"/";
|
||||
rest = &next[1];
|
||||
rest = next.substr(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1868,7 +1936,7 @@ int expand_string(const wcstring &input, std::vector<completion_t> &output, expa
|
|||
{
|
||||
if (!(flags & ACCEPT_INCOMPLETE))
|
||||
{
|
||||
append_completion(*out, next_str);
|
||||
append_completion(*out, next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
5
expand.h
5
expand.h
|
@ -102,6 +102,11 @@ enum
|
|||
*/
|
||||
INTERNAL_SEPARATOR,
|
||||
|
||||
/**
|
||||
Character representing an empty variable expansion.
|
||||
Only used transitively while expanding variables.
|
||||
*/
|
||||
VARIABLE_EXPAND_EMPTY,
|
||||
}
|
||||
;
|
||||
|
||||
|
|
158
fish_tests.cpp
158
fish_tests.cpp
|
@ -1341,6 +1341,11 @@ static int expand_test(const wchar_t *in, int flags, ...)
|
|||
i++;
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if (output.size() != i)
|
||||
{
|
||||
res = false;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
|
@ -1367,6 +1372,11 @@ static void test_expand()
|
|||
{
|
||||
err(L"Cannot skip wildcard expansion");
|
||||
}
|
||||
|
||||
if (!expand_test(L"/bin/l\\0", ACCEPT_INCOMPLETE, 0))
|
||||
{
|
||||
err(L"Failed to handle null escape in expansion");
|
||||
}
|
||||
|
||||
if (system("mkdir -p /tmp/fish_expand_test/")) err(L"mkdir failed");
|
||||
if (system("touch /tmp/fish_expand_test/.foo")) err(L"touch failed");
|
||||
|
@ -1858,6 +1868,7 @@ static void test_colors()
|
|||
static void test_complete(void)
|
||||
{
|
||||
say(L"Testing complete");
|
||||
|
||||
const wchar_t *name_strs[] = {L"Foo1", L"Foo2", L"Foo3", L"Bar1", L"Bar2", L"Bar3"};
|
||||
size_t count = sizeof name_strs / sizeof *name_strs;
|
||||
const wcstring_list_t names(name_strs, name_strs + count);
|
||||
|
@ -1937,7 +1948,47 @@ static void test_complete(void)
|
|||
completions.clear();
|
||||
complete(L"echo \\$Foo", completions, COMPLETION_REQUEST_DEFAULT);
|
||||
do_test(completions.empty());
|
||||
|
||||
/* File completions */
|
||||
char saved_wd[PATH_MAX + 1] = {};
|
||||
getcwd(saved_wd, sizeof saved_wd);
|
||||
if (system("mkdir -p '/tmp/complete_test/'")) err(L"mkdir failed");
|
||||
if (system("touch '/tmp/complete_test/testfile'")) err(L"touch failed");
|
||||
if (chdir("/tmp/complete_test/")) err(L"chdir failed");
|
||||
complete(L"cat te", completions, COMPLETION_REQUEST_DEFAULT);
|
||||
do_test(completions.size() == 1);
|
||||
do_test(completions.at(0).completion == L"stfile");
|
||||
completions.clear();
|
||||
complete(L"cat /tmp/complete_test/te", completions, COMPLETION_REQUEST_DEFAULT);
|
||||
do_test(completions.size() == 1);
|
||||
do_test(completions.at(0).completion == L"stfile");
|
||||
completions.clear();
|
||||
complete(L"echo sup > /tmp/complete_test/te", completions, COMPLETION_REQUEST_DEFAULT);
|
||||
do_test(completions.size() == 1);
|
||||
do_test(completions.at(0).completion == L"stfile");
|
||||
completions.clear();
|
||||
complete(L"echo sup > /tmp/complete_test/te", completions, COMPLETION_REQUEST_DEFAULT);
|
||||
do_test(completions.size() == 1);
|
||||
do_test(completions.at(0).completion == L"stfile");
|
||||
completions.clear();
|
||||
|
||||
// Zero escapes can cause problems. See #1631
|
||||
complete(L"cat foo\\0", completions, COMPLETION_REQUEST_DEFAULT);
|
||||
do_test(completions.empty());
|
||||
completions.clear();
|
||||
complete(L"cat foo\\0bar", completions, COMPLETION_REQUEST_DEFAULT);
|
||||
do_test(completions.empty());
|
||||
completions.clear();
|
||||
complete(L"cat \\0", completions, COMPLETION_REQUEST_DEFAULT);
|
||||
do_test(completions.empty());
|
||||
completions.clear();
|
||||
complete(L"cat te\\0", completions, COMPLETION_REQUEST_DEFAULT);
|
||||
do_test(completions.empty());
|
||||
completions.clear();
|
||||
|
||||
if (chdir(saved_wd)) err(L"chdir failed");
|
||||
if (system("rm -Rf '/tmp/complete_test/'")) err(L"rm failed");
|
||||
|
||||
complete_set_variable_names(NULL);
|
||||
|
||||
/* Test wraps */
|
||||
|
@ -2004,7 +2055,7 @@ static void test_completion_insertions()
|
|||
TEST_1_COMPLETION(L"'foo^", L"bar", COMPLETE_REPLACES_TOKEN, false, L"bar ^");
|
||||
}
|
||||
|
||||
static void perform_one_autosuggestion_test(const wcstring &command, const wcstring &wd, const wcstring &expected, long line)
|
||||
static void perform_one_autosuggestion_special_test(const wcstring &command, const wcstring &wd, const wcstring &expected, long line)
|
||||
{
|
||||
wcstring suggestion;
|
||||
bool success = autosuggest_suggest_special(command, wd, suggestion);
|
||||
|
@ -2034,57 +2085,81 @@ static void test_autosuggest_suggest_special()
|
|||
if (system("mkdir -p ~/test_autosuggest_suggest_special/")) err(L"mkdir failed"); //make sure tilde is handled
|
||||
|
||||
const wcstring wd = L"/tmp/autosuggest_test/";
|
||||
perform_one_autosuggestion_test(L"cd /tmp/autosuggest_test/0", wd, L"cd /tmp/autosuggest_test/0foobar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"/tmp/autosuggest_test/0", wd, L"cd \"/tmp/autosuggest_test/0foobar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '/tmp/autosuggest_test/0", wd, L"cd '/tmp/autosuggest_test/0foobar/'", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd 0", wd, L"cd 0foobar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"0", wd, L"cd \"0foobar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '0", wd, L"cd '0foobar/'", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd /tmp/autosuggest_test/0", wd, L"cd /tmp/autosuggest_test/0foobar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"/tmp/autosuggest_test/0", wd, L"cd \"/tmp/autosuggest_test/0foobar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '/tmp/autosuggest_test/0", wd, L"cd '/tmp/autosuggest_test/0foobar/'", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd 0", wd, L"cd 0foobar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"0", wd, L"cd \"0foobar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '0", wd, L"cd '0foobar/'", __LINE__);
|
||||
|
||||
perform_one_autosuggestion_test(L"cd /tmp/autosuggest_test/1", wd, L"cd /tmp/autosuggest_test/1foo\\ bar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"/tmp/autosuggest_test/1", wd, L"cd \"/tmp/autosuggest_test/1foo bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '/tmp/autosuggest_test/1", wd, L"cd '/tmp/autosuggest_test/1foo bar/'", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd 1", wd, L"cd 1foo\\ bar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"1", wd, L"cd \"1foo bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '1", wd, L"cd '1foo bar/'", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd /tmp/autosuggest_test/1", wd, L"cd /tmp/autosuggest_test/1foo\\ bar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"/tmp/autosuggest_test/1", wd, L"cd \"/tmp/autosuggest_test/1foo bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '/tmp/autosuggest_test/1", wd, L"cd '/tmp/autosuggest_test/1foo bar/'", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd 1", wd, L"cd 1foo\\ bar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"1", wd, L"cd \"1foo bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '1", wd, L"cd '1foo bar/'", __LINE__);
|
||||
|
||||
perform_one_autosuggestion_test(L"cd /tmp/autosuggest_test/2", wd, L"cd /tmp/autosuggest_test/2foo\\ \\ bar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"/tmp/autosuggest_test/2", wd, L"cd \"/tmp/autosuggest_test/2foo bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '/tmp/autosuggest_test/2", wd, L"cd '/tmp/autosuggest_test/2foo bar/'", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd 2", wd, L"cd 2foo\\ \\ bar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"2", wd, L"cd \"2foo bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '2", wd, L"cd '2foo bar/'", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd /tmp/autosuggest_test/2", wd, L"cd /tmp/autosuggest_test/2foo\\ \\ bar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"/tmp/autosuggest_test/2", wd, L"cd \"/tmp/autosuggest_test/2foo bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '/tmp/autosuggest_test/2", wd, L"cd '/tmp/autosuggest_test/2foo bar/'", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd 2", wd, L"cd 2foo\\ \\ bar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"2", wd, L"cd \"2foo bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '2", wd, L"cd '2foo bar/'", __LINE__);
|
||||
|
||||
perform_one_autosuggestion_test(L"cd /tmp/autosuggest_test/3", wd, L"cd /tmp/autosuggest_test/3foo\\\\bar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"/tmp/autosuggest_test/3", wd, L"cd \"/tmp/autosuggest_test/3foo\\bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '/tmp/autosuggest_test/3", wd, L"cd '/tmp/autosuggest_test/3foo\\bar/'", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd 3", wd, L"cd 3foo\\\\bar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"3", wd, L"cd \"3foo\\bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '3", wd, L"cd '3foo\\bar/'", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd /tmp/autosuggest_test/3", wd, L"cd /tmp/autosuggest_test/3foo\\\\bar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"/tmp/autosuggest_test/3", wd, L"cd \"/tmp/autosuggest_test/3foo\\bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '/tmp/autosuggest_test/3", wd, L"cd '/tmp/autosuggest_test/3foo\\bar/'", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd 3", wd, L"cd 3foo\\\\bar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"3", wd, L"cd \"3foo\\bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '3", wd, L"cd '3foo\\bar/'", __LINE__);
|
||||
|
||||
perform_one_autosuggestion_test(L"cd /tmp/autosuggest_test/4", wd, L"cd /tmp/autosuggest_test/4foo\\'bar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"/tmp/autosuggest_test/4", wd, L"cd \"/tmp/autosuggest_test/4foo'bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '/tmp/autosuggest_test/4", wd, L"cd '/tmp/autosuggest_test/4foo\\'bar/'", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd 4", wd, L"cd 4foo\\'bar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"4", wd, L"cd \"4foo'bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '4", wd, L"cd '4foo\\'bar/'", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd /tmp/autosuggest_test/4", wd, L"cd /tmp/autosuggest_test/4foo\\'bar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"/tmp/autosuggest_test/4", wd, L"cd \"/tmp/autosuggest_test/4foo'bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '/tmp/autosuggest_test/4", wd, L"cd '/tmp/autosuggest_test/4foo\\'bar/'", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd 4", wd, L"cd 4foo\\'bar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"4", wd, L"cd \"4foo'bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '4", wd, L"cd '4foo\\'bar/'", __LINE__);
|
||||
|
||||
perform_one_autosuggestion_test(L"cd /tmp/autosuggest_test/5", wd, L"cd /tmp/autosuggest_test/5foo\\\"bar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"/tmp/autosuggest_test/5", wd, L"cd \"/tmp/autosuggest_test/5foo\\\"bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '/tmp/autosuggest_test/5", wd, L"cd '/tmp/autosuggest_test/5foo\"bar/'", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd 5", wd, L"cd 5foo\\\"bar/", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd \"5", wd, L"cd \"5foo\\\"bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_test(L"cd '5", wd, L"cd '5foo\"bar/'", __LINE__);
|
||||
|
||||
perform_one_autosuggestion_test(L"cd ~/test_autosuggest_suggest_specia", wd, L"cd ~/test_autosuggest_suggest_special/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd /tmp/autosuggest_test/5", wd, L"cd /tmp/autosuggest_test/5foo\\\"bar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"/tmp/autosuggest_test/5", wd, L"cd \"/tmp/autosuggest_test/5foo\\\"bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '/tmp/autosuggest_test/5", wd, L"cd '/tmp/autosuggest_test/5foo\"bar/'", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd 5", wd, L"cd 5foo\\\"bar/", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd \"5", wd, L"cd \"5foo\\\"bar/\"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '5", wd, L"cd '5foo\"bar/'", __LINE__);
|
||||
|
||||
perform_one_autosuggestion_special_test(L"cd ~/test_autosuggest_suggest_specia", wd, L"cd ~/test_autosuggest_suggest_special/", __LINE__);
|
||||
|
||||
// A single quote should defeat tilde expansion
|
||||
perform_one_autosuggestion_test(L"cd '~/test_autosuggest_suggest_specia'", wd, L"", __LINE__);
|
||||
perform_one_autosuggestion_special_test(L"cd '~/test_autosuggest_suggest_specia'", wd, L"", __LINE__);
|
||||
|
||||
if (system("rm -Rf '/tmp/autosuggest_test/'")) err(L"rm failed");
|
||||
if (system("rm -Rf ~/test_autosuggest_suggest_special/")) err(L"rm failed");
|
||||
}
|
||||
|
||||
static void perform_one_autosuggestion_should_ignore_test(const wcstring &command, const wcstring &wd, long line)
|
||||
{
|
||||
completion_list_t comps;
|
||||
complete(command, comps, COMPLETION_REQUEST_AUTOSUGGESTION);
|
||||
do_test(comps.empty());
|
||||
if (! comps.empty())
|
||||
{
|
||||
const wcstring &suggestion = comps.front().completion;
|
||||
printf("line %ld: complete() expected to return nothing for %ls\n", line, command.c_str());
|
||||
printf(" instead got: %ls\n", suggestion.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static void test_autosuggestion_ignores()
|
||||
{
|
||||
say(L"Testing scenarios that should produce no autosuggestions");
|
||||
const wcstring wd = L"/tmp/autosuggest_test/";
|
||||
// Do not do file autosuggestions immediately after certain statement terminators - see #1631
|
||||
perform_one_autosuggestion_should_ignore_test(L"echo PIPE_TEST|", wd, __LINE__);
|
||||
perform_one_autosuggestion_should_ignore_test(L"echo PIPE_TEST&", wd, __LINE__);
|
||||
perform_one_autosuggestion_should_ignore_test(L"echo PIPE_TEST#comment", wd, __LINE__);
|
||||
perform_one_autosuggestion_should_ignore_test(L"echo PIPE_TEST;", wd, __LINE__);
|
||||
}
|
||||
|
||||
static void test_autosuggestion_combining()
|
||||
{
|
||||
say(L"Testing autosuggestion combining");
|
||||
|
@ -3404,6 +3479,8 @@ static void test_highlighting(void)
|
|||
{L"ls", highlight_spec_command},
|
||||
{L"param2", highlight_spec_param},
|
||||
{L")", highlight_spec_operator},
|
||||
{L"|", highlight_spec_statement_terminator},
|
||||
{L"cat", highlight_spec_command},
|
||||
{NULL, -1}
|
||||
};
|
||||
|
||||
|
@ -3629,6 +3706,7 @@ int main(int argc, char **argv)
|
|||
if (should_test_function("universal")) test_universal_callbacks();
|
||||
if (should_test_function("notifiers")) test_universal_notifiers();
|
||||
if (should_test_function("completion_insertions")) test_completion_insertions();
|
||||
if (should_test_function("autosuggestion_ignores")) test_autosuggestion_ignores();
|
||||
if (should_test_function("autosuggestion_combining")) test_autosuggestion_combining();
|
||||
if (should_test_function("autosuggest_suggest_special")) test_autosuggest_suggest_special();
|
||||
if (should_test_function("history")) history_tests_t::test_history();
|
||||
|
|
|
@ -617,12 +617,26 @@ static size_t color_variable(const wchar_t *in, size_t in_len, std::vector<highl
|
|||
if (in[idx] == L'[')
|
||||
{
|
||||
wchar_t *slice_begin = NULL, *slice_end = NULL;
|
||||
if (1 == parse_util_locate_slice(in, &slice_begin, &slice_end, false))
|
||||
switch (parse_util_locate_slice(in, &slice_begin, &slice_end, false))
|
||||
{
|
||||
size_t slice_begin_idx = slice_begin - in, slice_end_idx = slice_end - in;
|
||||
assert(slice_end_idx > slice_begin_idx);
|
||||
colors[slice_begin_idx] = highlight_spec_operator;
|
||||
colors[slice_end_idx] = highlight_spec_operator;
|
||||
case 1:
|
||||
{
|
||||
size_t slice_begin_idx = slice_begin - in, slice_end_idx = slice_end - in;
|
||||
assert(slice_end_idx > slice_begin_idx);
|
||||
colors[slice_begin_idx] = highlight_spec_operator;
|
||||
colors[slice_end_idx] = highlight_spec_operator;
|
||||
break;
|
||||
}
|
||||
case -1:
|
||||
{
|
||||
// syntax error
|
||||
// Normally the entire token is colored red for us, but inside a double-quoted string
|
||||
// that doesn't happen. As such, color the variable + the slice start red. Coloring any
|
||||
// more than that looks bad, unless we're willing to try and detect where the double-quoted
|
||||
// string ends, and I'd rather not do that.
|
||||
std::fill(colors, colors + idx + 1, (highlight_spec_t)highlight_spec_error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return idx;
|
||||
|
@ -861,7 +875,11 @@ static void color_argument_internal(const wcstring &buffstr, std::vector<highlig
|
|||
*/
|
||||
case e_double_quoted:
|
||||
{
|
||||
colors[in_pos] = highlight_spec_quote;
|
||||
// slices are colored in advance, past `in_pos`, and we don't want to overwrite that
|
||||
if (colors[in_pos] == highlight_spec_param)
|
||||
{
|
||||
colors[in_pos] = highlight_spec_quote;
|
||||
}
|
||||
switch (c)
|
||||
{
|
||||
case L'"':
|
||||
|
@ -876,7 +894,7 @@ static void color_argument_internal(const wcstring &buffstr, std::vector<highlig
|
|||
if (in_pos + 1 < buff_len)
|
||||
{
|
||||
const wchar_t escaped_char = buffstr.at(in_pos + 1);
|
||||
if (escaped_char == L'\\' || escaped_char == L'\'' || escaped_char == L'$')
|
||||
if (wcschr(L"\\\"\n$", escaped_char))
|
||||
{
|
||||
colors[in_pos] = highlight_spec_escape; //backslash
|
||||
colors[in_pos + 1] = highlight_spec_escape; //escaped char
|
||||
|
@ -1358,6 +1376,7 @@ const highlighter_t::color_array_t & highlighter_t::highlight()
|
|||
}
|
||||
break;
|
||||
|
||||
case parse_token_type_pipe:
|
||||
case parse_token_type_background:
|
||||
case parse_token_type_end:
|
||||
case symbol_optional_background:
|
||||
|
|
|
@ -47,7 +47,7 @@ if not set -q fish_function_path
|
|||
end
|
||||
|
||||
if not contains $__fish_datadir/functions $fish_function_path
|
||||
set fish_function_path[-1] $__fish_datadir/functions
|
||||
set fish_function_path $fish_function_path $__fish_datadir/functions
|
||||
end
|
||||
|
||||
if not set -q fish_complete_path
|
||||
|
@ -55,7 +55,7 @@ if not set -q fish_complete_path
|
|||
end
|
||||
|
||||
if not contains $__fish_datadir/completions $fish_complete_path
|
||||
set fish_complete_path[-1] $__fish_datadir/completions
|
||||
set fish_complete_path $fish_complete_path $__fish_datadir/completions
|
||||
end
|
||||
|
||||
#
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function __fish_complete_cabal
|
||||
if type -f cabal >/dev/null
|
||||
if type -q -f cabal
|
||||
set cmd (commandline -poc)
|
||||
if test (count $cmd) -gt 1
|
||||
cabal $cmd[2..-1] --list-options
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
function __fish_complete_vi -d "Compleletions for vi and its aliases" --argument-names cmd
|
||||
set -l is_vim
|
||||
if type $cmd > /dev/null
|
||||
if type -q $cmd
|
||||
eval command $cmd --version >/dev/null ^/dev/null; and set -l is_vim vim
|
||||
end
|
||||
|
||||
|
|
|
@ -248,7 +248,7 @@ function __fish_config_interactive -d "Initializations that should be performed
|
|||
# First check if we are on OpenSUSE since SUSE's handler has no options
|
||||
# and expects first argument to be a command and second database
|
||||
# also check if there is command-not-found command.
|
||||
if begin; test -f /etc/SuSE-release; and type -p command-not-found > /dev/null 2> /dev/null; end
|
||||
if begin; test -f /etc/SuSE-release; and type -q -p command-not-found; end
|
||||
function __fish_command_not_found_handler --on-event fish_command_not_found
|
||||
/usr/bin/command-not-found $argv
|
||||
end
|
||||
|
@ -263,7 +263,7 @@ function __fish_config_interactive -d "Initializations that should be performed
|
|||
/usr/lib/command-not-found -- $argv
|
||||
end
|
||||
# Ubuntu Feisty places this command in the regular path instead
|
||||
else if type -p command-not-found > /dev/null 2> /dev/null
|
||||
else if type -q -p command-not-found
|
||||
function __fish_command_not_found_handler --on-event fish_command_not_found
|
||||
command-not-found -- $argv
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ function __fish_print_packages
|
|||
end
|
||||
mkdir -m 700 -p $XDG_CACHE_HOME
|
||||
|
||||
if type -f apt-cache >/dev/null
|
||||
if type -q -f apt-cache
|
||||
# Do not generate the cache as apparently sometimes this is slow.
|
||||
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=547550
|
||||
apt-cache --no-generate pkgnames (commandline -tc) ^/dev/null | sed -e 's/$/'\t$package'/'
|
||||
|
@ -28,7 +28,7 @@ function __fish_print_packages
|
|||
# Pkg is fast on FreeBSD and provides versioning info which we want for
|
||||
# installed packages
|
||||
if begin
|
||||
type -f pkg > /dev/null
|
||||
type -q -f pkg
|
||||
and test (uname) = "FreeBSD"
|
||||
end
|
||||
pkg query "%n-%v"
|
||||
|
@ -36,7 +36,7 @@ function __fish_print_packages
|
|||
end
|
||||
|
||||
# Caches for 5 minutes
|
||||
if type -f pacman >/dev/null
|
||||
if type -q -f pacman
|
||||
set cache_file $XDG_CACHE_HOME/.pac-cache.$USER
|
||||
if test -f $cache_file
|
||||
cat $cache_file
|
||||
|
@ -53,7 +53,7 @@ function __fish_print_packages
|
|||
end
|
||||
|
||||
# yum is slow, just like rpm, so go to the background
|
||||
if type -f /usr/share/yum-cli/completion-helper.py >/dev/null
|
||||
if type -q -f /usr/share/yum-cli/completion-helper.py
|
||||
|
||||
# If the cache is less than six hours old, we do not recalculate it
|
||||
|
||||
|
@ -75,7 +75,7 @@ function __fish_print_packages
|
|||
# Rpm is too slow for this job, so we set it up to do completions
|
||||
# as a background job and cache the results.
|
||||
|
||||
if type -f rpm >/dev/null
|
||||
if type -q -f rpm
|
||||
|
||||
# If the cache is less than five minutes old, we do not recalculate it
|
||||
|
||||
|
@ -99,12 +99,12 @@ function __fish_print_packages
|
|||
# installed on the system packages is in completions/emerge.fish
|
||||
|
||||
# eix is MUCH faster than emerge so use it if it is available
|
||||
if type -f eix > /dev/null
|
||||
if type -q -f eix
|
||||
eix --only-names "^"(commandline -tc) | cut -d/ -f2
|
||||
return
|
||||
else
|
||||
# FIXME? Seems to be broken
|
||||
if type -f emerge >/dev/null
|
||||
if type -q -f emerge
|
||||
emerge -s \^(commandline -tc) |sgrep "^*" |cut -d\ -f3 |cut -d/ -f2
|
||||
return
|
||||
end
|
||||
|
|
|
@ -12,6 +12,7 @@ function alias --description "Legacy function for creating shellscript functions
|
|||
set -l name
|
||||
set -l body
|
||||
set -l prefix
|
||||
set -l first_word
|
||||
switch (count $argv)
|
||||
|
||||
case 0
|
||||
|
@ -21,8 +22,9 @@ function alias --description "Legacy function for creating shellscript functions
|
|||
# Some seds (e.g. on Mac OS X), don't support \n in the RHS
|
||||
# Use a literal newline instead
|
||||
# http://sed.sourceforge.net/sedfaq4.html#s4.1
|
||||
set -l tmp (echo $argv|sed -e "s/\([^=]\)=/\1\\
|
||||
/")
|
||||
# The extra '' at the end is so $tmp[2] is guaranteed to work
|
||||
set -l tmp (echo $argv|sed -e 's/\([^=]\{0,1\}\)=/\1\
|
||||
/') ''
|
||||
set name $tmp[1]
|
||||
set body $tmp[2]
|
||||
|
||||
|
@ -35,18 +37,34 @@ function alias --description "Legacy function for creating shellscript functions
|
|||
return 1
|
||||
end
|
||||
|
||||
# sanity check
|
||||
if test -z "$name"
|
||||
printf ( _ "%s: Name cannot be empty\n") alias
|
||||
return 1
|
||||
else if test -z "$body"
|
||||
printf ( _ "%s: Body cannot be empty\n") alias
|
||||
return 1
|
||||
end
|
||||
|
||||
# Extract the first command from the body
|
||||
switch $body
|
||||
case \*\ \* \*\t\*
|
||||
# note: strip leading spaces if present
|
||||
set first_word (echo $body|sed -e 's/^[[:space:]]\{1,\}//;s/[[:space:]].*//;q')
|
||||
case '*'
|
||||
set first_word $body
|
||||
end
|
||||
|
||||
# Prevent the alias from immediately running into an infinite recursion if
|
||||
# $body starts with the same command as $name.
|
||||
|
||||
switch $body
|
||||
case $name $name\ \* $name\t\*
|
||||
if contains $name (builtin --names)
|
||||
set prefix builtin
|
||||
else
|
||||
set prefix command
|
||||
end
|
||||
if test $first_word = $name
|
||||
if contains $name (builtin --names)
|
||||
set prefix builtin
|
||||
else
|
||||
set prefix command
|
||||
end
|
||||
end
|
||||
|
||||
eval "function $name --wraps $body; $prefix $body \$argv; end"
|
||||
eval "function $name --wraps $first_word; $prefix $body \$argv; end"
|
||||
end
|
||||
|
|
|
@ -51,7 +51,7 @@ function funced --description 'Edit function definition'
|
|||
if test -n "$editor"
|
||||
set -l editor_cmd
|
||||
eval set editor_cmd $editor
|
||||
if not type -f "$editor_cmd[1]" >/dev/null
|
||||
if not type -q -f "$editor_cmd[1]"
|
||||
_ "funced: The value for \$EDITOR '$editor' could not be used because the command '$editor_cmd[1]' could not be found
|
||||
"
|
||||
set editor fish
|
||||
|
|
|
@ -25,7 +25,7 @@ function help --description 'Show help for the fish shell'
|
|||
set -l graphical_browsers htmlview x-www-browser firefox galeon mozilla konqueror epiphany opera netscape rekonq google-chrome chromium-browser
|
||||
set -l text_browsers htmlview www-browser links elinks lynx w3m
|
||||
|
||||
if type "$BROWSER" >/dev/null
|
||||
if type -q "$BROWSER"
|
||||
# User has manually set a preferred browser, so we respect that
|
||||
set fish_browser $BROWSER
|
||||
|
||||
|
@ -36,7 +36,7 @@ function help --description 'Show help for the fish shell'
|
|||
else
|
||||
# Check for a text-based browser.
|
||||
for i in $text_browsers
|
||||
if type -f $i >/dev/null
|
||||
if type -q -f $i
|
||||
set fish_browser $i
|
||||
break
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ function help --description 'Show help for the fish shell'
|
|||
# browser to use instead.
|
||||
if test "$DISPLAY" -a \( "$XAUTHORITY" = "$HOME/.Xauthority" -o "$XAUTHORITY" = "" \)
|
||||
for i in $graphical_browsers
|
||||
if type -f $i >/dev/null
|
||||
if type -q -f $i
|
||||
set fish_browser $i
|
||||
set fish_browser_bg 1
|
||||
break
|
||||
|
@ -55,17 +55,17 @@ function help --description 'Show help for the fish shell'
|
|||
end
|
||||
|
||||
# If the OS appears to be Windows (graphical), try to use cygstart
|
||||
if type cygstart > /dev/null
|
||||
if type -q cygstart
|
||||
set fish_browser cygstart
|
||||
# If xdg-open is available, just use that
|
||||
else if type xdg-open > /dev/null
|
||||
else if type -q xdg-open
|
||||
set fish_browser xdg-open
|
||||
end
|
||||
|
||||
|
||||
# On OS X, we go through osascript by default
|
||||
if test (uname) = Darwin
|
||||
if type osascript >/dev/null
|
||||
if type -q osascript
|
||||
set fish_browser osascript
|
||||
end
|
||||
end
|
||||
|
@ -92,7 +92,7 @@ function help --description 'Show help for the fish shell'
|
|||
case $help_topics
|
||||
set fish_help_page "index.html\#$fish_help_item"
|
||||
case "*"
|
||||
if type -f $fish_help_item >/dev/null
|
||||
if type -q -f $fish_help_item
|
||||
# Prefer to use fish's man pages, to avoid
|
||||
# the annoying useless "builtin" man page bash
|
||||
# installs on OS X
|
||||
|
|
|
@ -13,7 +13,7 @@ if command ls --version 1>/dev/null 2>/dev/null
|
|||
end
|
||||
|
||||
if not set -q LS_COLORS
|
||||
if type -f dircolors >/dev/null
|
||||
if type -q -f dircolors
|
||||
eval (dircolors -c | sed 's/>&\/dev\/null$//')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,11 +14,11 @@ if not test (uname) = Darwin
|
|||
end
|
||||
end
|
||||
|
||||
if type -f cygstart >/dev/null
|
||||
if type -q -f cygstart
|
||||
for i in $argv
|
||||
cygstart $i
|
||||
end
|
||||
else if type -f xdg-open >/dev/null
|
||||
else if type -q -f xdg-open
|
||||
for i in $argv
|
||||
xdg-open $i
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# test -x in /usr/bin/seq because that's where it usually is and
|
||||
# that's substantially cheaper than the type function
|
||||
|
||||
if begin ; not test -x /usr/bin/seq ; and not type -f seq > /dev/null; end
|
||||
if begin ; not test -x /usr/bin/seq ; and not type -q -f seq; end
|
||||
# No seq command
|
||||
function seq --description "Print sequences of numbers"
|
||||
__fish_fallback_seq $argv
|
||||
|
|
|
@ -4,79 +4,84 @@ function type --description "Print the type of a command"
|
|||
# Initialize
|
||||
set -l res 1
|
||||
set -l mode normal
|
||||
set -l multi no
|
||||
set -l selection all
|
||||
|
||||
#
|
||||
# Get options
|
||||
#
|
||||
set -l options
|
||||
set -l shortopt tpPafh
|
||||
if not getopt -T > /dev/null
|
||||
# GNU getopt
|
||||
set -l longopt type,path,force-path,all,no-functions,help
|
||||
set options -o $shortopt -l $longopt --
|
||||
# Verify options
|
||||
if not getopt -n type $options $argv >/dev/null
|
||||
return 1
|
||||
end
|
||||
else
|
||||
# Old getopt, used on OS X
|
||||
set options $shortopt
|
||||
# Verify options
|
||||
if not getopt $options $argv >/dev/null
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
# Do the real getopt invocation
|
||||
set -l tmp (getopt $options $argv)
|
||||
# Parse options
|
||||
set -l names
|
||||
if test (count $argv) -gt 0
|
||||
for i in (seq (count $argv))
|
||||
set -l arg $argv[$i]
|
||||
set -l needbreak 0
|
||||
while test -n $arg
|
||||
set -l flag $arg
|
||||
set arg ''
|
||||
switch $flag
|
||||
case '--*'
|
||||
# do nothing; this just prevents it matching the next case
|
||||
case '-??*'
|
||||
# combined flags
|
||||
set -l IFS
|
||||
echo -n $flag | read _ flag arg
|
||||
set flag -$flag
|
||||
set arg -$arg
|
||||
end
|
||||
switch $flag
|
||||
case -t --type
|
||||
if test $mode != quiet
|
||||
set mode type
|
||||
end
|
||||
|
||||
# Break tmp up into an array
|
||||
set -l opt
|
||||
eval set opt $tmp
|
||||
|
||||
for i in $opt
|
||||
switch $i
|
||||
case -t --type
|
||||
set mode type
|
||||
case -p --path
|
||||
if test $mode != quiet
|
||||
set mode path
|
||||
end
|
||||
|
||||
case -p --path
|
||||
set mode path
|
||||
case -P --force-path
|
||||
if test $mode != quiet
|
||||
set mode path
|
||||
end
|
||||
set selection files
|
||||
|
||||
case -P --force-path
|
||||
set mode path
|
||||
set selection files
|
||||
case -a --all
|
||||
set multi yes
|
||||
|
||||
case -a --all
|
||||
set selection multi
|
||||
case -f --no-functions
|
||||
set selection files
|
||||
|
||||
case -f --no-functions
|
||||
set selection files
|
||||
case -q --quiet
|
||||
set mode quiet
|
||||
|
||||
case -h --help
|
||||
__fish_print_help type
|
||||
return 0
|
||||
case -h --help
|
||||
__fish_print_help type
|
||||
return 0
|
||||
|
||||
case --
|
||||
break
|
||||
case --
|
||||
set names $argv[$i..-1]
|
||||
set -e names[1]
|
||||
set needbreak 1
|
||||
break
|
||||
|
||||
case '*'
|
||||
set names $argv[$i..-1]
|
||||
set needbreak 1
|
||||
break
|
||||
end
|
||||
end
|
||||
if test $needbreak -eq 1
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Check all possible types for the remaining arguments
|
||||
for i in $argv
|
||||
|
||||
switch $i
|
||||
case '-*'
|
||||
continue
|
||||
end
|
||||
|
||||
for i in $names
|
||||
# Found will be set to 1 if a match is found
|
||||
set found 0
|
||||
set -l found 0
|
||||
|
||||
if test $selection != files
|
||||
|
||||
if contains -- $i (functions -na)
|
||||
if functions -q -- $i
|
||||
set res 0
|
||||
set found 1
|
||||
switch $mode
|
||||
|
@ -86,12 +91,8 @@ function type --description "Print the type of a command"
|
|||
|
||||
case type
|
||||
echo (_ 'function')
|
||||
|
||||
case path
|
||||
echo
|
||||
|
||||
end
|
||||
if test $selection != multi
|
||||
if test $multi != yes
|
||||
continue
|
||||
end
|
||||
end
|
||||
|
@ -106,11 +107,8 @@ function type --description "Print the type of a command"
|
|||
|
||||
case type
|
||||
echo (_ 'builtin')
|
||||
|
||||
case path
|
||||
echo
|
||||
end
|
||||
if test $selection != multi
|
||||
if test $multi != yes
|
||||
continue
|
||||
end
|
||||
end
|
||||
|
@ -118,33 +116,31 @@ function type --description "Print the type of a command"
|
|||
end
|
||||
|
||||
set -l paths
|
||||
if test $selection != multi
|
||||
set paths (which $i ^/dev/null)
|
||||
if test $multi != yes
|
||||
set paths (command -s -- $i)
|
||||
else
|
||||
set paths (which -a $i ^/dev/null)
|
||||
set paths (which -a -- $i ^/dev/null)
|
||||
end
|
||||
for path in $paths
|
||||
if test -x (echo $path)
|
||||
set res 0
|
||||
set found 1
|
||||
switch $mode
|
||||
case normal
|
||||
printf (_ '%s is %s\n') $i $path
|
||||
set res 0
|
||||
set found 1
|
||||
switch $mode
|
||||
case normal
|
||||
printf (_ '%s is %s\n') $i $path
|
||||
|
||||
case type
|
||||
echo (_ 'file')
|
||||
case type
|
||||
echo (_ 'file')
|
||||
|
||||
case path
|
||||
echo $path
|
||||
end
|
||||
if test $selection != multi
|
||||
continue
|
||||
end
|
||||
case path
|
||||
echo $path
|
||||
end
|
||||
if test $multi != yes
|
||||
continue
|
||||
end
|
||||
end
|
||||
|
||||
if test $found = 0
|
||||
printf (_ "%s: Could not find '%s'\n") type $i
|
||||
if begin; test $found = 0; and test $mode != quiet; end
|
||||
printf (_ "%s: Could not find '%s'\n") type $i >&2
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ if term:
|
|||
os.environ['TERM'] = term
|
||||
|
||||
import subprocess
|
||||
import re, socket, cgi, select, time, glob, random, string
|
||||
import re, socket, cgi, select, time, glob, random, string, binascii
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
|
@ -617,14 +617,16 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||
|
||||
def do_get_current_prompt(self):
|
||||
# Return the current prompt
|
||||
# We run 'false' to demonstrate how the prompt shows the command status (#1624)
|
||||
prompt_func, err = run_fish_cmd('functions fish_prompt')
|
||||
result = self.do_get_prompt('builtin cd "' + initial_wd + '" ; fish_prompt', prompt_func.strip(), {'name': 'Current'})
|
||||
result = self.do_get_prompt('builtin cd "' + initial_wd + '" ; false ; fish_prompt', prompt_func.strip(), {'name': 'Current'})
|
||||
return result
|
||||
|
||||
def do_get_sample_prompt(self, text, extras_dict):
|
||||
# Return the prompt you get from the given text
|
||||
# extras_dict is a dictionary whose values get merged in
|
||||
cmd = text + "\n cd \"" + initial_wd + "\" \n fish_prompt\n"
|
||||
# We run 'false' to demonstrate how the prompt shows the command status (#1624)
|
||||
cmd = text + "\n builtin cd \"" + initial_wd + "\" \n false \n fish_prompt\n"
|
||||
return self.do_get_prompt(cmd, text.strip(), extras_dict)
|
||||
|
||||
def parse_one_sample_prompt_hash(self, line, result_dict):
|
||||
|
@ -680,6 +682,14 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||
result.extend([r for r in sample_results if r])
|
||||
return result
|
||||
|
||||
def secure_startswith(self, haystack, needle):
|
||||
if len(haystack) < len(needle):
|
||||
return False
|
||||
bits = 0
|
||||
for x,y in zip(haystack, needle):
|
||||
bits |= ord(x) ^ ord(y)
|
||||
return bits == 0
|
||||
|
||||
def font_size_for_ansi_prompt(self, prompt_demo_ansi):
|
||||
width = ansi_prompt_line_width(prompt_demo_ansi)
|
||||
# Pick a font size
|
||||
|
@ -697,7 +707,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||
p = self.path
|
||||
|
||||
authpath = '/' + authkey
|
||||
if p.startswith(authpath):
|
||||
if self.secure_startswith(p, authpath):
|
||||
p = p[len(authpath):]
|
||||
else:
|
||||
return self.send_error(403)
|
||||
|
@ -736,7 +746,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||
p = self.path
|
||||
|
||||
authpath = '/' + authkey
|
||||
if p.startswith(authpath):
|
||||
if self.secure_startswith(p, authpath):
|
||||
p = p[len(authpath):]
|
||||
else:
|
||||
return self.send_error(403)
|
||||
|
@ -851,7 +861,7 @@ where = os.path.dirname(sys.argv[0])
|
|||
os.chdir(where)
|
||||
|
||||
# Generate a 16-byte random key as a hexadecimal string
|
||||
authkey = hex(random.getrandbits(16*4))[2:]
|
||||
authkey = binascii.b2a_hex(os.urandom(16))
|
||||
|
||||
# Try to find a suitable port
|
||||
PORT = 8000
|
||||
|
|
30
tests/expansion.err
Normal file
30
tests/expansion.err
Normal file
|
@ -0,0 +1,30 @@
|
|||
Array index out of bounds
|
||||
fish: show "$foo[2]"
|
||||
^
|
||||
Array index out of bounds
|
||||
fish: show $foo[2]
|
||||
^
|
||||
Array index out of bounds
|
||||
fish: show "$foo[1 2]"
|
||||
^
|
||||
Array index out of bounds
|
||||
fish: show $foo[1 2]
|
||||
^
|
||||
Array index out of bounds
|
||||
fish: show "$foo[2 1]"
|
||||
^
|
||||
Array index out of bounds
|
||||
fish: show $foo[2 1]
|
||||
^
|
||||
Invalid index value
|
||||
fish: echo "$foo[d]"
|
||||
^
|
||||
Invalid index value
|
||||
fish: echo $foo[d]
|
||||
^
|
||||
Array index out of bounds
|
||||
fish: echo ()[1]
|
||||
^
|
||||
Invalid index value
|
||||
fish: echo ()[d]
|
||||
^
|
82
tests/expansion.in
Normal file
82
tests/expansion.in
Normal file
|
@ -0,0 +1,82 @@
|
|||
# Test expansion of variables
|
||||
|
||||
function show --description 'Prints argument count followed by arguments'
|
||||
echo (count $argv) $argv
|
||||
end
|
||||
|
||||
set -l foo
|
||||
show "$foo"
|
||||
show $foo
|
||||
show "prefix$foo"
|
||||
show prefix$foo
|
||||
|
||||
show "$$foo"
|
||||
show $$foo
|
||||
show "prefix$$foo"
|
||||
show prefix$$foo
|
||||
|
||||
set -l foo ''
|
||||
show "$foo"
|
||||
show $foo
|
||||
show "prefix$foo"
|
||||
show prefix$foo
|
||||
|
||||
show "$$foo"
|
||||
show $$foo
|
||||
show "prefix$$foo"
|
||||
show prefix$$foo
|
||||
|
||||
set -l foo bar
|
||||
set -l bar
|
||||
show "$$foo"
|
||||
show $$foo
|
||||
show "prefix$$foo"
|
||||
show prefix$$foo
|
||||
|
||||
set -l bar baz
|
||||
show "$$foo"
|
||||
show $$foo
|
||||
show "prefix$$foo"
|
||||
show prefix$$foo
|
||||
|
||||
set -l bar baz quux
|
||||
show "$$foo"
|
||||
show $$foo
|
||||
show "prefix$$foo"
|
||||
show prefix$$foo
|
||||
|
||||
set -l foo bar fooer fooest
|
||||
set -l fooer
|
||||
set -l fooest
|
||||
show "$$foo"
|
||||
show $$foo
|
||||
show "prefix$$foo"
|
||||
show prefix$$foo
|
||||
|
||||
set -l fooer ''
|
||||
show $$foo
|
||||
show prefix$$foo
|
||||
|
||||
set -l foo bar '' fooest
|
||||
show "$$foo"
|
||||
show $$foo
|
||||
show "prefix$$foo"
|
||||
show prefix$$foo
|
||||
|
||||
set -l foo
|
||||
show "$foo[1]"
|
||||
show $foo[1]
|
||||
show "$foo[-1]"
|
||||
show $foo[-1]
|
||||
show "$foo[2]"
|
||||
show $foo[2]
|
||||
show "$foo[1 2]"
|
||||
show $foo[1 2]
|
||||
show "$foo[2 1]"
|
||||
show $foo[2 1]
|
||||
|
||||
echo "$foo[d]"
|
||||
echo $foo[d]
|
||||
|
||||
echo ()[1]
|
||||
echo ()[d]
|
42
tests/expansion.out
Normal file
42
tests/expansion.out
Normal file
|
@ -0,0 +1,42 @@
|
|||
1
|
||||
0
|
||||
1 prefix
|
||||
0
|
||||
1
|
||||
0
|
||||
1 prefix
|
||||
0
|
||||
1
|
||||
1
|
||||
1 prefix
|
||||
1 prefix
|
||||
1
|
||||
0
|
||||
1 prefix
|
||||
0
|
||||
1
|
||||
0
|
||||
1 prefix
|
||||
0
|
||||
1 baz
|
||||
1 baz
|
||||
1 prefixbaz
|
||||
1 prefixbaz
|
||||
1 baz quux
|
||||
2 baz quux
|
||||
1 prefixbaz quux
|
||||
2 prefixbaz prefixquux
|
||||
1 baz quux fooer fooest
|
||||
2 baz quux
|
||||
1 prefixbaz quux fooer fooest
|
||||
2 prefixbaz prefixquux
|
||||
3 baz quux
|
||||
3 prefixbaz prefixquux prefix
|
||||
1 baz quux fooest
|
||||
2 baz quux
|
||||
1 prefixbaz quux fooest
|
||||
2 prefixbaz prefixquux
|
||||
1
|
||||
0
|
||||
1
|
||||
0
|
1
tests/expansion.status
Normal file
1
tests/expansion.status
Normal file
|
@ -0,0 +1 @@
|
|||
0
|
0
tests/read.err
Normal file
0
tests/read.err
Normal file
72
tests/read.in
Normal file
72
tests/read.in
Normal file
|
@ -0,0 +1,72 @@
|
|||
#
|
||||
# Test read builtin and IFS
|
||||
#
|
||||
|
||||
count (echo one\ntwo)
|
||||
set -l IFS \t
|
||||
count (echo one\ntwo)
|
||||
set -l IFS
|
||||
count (echo one\ntwo)
|
||||
set -le IFS
|
||||
|
||||
function print_vars --no-scope-shadowing
|
||||
set -l space
|
||||
set -l IFS \n # ensure our command substitution works right
|
||||
for var in $argv
|
||||
echo -n $space (count $$var) \'$$var\'
|
||||
set space ''
|
||||
end
|
||||
echo
|
||||
end
|
||||
|
||||
echo
|
||||
echo 'hello there' | read -l one two
|
||||
print_vars one two
|
||||
echo 'hello there' | read -l one
|
||||
print_vars one
|
||||
echo '' | read -l one
|
||||
print_vars one
|
||||
echo '' | read -l one two
|
||||
print_vars one two
|
||||
echo 'test' | read -l one two three
|
||||
print_vars one two three
|
||||
|
||||
echo
|
||||
set -l IFS
|
||||
echo 'hello' | read -l one
|
||||
print_vars one
|
||||
echo 'hello' | read -l one two
|
||||
print_vars one two
|
||||
echo 'hello' | read -l one two three
|
||||
print_vars one two three
|
||||
echo '' | read -l one
|
||||
print_vars one
|
||||
echo 't' | read -l one two
|
||||
print_vars one two
|
||||
echo 't' | read -l one two three
|
||||
print_vars one two three
|
||||
echo ' t' | read -l one two
|
||||
print_vars one two
|
||||
set -le IFS
|
||||
|
||||
echo
|
||||
echo 'hello there' | read -la ary
|
||||
print_vars ary
|
||||
echo 'hello' | read -la ary
|
||||
print_vars ary
|
||||
echo 'this is a bunch of words' | read -la ary
|
||||
print_vars ary
|
||||
echo ' one two three' | read -la ary
|
||||
print_vars ary
|
||||
echo '' | read -la ary
|
||||
print_vars ary
|
||||
|
||||
echo
|
||||
set -l IFS
|
||||
echo 'hello' | read -la ary
|
||||
print_vars ary
|
||||
echo 'h' | read -la ary
|
||||
print_vars ary
|
||||
echo '' | read -la ary
|
||||
print_vars ary
|
||||
set -le IFS
|
27
tests/read.out
Normal file
27
tests/read.out
Normal file
|
@ -0,0 +1,27 @@
|
|||
2
|
||||
2
|
||||
1
|
||||
|
||||
1 'hello' 1 'there'
|
||||
1 'hello there'
|
||||
1 ''
|
||||
1 '' 1 ''
|
||||
1 'test' 1 '' 1 ''
|
||||
|
||||
1 'hello'
|
||||
1 'h' 1 'ello'
|
||||
1 'h' 1 'e' 1 'llo'
|
||||
1 ''
|
||||
1 't' 1 ''
|
||||
1 't' 1 '' 1 ''
|
||||
1 ' ' 1 't'
|
||||
|
||||
2 'hello' 'there'
|
||||
1 'hello'
|
||||
6 'this' 'is' 'a' 'bunch' 'of' 'words'
|
||||
3 'one' 'two' 'three'
|
||||
0
|
||||
|
||||
5 'h' 'e' 'l' 'l' 'o'
|
||||
1 'h'
|
||||
0
|
1
tests/read.status
Normal file
1
tests/read.status
Normal file
|
@ -0,0 +1 @@
|
|||
0
|
|
@ -110,6 +110,6 @@ function fish_test_type_zzz
|
|||
true
|
||||
end
|
||||
# Should succeed
|
||||
type fish_test_type_zzz >/dev/null ; echo $status
|
||||
type -q fish_test_type_zzz ; echo $status
|
||||
# Should fail
|
||||
type -f fish_test_type_zzz >/dev/null ; echo $status
|
||||
type -q -f fish_test_type_zzz ; echo $status
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
Testing high level script functionality
|
||||
File expansion.in tested ok
|
||||
File printf.in tested ok
|
||||
File read.in tested ok
|
||||
File test1.in tested ok
|
||||
File test2.in tested ok
|
||||
File test3.in tested ok
|
||||
|
|
33
wildcard.cpp
33
wildcard.cpp
|
@ -105,18 +105,14 @@ wildcards using **.
|
|||
/** Hashtable containing all descriptions that describe an executable */
|
||||
static std::map<wcstring, wcstring> suffix_map;
|
||||
|
||||
|
||||
bool wildcard_has(const wchar_t *str, bool internal)
|
||||
// Implementation of wildcard_has. Needs to take the length to handle embedded nulls (#1631)
|
||||
static bool wildcard_has_impl(const wchar_t *str, size_t len, bool internal)
|
||||
{
|
||||
if (!str)
|
||||
{
|
||||
debug(2, L"Got null string on line %d of file %s", __LINE__, __FILE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(str != NULL);
|
||||
const wchar_t *end = str + len;
|
||||
if (internal)
|
||||
{
|
||||
for (; *str; str++)
|
||||
for (; str < end; str++)
|
||||
{
|
||||
if ((*str == ANY_CHAR) || (*str == ANY_STRING) || (*str == ANY_STRING_RECURSIVE))
|
||||
return true;
|
||||
|
@ -125,7 +121,7 @@ bool wildcard_has(const wchar_t *str, bool internal)
|
|||
else
|
||||
{
|
||||
wchar_t prev=0;
|
||||
for (; *str; str++)
|
||||
for (; str < end; str++)
|
||||
{
|
||||
if (((*str == L'*') || (*str == L'?')) && (prev != L'\\'))
|
||||
return true;
|
||||
|
@ -136,6 +132,18 @@ bool wildcard_has(const wchar_t *str, bool internal)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool wildcard_has(const wchar_t *str, bool internal)
|
||||
{
|
||||
assert(str != NULL);
|
||||
return wildcard_has_impl(str, wcslen(str), internal);
|
||||
}
|
||||
|
||||
bool wildcard_has(const wcstring &str, bool internal)
|
||||
{
|
||||
return wildcard_has_impl(str.data(), str.size(), internal);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Check whether the string str matches the wildcard string wc.
|
||||
|
||||
|
@ -1084,6 +1092,11 @@ int wildcard_expand(const wchar_t *wc,
|
|||
|
||||
int wildcard_expand_string(const wcstring &wc, const wcstring &base_dir, expand_flags_t flags, std::vector<completion_t> &outputs)
|
||||
{
|
||||
/* Hackish fix for 1631. We are about to call c_str(), which will produce a string truncated at any embedded nulls. We could fix this by passing around the size, etc. However embedded nulls are never allowed in a filename, so we just check for them and return 0 (no matches) if there is an embedded null. This isn't quite right, e.g. it will fail for \0?, but that is an edge case. */
|
||||
if (wc.find(L'\0') != wcstring::npos)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// PCA: not convinced this temporary variable is really necessary
|
||||
std::vector<completion_t> lst;
|
||||
int res = wildcard_expand(wc.c_str(), base_dir.c_str(), flags, lst);
|
||||
|
|
|
@ -79,9 +79,9 @@ int wildcard_expand_string(const wcstring &wc, const wcstring &base_dir, expand_
|
|||
*/
|
||||
bool wildcard_match(const wcstring &str, const wcstring &wc, bool leading_dots_fail_to_match = false);
|
||||
|
||||
|
||||
/** Check if the specified string contains wildcards */
|
||||
bool wildcard_has(const wchar_t *str, bool internal);
|
||||
bool wildcard_has(const wcstring &, bool internal);
|
||||
bool wildcard_has(const wchar_t *, bool internal);
|
||||
|
||||
/**
|
||||
Test wildcard completion
|
||||
|
|
Loading…
Reference in New Issue
Block a user