From 195902a645b794092959ac3818f367104c7ffeb8 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 8 Dec 2018 15:45:44 +0000 Subject: lineedit: improvements to tab completion Since getpwent isn't implemented for WIN32 there's no point in enabling FEATURE_USERNAME_COMPLETION. Use case-insensitive comparisons when matching filenames. The code to exclude non-executables when tab completing executables is WIN32-specific and shouldn't omit directories. --- configs/mingw32_defconfig | 2 +- configs/mingw64_defconfig | 2 +- include/mingw.h | 2 ++ libbb/compare_string_array.c | 13 +++++++++++++ libbb/lineedit.c | 19 +++++++++---------- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig index 5a49bc4a8..6ef09c7b9 100644 --- a/configs/mingw32_defconfig +++ b/configs/mingw32_defconfig @@ -115,7 +115,7 @@ CONFIG_FEATURE_EDITING_SAVEHISTORY=y # CONFIG_FEATURE_EDITING_SAVE_ON_EXIT is not set CONFIG_FEATURE_REVERSE_SEARCH=y CONFIG_FEATURE_TAB_COMPLETION=y -CONFIG_FEATURE_USERNAME_COMPLETION=y +# CONFIG_FEATURE_USERNAME_COMPLETION is not set CONFIG_FEATURE_EDITING_FANCY_PROMPT=y # CONFIG_FEATURE_EDITING_WINCH is not set # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set diff --git a/configs/mingw64_defconfig b/configs/mingw64_defconfig index 9d6e32104..8cc6b419a 100644 --- a/configs/mingw64_defconfig +++ b/configs/mingw64_defconfig @@ -115,7 +115,7 @@ CONFIG_FEATURE_EDITING_SAVEHISTORY=y # CONFIG_FEATURE_EDITING_SAVE_ON_EXIT is not set CONFIG_FEATURE_REVERSE_SEARCH=y CONFIG_FEATURE_TAB_COMPLETION=y -CONFIG_FEATURE_USERNAME_COMPLETION=y +# CONFIG_FEATURE_USERNAME_COMPLETION is not set CONFIG_FEATURE_EDITING_FANCY_PROMPT=y # CONFIG_FEATURE_EDITING_WINCH is not set # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set diff --git a/include/mingw.h b/include/mingw.h index 543172075..a828e6613 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -447,6 +447,8 @@ int kill_SIGTERM_by_handle(HANDLE process, int exit_code); #define find_mount_point(n, s) find_mount_point(n) +char *is_prefixed_with_case(const char *string, const char *key) FAST_FUNC; + /* * helpers */ diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c index 01a9df0e2..7ccdaef8a 100644 --- a/libbb/compare_string_array.c +++ b/libbb/compare_string_array.c @@ -27,6 +27,19 @@ char* FAST_FUNC is_prefixed_with(const char *string, const char *key) #endif } +#if ENABLE_PLATFORM_MINGW32 +char* FAST_FUNC is_prefixed_with_case(const char *string, const char *key) +{ + while (*key != '\0') { + if (tolower(*key) != tolower(*string)) + return NULL; + key++; + string++; + } + return (char*)string; +} +#endif + /* * Return NULL if string is not suffixed with key. Return pointer to the * beginning of prefix key in string. If key is an empty string return pointer diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 19b579782..979e0d544 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -681,6 +681,11 @@ static void input_forward(void) //Also, perhaps "foo b needs to complete to "foo bar" , //not "foo bar ... +# if ENABLE_PLATFORM_MINGW32 +/* use case-insensitive comparisons for filenames */ +# define is_prefixed_with(s, k) is_prefixed_with_case(s, k) +# endif + static void free_tab_completion_data(void) { if (matches) { @@ -897,8 +902,11 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) if (stat(found, &st) && lstat(found, &st)) goto cont; /* hmm, remove in progress? */ - if (type == FIND_EXE_ONLY && !file_is_executable(found)) +# if ENABLE_PLATFORM_MINGW32 + if (type == FIND_EXE_ONLY && !S_ISDIR(st.st_mode) && + !file_is_executable(found)) goto cont; +# endif /* Save only name */ len = strlen(name_found); @@ -2005,16 +2013,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) char *after_home_user; /* /home/user[/something] -> ~[/something] */ -#if !ENABLE_PLATFORM_MINGW32 after_home_user = is_prefixed_with(cwd_buf, home_pwd_buf); -#else - after_home_user = NULL; - l = strlen(home_pwd_buf); - if (l != 0 - && strncasecmp(home_pwd_buf, cwd_buf, l) == 0) { - after_home_user = cwd_buf + l; - } -#endif if (after_home_user && (*after_home_user == '/' || *after_home_user == '\0') ) { -- cgit v1.2.3-55-g6feb