Skip to content

Commit 5a561bc

Browse files
committed
Source : function without any C++ hacks
Thanks, @faho
1 parent 5732aea commit 5a561bc

File tree

6 files changed

+11
-17
lines changed

6 files changed

+11
-17
lines changed

share/config.fish

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ if not contains -- $__fish_data_dir/completions $fish_complete_path
105105
set fish_complete_path $fish_complete_path $__fish_data_dir/completions
106106
end
107107

108+
# : is a sh/bash-compatibility function, but because its name can cause problems on many
109+
# systems, it is saved as colon.fish and not :.fish, which means that it's never autoloaded
110+
# since the name of the file and the name of the function differ. Force evaluation of colon.fish
111+
# as a function by simply trying to load the non-existent function colon, which will pull in
112+
# colon.fish and lead to `:` being recognized. Sourced up here so it can be used later safely.
113+
type -q colon; or true # just to reset $status
114+
108115
#
109116
# This is a Solaris-specific test to modify the PATH so that
110117
# Posix-conformant tools are used by default. It is separate from the

src/env.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -746,12 +746,6 @@ static void setup_user(bool force) {
746746
}
747747
}
748748

749-
void misc_init_with_paths() {
750-
// Since ':' can cause problems in filenames, the : function is saved to colon.fish
751-
// But that means it isn't autoloaded since the name doesn't match the function.
752-
bool loaded = function_load(L"colon");
753-
}
754-
755749
/// Various things we need to initialize at run-time that don't really fit any of the other init
756750
/// routines.
757751
void misc_init() {
@@ -769,7 +763,7 @@ void misc_init() {
769763
// MS Windows tty devices do not currently have either a read or write timestamp. Those
770764
// respective fields of `struct stat` are always the current time. Which means we can't
771765
// use them. So we assume no external program has written to the terminal behind our
772-
// back. This makes multiline prompt usable. See issue #2859 and
766+
// back. This makes multiline promptusable. See issue #2859 and
773767
// https://github.com/Microsoft/BashOnWindows/issues/545
774768
has_working_tty_timestamps = false;
775769
#endif

src/env.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ void env_init(const struct config_paths_t *paths = NULL);
6767
/// Various things we need to initialize at run-time that don't really fit any of the other init
6868
/// routines.
6969
void misc_init();
70-
/// Same as misc_init() but after configuration paths have been loaded
71-
void misc_init_with_paths();
7270

7371
class env_var_t {
7472
private:

src/fish.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,6 @@ int main(int argc, char **argv) {
384384

385385
const io_chain_t empty_ios;
386386
if (read_init(paths)) {
387-
// Additional initialization that must occur after paths are loaded
388-
misc_init_with_paths();
389-
390387
// Stomp the exit status of any initialization commands (issue #635).
391388
proc_set_last_status(STATUS_CMD_OK);
392389

src/function.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,11 @@ int function_exists(const wcstring &cmd) {
194194
return loaded_functions.find(cmd) != loaded_functions.end();
195195
}
196196

197-
bool function_load(const wcstring &cmd) {
197+
void function_load(const wcstring &cmd) {
198198
if (!parser_keywords_is_reserved(cmd)) {
199199
scoped_rlock locker(functions_lock);
200-
return load(cmd) == 0;
200+
load(cmd);
201201
}
202-
203-
return false; //not loaded
204202
}
205203

206204
int function_exists_no_autoload(const wcstring &cmd, const env_vars_snapshot_t &vars) {

src/function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void function_set_desc(const wcstring &name, const wcstring &desc);
7474
int function_exists(const wcstring &name);
7575

7676
/// Attempts to load a function if not yet loaded. This is used by the completion machinery.
77-
bool function_load(const wcstring &name);
77+
void function_load(const wcstring &name);
7878

7979
/// Returns true if the function with the name name exists, without triggering autoload.
8080
int function_exists_no_autoload(const wcstring &name, const env_vars_snapshot_t &vars);

0 commit comments

Comments
 (0)