mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Remove PATH and COMMAND defines
Also clean up a bit of builtin_complete
This commit is contained in:
parent
496529b20a
commit
d962668aa0
2 changed files with 33 additions and 40 deletions
|
@ -27,86 +27,82 @@
|
||||||
// complete_add function only accepts one short switch and one long switch.
|
// complete_add function only accepts one short switch and one long switch.
|
||||||
|
|
||||||
/// Silly function.
|
/// Silly function.
|
||||||
static void builtin_complete_add2(const wchar_t *cmd, int cmd_type, const wchar_t *short_opt,
|
static void builtin_complete_add2(const wchar_t *cmd, bool cmd_is_path, const wchar_t *short_opt,
|
||||||
const wcstring_list_t &gnu_opt, const wcstring_list_t &old_opt,
|
const wcstring_list_t &gnu_opts, const wcstring_list_t &old_opts,
|
||||||
int result_mode, const wchar_t *condition, const wchar_t *comp,
|
int result_mode, const wchar_t *condition, const wchar_t *comp,
|
||||||
const wchar_t *desc, int flags) {
|
const wchar_t *desc, int flags) {
|
||||||
size_t i;
|
for (const wchar_t *s = short_opt; *s; s++) {
|
||||||
const wchar_t *s;
|
complete_add(cmd, cmd_is_path, wcstring{*s}, option_type_short, result_mode, condition,
|
||||||
|
|
||||||
for (s = short_opt; *s; s++) {
|
|
||||||
complete_add(cmd, cmd_type, wcstring(1, *s), option_type_short, result_mode, condition,
|
|
||||||
comp, desc, flags);
|
comp, desc, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < gnu_opt.size(); i++) {
|
for (const wcstring &gnu_opt : gnu_opts) {
|
||||||
complete_add(cmd, cmd_type, gnu_opt.at(i), option_type_double_long, result_mode, condition,
|
complete_add(cmd, cmd_is_path, gnu_opt, option_type_double_long, result_mode, condition,
|
||||||
comp, desc, flags);
|
comp, desc, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < old_opt.size(); i++) {
|
for (const wcstring &old_opt : old_opts) {
|
||||||
complete_add(cmd, cmd_type, old_opt.at(i), option_type_single_long, result_mode, condition,
|
complete_add(cmd, cmd_is_path, old_opt, option_type_single_long, result_mode, condition,
|
||||||
comp, desc, flags);
|
comp, desc, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (old_opt.empty() && gnu_opt.empty() && short_opt[0] == L'\0') {
|
if (old_opts.empty() && gnu_opts.empty() && short_opt[0] == L'\0') {
|
||||||
complete_add(cmd, cmd_type, wcstring(), option_type_args_only, result_mode, condition, comp,
|
complete_add(cmd, cmd_is_path, wcstring(), option_type_args_only, result_mode, condition,
|
||||||
desc, flags);
|
comp, desc, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Silly function.
|
/// Silly function.
|
||||||
static void builtin_complete_add(const wcstring_list_t &cmd, const wcstring_list_t &path,
|
static void builtin_complete_add(const wcstring_list_t &cmds, const wcstring_list_t &paths,
|
||||||
const wchar_t *short_opt, wcstring_list_t &gnu_opt,
|
const wchar_t *short_opt, wcstring_list_t &gnu_opt,
|
||||||
wcstring_list_t &old_opt, int result_mode,
|
wcstring_list_t &old_opt, int result_mode,
|
||||||
const wchar_t *condition, const wchar_t *comp, const wchar_t *desc,
|
const wchar_t *condition, const wchar_t *comp, const wchar_t *desc,
|
||||||
int flags) {
|
int flags) {
|
||||||
for (size_t i = 0; i < cmd.size(); i++) {
|
for (const wcstring &cmd : cmds) {
|
||||||
builtin_complete_add2(cmd.at(i).c_str(), COMMAND, short_opt, gnu_opt, old_opt, result_mode,
|
builtin_complete_add2(cmd.c_str(), false /* not path */, short_opt, gnu_opt, old_opt,
|
||||||
condition, comp, desc, flags);
|
result_mode, condition, comp, desc, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < path.size(); i++) {
|
for (const wcstring &path : paths) {
|
||||||
builtin_complete_add2(path.at(i).c_str(), PATH, short_opt, gnu_opt, old_opt, result_mode,
|
builtin_complete_add2(path.c_str(), true /* is path */, short_opt, gnu_opt, old_opt,
|
||||||
condition, comp, desc, flags);
|
result_mode, condition, comp, desc, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void builtin_complete_remove_cmd(const wcstring &cmd, int cmd_type, const wchar_t *short_opt,
|
static void builtin_complete_remove_cmd(const wcstring &cmd, bool cmd_is_path,
|
||||||
const wcstring_list_t &gnu_opt,
|
const wchar_t *short_opt, const wcstring_list_t &gnu_opt,
|
||||||
const wcstring_list_t &old_opt) {
|
const wcstring_list_t &old_opt) {
|
||||||
bool removed = false;
|
bool removed = false;
|
||||||
size_t i;
|
for (const wchar_t *s = short_opt; *s; s++) {
|
||||||
for (i = 0; short_opt[i] != L'\0'; i++) {
|
complete_remove(cmd, cmd_is_path, wcstring{*s}, option_type_short);
|
||||||
complete_remove(cmd, cmd_type, wcstring(1, short_opt[i]), option_type_short);
|
|
||||||
removed = true;
|
removed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < old_opt.size(); i++) {
|
for (const wcstring &opt : old_opt) {
|
||||||
complete_remove(cmd, cmd_type, old_opt.at(i), option_type_single_long);
|
complete_remove(cmd, cmd_is_path, opt, option_type_single_long);
|
||||||
removed = true;
|
removed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < gnu_opt.size(); i++) {
|
for (const wcstring &opt : gnu_opt) {
|
||||||
complete_remove(cmd, cmd_type, gnu_opt.at(i), option_type_double_long);
|
complete_remove(cmd, cmd_is_path, opt, option_type_double_long);
|
||||||
removed = true;
|
removed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!removed) {
|
if (!removed) {
|
||||||
// This means that all loops were empty.
|
// This means that all loops were empty.
|
||||||
complete_remove_all(cmd, cmd_type);
|
complete_remove_all(cmd, cmd_is_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void builtin_complete_remove(const wcstring_list_t &cmd, const wcstring_list_t &path,
|
static void builtin_complete_remove(const wcstring_list_t &cmds, const wcstring_list_t &paths,
|
||||||
const wchar_t *short_opt, const wcstring_list_t &gnu_opt,
|
const wchar_t *short_opt, const wcstring_list_t &gnu_opt,
|
||||||
const wcstring_list_t &old_opt) {
|
const wcstring_list_t &old_opt) {
|
||||||
for (size_t i = 0; i < cmd.size(); i++) {
|
for (const wcstring &cmd : cmds) {
|
||||||
builtin_complete_remove_cmd(cmd.at(i), COMMAND, short_opt, gnu_opt, old_opt);
|
builtin_complete_remove_cmd(cmd, false /* not path */, short_opt, gnu_opt, old_opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < path.size(); i++) {
|
for (const wcstring &path : paths) {
|
||||||
builtin_complete_remove_cmd(path.at(i), PATH, short_opt, gnu_opt, old_opt);
|
builtin_complete_remove_cmd(path, true /* is path */, short_opt, gnu_opt, old_opt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,7 @@
|
||||||
/// Only use the argument list specifies with completion after option. This is the same as (NO_FILES
|
/// Only use the argument list specifies with completion after option. This is the same as (NO_FILES
|
||||||
/// | NO_COMMON).
|
/// | NO_COMMON).
|
||||||
#define EXCLUSIVE 3
|
#define EXCLUSIVE 3
|
||||||
/// Command is a path.
|
|
||||||
#define PATH 1
|
|
||||||
/// Command is not a path.
|
|
||||||
#define COMMAND 0
|
|
||||||
/// Separator between completion and description.
|
/// Separator between completion and description.
|
||||||
#define COMPLETE_SEP L'\004'
|
#define COMPLETE_SEP L'\004'
|
||||||
/// Character that separates the completion and description on programmable completions.
|
/// Character that separates the completion and description on programmable completions.
|
||||||
|
|
Loading…
Reference in a new issue