diff --git a/complete.cpp b/complete.cpp index 8389e852b..762a33127 100644 --- a/complete.cpp +++ b/complete.cpp @@ -1033,8 +1033,9 @@ static void complete_cmd_desc( const wchar_t *cmd, std::vector &co for( i=0; ibuff, data->buff_pos, &begin, 0, 0, 0 ); - base_len = data->buff_pos - (begin-data->buff); - } - - foo = escape( el.completion.c_str() + base_len, ESCAPE_ALL | ESCAPE_NO_QUOTED ); - } - else - { - wcstring foo_wstr = escape_string( el.completion, ESCAPE_ALL | ESCAPE_NO_QUOTED ); - foo = wcsdup(foo_wstr.c_str()); - } + if( el.completion.empty() ){ + continue; } + if( el.flags & COMPLETE_NO_CASE ) + { + if( base_len == -1 ) + { + wchar_t *begin; + + parse_util_token_extent( data->buff, data->buff_pos, &begin, 0, 0, 0 ); + base_len = data->buff_pos - (begin-data->buff); + } + + wcstring foo_wstr = escape_string( el.completion.c_str() + base_len, ESCAPE_ALL | ESCAPE_NO_QUOTED ); + foo = wcsdup(foo_wstr.c_str()); + } + else + { + wcstring foo_wstr = escape_string( el.completion, ESCAPE_ALL | ESCAPE_NO_QUOTED ); + foo = wcsdup(foo_wstr.c_str()); + } + + if( !el.description.empty() ) { wcstring baz_wstr = escape_string( el.description, 1 ); diff --git a/wildcard.cpp b/wildcard.cpp index 115f9045e..1d250176a 100644 --- a/wildcard.cpp +++ b/wildcard.cpp @@ -250,12 +250,7 @@ static int wildcard_complete_internal( const wchar_t *orig, { wchar_t *out_completion = 0; const wchar_t *out_desc = desc; - - if( out.empty() ) - { - return 1; - } - + if( flags & COMPLETE_NO_CASE ) { out_completion = wcsdup( orig ); @@ -319,7 +314,7 @@ static int wildcard_complete_internal( const wchar_t *orig, do { res |= wildcard_complete_internal( orig, str, wc+1, 0, desc, desc_func, out, flags ); - if( res && out.empty() ) + if( res ) break; } while( *str++ != 0 ); @@ -1190,7 +1185,7 @@ int wildcard_expand( const wchar_t *wc, if( c.flags & COMPLETE_NO_CASE ) { sb_clear( &sb ); - sb_printf( &sb, L"%ls%ls%ls", base_dir, wc_base, c.completion ); + sb_printf( &sb, L"%ls%ls%ls", base_dir, wc_base, c.completion.c_str() ); c.completion = (wchar_t *)sb.buff; }