mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Autoload :
function on startup.
The newly added `:` command is implemented as a function (to avoid increasing complexity by making it a builtin), but it is saved to a path that does not match its filename (since its name is somewhat of a special character that might cause problems during installation). Directly probing the `colon` function for autoload causes `:` to be correctly loaded, so doing just that after function paths are loaded upon startup. This is a hack since the CPP code shouldn't really be aware of individual functions, perhaps there is a better way of doing this.
This commit is contained in:
parent
007ae0b15e
commit
3996e437b6
5 changed files with 17 additions and 4 deletions
|
@ -746,6 +746,12 @@ static void setup_user(bool force) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void misc_init_with_paths() {
|
||||||
|
// Since ':' can cause problems in filenames, the : function is saved to colon.fish
|
||||||
|
// But that means it isn't autoloaded since the name doesn't match the function.
|
||||||
|
bool loaded = function_load(L"colon");
|
||||||
|
}
|
||||||
|
|
||||||
/// Various things we need to initialize at run-time that don't really fit any of the other init
|
/// Various things we need to initialize at run-time that don't really fit any of the other init
|
||||||
/// routines.
|
/// routines.
|
||||||
void misc_init() {
|
void misc_init() {
|
||||||
|
@ -763,7 +769,7 @@ void misc_init() {
|
||||||
// MS Windows tty devices do not currently have either a read or write timestamp. Those
|
// MS Windows tty devices do not currently have either a read or write timestamp. Those
|
||||||
// respective fields of `struct stat` are always the current time. Which means we can't
|
// respective fields of `struct stat` are always the current time. Which means we can't
|
||||||
// use them. So we assume no external program has written to the terminal behind our
|
// use them. So we assume no external program has written to the terminal behind our
|
||||||
// back. This makes multiline promptusable. See issue #2859 and
|
// back. This makes multiline prompt usable. See issue #2859 and
|
||||||
// https://github.com/Microsoft/BashOnWindows/issues/545
|
// https://github.com/Microsoft/BashOnWindows/issues/545
|
||||||
has_working_tty_timestamps = false;
|
has_working_tty_timestamps = false;
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -67,6 +67,8 @@ void env_init(const struct config_paths_t *paths = NULL);
|
||||||
/// Various things we need to initialize at run-time that don't really fit any of the other init
|
/// Various things we need to initialize at run-time that don't really fit any of the other init
|
||||||
/// routines.
|
/// routines.
|
||||||
void misc_init();
|
void misc_init();
|
||||||
|
/// Same as misc_init() but after configuration paths have been loaded
|
||||||
|
void misc_init_with_paths();
|
||||||
|
|
||||||
class env_var_t {
|
class env_var_t {
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -384,6 +384,9 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
const io_chain_t empty_ios;
|
const io_chain_t empty_ios;
|
||||||
if (read_init(paths)) {
|
if (read_init(paths)) {
|
||||||
|
// Additional initialization that must occur after paths are loaded
|
||||||
|
misc_init_with_paths();
|
||||||
|
|
||||||
// Stomp the exit status of any initialization commands (issue #635).
|
// Stomp the exit status of any initialization commands (issue #635).
|
||||||
proc_set_last_status(STATUS_CMD_OK);
|
proc_set_last_status(STATUS_CMD_OK);
|
||||||
|
|
||||||
|
|
|
@ -194,11 +194,13 @@ int function_exists(const wcstring &cmd) {
|
||||||
return loaded_functions.find(cmd) != loaded_functions.end();
|
return loaded_functions.find(cmd) != loaded_functions.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void function_load(const wcstring &cmd) {
|
bool function_load(const wcstring &cmd) {
|
||||||
if (!parser_keywords_is_reserved(cmd)) {
|
if (!parser_keywords_is_reserved(cmd)) {
|
||||||
scoped_rlock locker(functions_lock);
|
scoped_rlock locker(functions_lock);
|
||||||
load(cmd);
|
return load(cmd) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false; //not loaded
|
||||||
}
|
}
|
||||||
|
|
||||||
int function_exists_no_autoload(const wcstring &cmd, const env_vars_snapshot_t &vars) {
|
int function_exists_no_autoload(const wcstring &cmd, const env_vars_snapshot_t &vars) {
|
||||||
|
|
|
@ -74,7 +74,7 @@ void function_set_desc(const wcstring &name, const wcstring &desc);
|
||||||
int function_exists(const wcstring &name);
|
int function_exists(const wcstring &name);
|
||||||
|
|
||||||
/// Attempts to load a function if not yet loaded. This is used by the completion machinery.
|
/// Attempts to load a function if not yet loaded. This is used by the completion machinery.
|
||||||
void function_load(const wcstring &name);
|
bool function_load(const wcstring &name);
|
||||||
|
|
||||||
/// Returns true if the function with the name name exists, without triggering autoload.
|
/// Returns true if the function with the name name exists, without triggering autoload.
|
||||||
int function_exists_no_autoload(const wcstring &name, const env_vars_snapshot_t &vars);
|
int function_exists_no_autoload(const wcstring &name, const env_vars_snapshot_t &vars);
|
||||||
|
|
Loading…
Reference in a new issue