diff --git a/builtin.cpp b/builtin.cpp index 3a61d16f2..f16c065e4 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -1442,7 +1442,32 @@ static int builtin_functions( parser_t &parser, wchar_t **argv ) } return res; +} +/** The echo builtin. + bash only respects -n if it's the first argument. We'll do the same. */ + +static int builtin_echo( parser_t &parser, wchar_t **argv ) +{ + /* Skip first arg */ + if (! *argv++) + return STATUS_BUILTIN_ERROR; + + /* Process -n */ + bool show_newline = true; + if (*argv && ! wcscmp(*argv, L"-n")) { + show_newline = false; + argv++; + } + + for (size_t idx = 0; argv[idx]; idx++) { + if (idx > 0) + stdout_buffer.push_back(' '); + stdout_buffer.append(argv[idx]); + } + if (show_newline) + stdout_buffer.push_back('\n'); + return STATUS_BUILTIN_OK; } @@ -3562,6 +3587,7 @@ static const builtin_data_t builtin_datas[]= { L"contains", &builtin_contains, N_( L"Search for a specified string in a list" ) }, { L"continue", &builtin_break_continue, N_( L"Skip the rest of the current lap of the innermost loop" ) }, { L"count", &builtin_count, N_( L"Count the number of arguments" ) }, + { L"echo", &builtin_echo, N_( L"Print arguments" ) }, { L"else", &builtin_else, N_( L"Evaluate block if condition is false" ) }, { L"emit", &builtin_emit, N_( L"Emit an event" ) }, { L"end", &builtin_end, N_( L"End a block of commands" ) }, diff --git a/exec.cpp b/exec.cpp index a9fff7678..54ee809ae 100644 --- a/exec.cpp +++ b/exec.cpp @@ -1238,8 +1238,12 @@ void exec( parser_t &parser, job_t *j ) const char *actual_cmd = actual_cmd_str.c_str(); const wchar_t *reader_current_filename(); - if (g_log_forks) + if (g_log_forks) { printf("forking for '%s' in '%ls'\n", actual_cmd, reader_current_filename()); + if (std::string(actual_cmd) == "/usr/bin/getopt") { + puts("wat"); + } + } pid = execute_fork(true /* must drain threads */); if( pid == 0 ) { diff --git a/fish_indent.cpp b/fish_indent.cpp index 6c0f65f38..c99c7a9e3 100644 --- a/fish_indent.cpp +++ b/fish_indent.cpp @@ -279,7 +279,9 @@ static void trim( wcstring &str ) int main( int argc, char **argv ) { int do_indent=1; - set_main_thread(); + set_main_thread(); + setup_fork_guards(); + wsetlocale( LC_ALL, L"" ); program_name=L"fish_indent"; diff --git a/fish_pager.cpp b/fish_pager.cpp index c351a88b1..1ca0f903b 100644 --- a/fish_pager.cpp +++ b/fish_pager.cpp @@ -1190,7 +1190,9 @@ int main( int argc, char **argv ) int mangle_descriptors = 0; int result_fd = -1; - set_main_thread(); + set_main_thread(); + setup_fork_guards(); + /* This initialization is made early, so that the other init code can use global_context for memory managment diff --git a/fishd.cpp b/fishd.cpp index edaa762a8..1704d3753 100644 --- a/fishd.cpp +++ b/fishd.cpp @@ -827,6 +827,7 @@ int main( int argc, char ** argv ) fd_set read_fd, write_fd; set_main_thread(); + setup_fork_guards(); program_name=L"fishd"; wsetlocale( LC_ALL, L"" ); diff --git a/key_reader.cpp b/key_reader.cpp index 52ef733be..bb092f99f 100644 --- a/key_reader.cpp +++ b/key_reader.cpp @@ -28,6 +28,7 @@ int writestr( char *str ) int main( int argc, char **argv) { set_main_thread(); + setup_fork_guards(); setlocale( LC_ALL, "" ); diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index c60fa6065..02c795b0c 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -227,7 +227,7 @@ function __fish_config_interactive -d "Initializations that should be performed end else # Ubuntu Feisty places this command in the regular path instead - if type -p command-not-found >/dev/null + if which command-not-found >/dev/null function fish_command_not_found_handler --on-event fish_command_not_found command-not-found $argv end