2016-04-29 03:10:27 +00:00
|
|
|
// Prototypes for string expansion functions. These functions perform several kinds of parameter
|
|
|
|
// expansion. There are a lot of issues with regards to memory allocation. Overall, these functions
|
|
|
|
// would benefit from using a more clever memory allocation scheme, perhaps an evil combination of
|
|
|
|
// talloc, string buffers and reference counting.
|
2005-10-04 15:11:39 +00:00
|
|
|
#ifndef FISH_EXPAND_H
|
|
|
|
#define FISH_EXPAND_H
|
|
|
|
|
2016-04-21 06:00:54 +00:00
|
|
|
#include "config.h"
|
2015-07-25 15:14:25 +00:00
|
|
|
|
2022-08-21 06:14:48 +00:00
|
|
|
#include <initializer_list>
|
2018-10-16 06:36:40 +00:00
|
|
|
#include <map>
|
2016-04-21 06:00:54 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2011-12-27 03:18:46 +00:00
|
|
|
#include "common.h"
|
2019-04-25 18:22:17 +00:00
|
|
|
#include "enum_set.h"
|
2023-10-08 21:22:27 +00:00
|
|
|
#include "env.h"
|
2018-09-24 05:47:38 +00:00
|
|
|
#include "maybe.h"
|
2023-10-08 21:22:27 +00:00
|
|
|
#include "operation_context.h"
|
2014-03-22 00:13:33 +00:00
|
|
|
#include "parse_constants.h"
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2019-04-25 18:34:49 +00:00
|
|
|
/// Set of flags controlling expansions.
|
2023-10-08 21:22:27 +00:00
|
|
|
enum expand_flag {
|
2019-04-25 18:34:49 +00:00
|
|
|
/// Skip command substitutions.
|
2023-10-08 21:22:27 +00:00
|
|
|
skip_cmdsubst = 1 << 0,
|
2019-04-25 18:34:49 +00:00
|
|
|
/// Skip variable expansion.
|
2023-10-08 21:22:27 +00:00
|
|
|
skip_variables = 1 << 1,
|
2019-04-25 18:34:49 +00:00
|
|
|
/// Skip wildcard expansion.
|
2023-10-08 21:22:27 +00:00
|
|
|
skip_wildcards = 1 << 2,
|
2016-04-29 03:10:27 +00:00
|
|
|
/// The expansion is being done for tab or auto completions. Returned completions may have the
|
|
|
|
/// wildcard as a prefix instead of a match.
|
2023-10-08 21:22:27 +00:00
|
|
|
for_completions = 1 << 3,
|
2017-04-09 04:05:18 +00:00
|
|
|
/// Only match files that are executable by the current user.
|
2023-10-08 21:22:27 +00:00
|
|
|
executables_only = 1 << 4,
|
2017-04-09 04:05:18 +00:00
|
|
|
/// Only match directories.
|
2023-10-08 21:22:27 +00:00
|
|
|
directories_only = 1 << 5,
|
2020-09-27 23:49:12 +00:00
|
|
|
/// Generate descriptions, stored in the description field of completions.
|
2023-10-08 21:22:27 +00:00
|
|
|
gen_descriptions = 1 << 6,
|
2021-11-28 02:42:25 +00:00
|
|
|
/// Un-expand home directories to tildes after.
|
2023-10-08 21:22:27 +00:00
|
|
|
preserve_home_tildes = 1 << 7,
|
2016-04-29 03:10:27 +00:00
|
|
|
/// Allow fuzzy matching.
|
2023-10-08 21:22:27 +00:00
|
|
|
fuzzy_match = 1 << 8,
|
2016-04-29 03:10:27 +00:00
|
|
|
/// Disallow directory abbreviations like /u/l/b for /usr/local/bin. Only applicable if
|
2019-04-25 18:34:49 +00:00
|
|
|
/// fuzzy_match is set.
|
2023-10-08 21:22:27 +00:00
|
|
|
no_fuzzy_directories = 1 << 9,
|
2022-09-12 22:33:29 +00:00
|
|
|
/// Allows matching a leading dot even if the wildcard does not contain one.
|
|
|
|
/// By default, wildcards only match a leading dot literally; this is why e.g. '*' does not
|
|
|
|
/// match hidden files.
|
2023-10-08 21:22:27 +00:00
|
|
|
allow_nonliteral_leading_dot = 1 << 10,
|
2016-04-29 03:10:27 +00:00
|
|
|
/// Do expansions specifically to support cd. This means using CDPATH as a list of potential
|
2018-11-03 20:30:55 +00:00
|
|
|
/// working directories, and to use logical instead of physical paths.
|
2023-10-08 21:22:27 +00:00
|
|
|
special_for_cd = 1 << 11,
|
2018-01-08 21:36:20 +00:00
|
|
|
/// Do expansions specifically for cd autosuggestion. This is to differentiate between cd
|
|
|
|
/// completions and cd autosuggestions.
|
2023-10-08 21:22:27 +00:00
|
|
|
special_for_cd_autosuggestion = 1 << 12,
|
2016-04-29 03:10:27 +00:00
|
|
|
/// Do expansions specifically to support external command completions. This means using PATH as
|
2016-06-06 01:46:04 +00:00
|
|
|
/// a list of potential working directories.
|
2023-10-08 21:22:27 +00:00
|
|
|
special_for_command = 1 << 13,
|
2012-02-24 20:13:35 +00:00
|
|
|
};
|
2019-04-25 18:22:17 +00:00
|
|
|
|
2023-10-08 21:22:27 +00:00
|
|
|
using expand_flags_t = uint64_t;
|
2012-01-16 16:56:47 +00:00
|
|
|
|
2019-09-14 20:17:22 +00:00
|
|
|
enum : wchar_t {
|
2016-04-29 03:10:27 +00:00
|
|
|
/// Character representing a home directory.
|
2016-01-22 03:56:39 +00:00
|
|
|
HOME_DIRECTORY = EXPAND_RESERVED_BASE,
|
2018-10-10 21:26:29 +00:00
|
|
|
/// Character representing process expansion for %self.
|
|
|
|
PROCESS_EXPAND_SELF,
|
2016-04-29 03:10:27 +00:00
|
|
|
/// Character representing variable expansion.
|
2012-11-19 00:30:30 +00:00
|
|
|
VARIABLE_EXPAND,
|
2016-04-29 03:10:27 +00:00
|
|
|
/// Character representing variable expansion into a single element.
|
2012-11-19 00:30:30 +00:00
|
|
|
VARIABLE_EXPAND_SINGLE,
|
2019-09-22 22:33:08 +00:00
|
|
|
/// Character representing the start of a bracket expansion.
|
2018-03-10 19:16:07 +00:00
|
|
|
BRACE_BEGIN,
|
2019-09-22 22:33:08 +00:00
|
|
|
/// Character representing the end of a bracket expansion.
|
2018-03-10 19:16:07 +00:00
|
|
|
BRACE_END,
|
2016-04-29 03:10:27 +00:00
|
|
|
/// Character representing separation between two bracket elements.
|
2018-03-10 19:16:07 +00:00
|
|
|
BRACE_SEP,
|
2018-03-12 03:02:43 +00:00
|
|
|
/// Character that takes the place of any whitespace within non-quoted text in braces
|
|
|
|
BRACE_SPACE,
|
2016-04-29 03:10:27 +00:00
|
|
|
/// Separate subtokens in a token with this character.
|
2012-11-19 00:30:30 +00:00
|
|
|
INTERNAL_SEPARATOR,
|
2016-04-29 03:10:27 +00:00
|
|
|
/// Character representing an empty variable expansion. Only used transitively while expanding
|
|
|
|
/// variables.
|
2014-08-21 04:19:08 +00:00
|
|
|
VARIABLE_EXPAND_EMPTY,
|
2019-11-25 11:03:25 +00:00
|
|
|
/// This is a special pseudo-char that is not used other than to mark the end of the the special
|
2016-04-29 03:10:27 +00:00
|
|
|
/// characters so we can sanity check the enum range.
|
2020-02-29 23:56:52 +00:00
|
|
|
EXPAND_SENTINEL
|
2016-01-22 03:56:39 +00:00
|
|
|
};
|
2005-12-03 16:43:56 +00:00
|
|
|
|
2018-10-10 21:26:29 +00:00
|
|
|
/// The string represented by PROCESS_EXPAND_SELF
|
2022-09-20 18:58:37 +00:00
|
|
|
#define PROCESS_EXPAND_SELF_STR L"%self"
|
|
|
|
#define PROCESS_EXPAND_SELF_STR_LEN 5
|
2018-10-10 21:26:29 +00:00
|
|
|
|
2023-10-08 21:22:27 +00:00
|
|
|
#if INCLUDE_RUST_HEADERS
|
|
|
|
#include "expand.rs.h"
|
|
|
|
using expand_result_t = ExpandResult;
|
|
|
|
#endif
|
2019-12-29 16:43:05 +00:00
|
|
|
|
2016-04-29 03:10:27 +00:00
|
|
|
/// \param input the string to tilde expand
|
2023-10-08 21:22:27 +00:00
|
|
|
void expand_tilde(wcstring &input, const env_stack_t &vars);
|
2013-12-16 23:33:20 +00:00
|
|
|
|
2005-10-04 15:11:39 +00:00
|
|
|
#endif
|