mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Fix bug where underlining was failing for paths prefixed with ~
Fixes https://github.com/fish-shell/fish-shell/issues/292
This commit is contained in:
parent
f5d4e3f94c
commit
5bbf220077
3 changed files with 26 additions and 19 deletions
10
expand.cpp
10
expand.cpp
|
@ -1453,9 +1453,9 @@ static wcstring expand_unescape_string( const wcstring &in, int escape_special )
|
|||
/**
|
||||
Attempts tilde expansion of the string specified, modifying it in place.
|
||||
*/
|
||||
static void expand_tilde_internal( wcstring &input )
|
||||
static void expand_home_directory( wcstring &input )
|
||||
{
|
||||
const wchar_t * const in = input.c_str();
|
||||
const wchar_t * const in = input.c_str();
|
||||
if( in[0] == HOME_DIRECTORY )
|
||||
{
|
||||
int tilde_error = 0;
|
||||
|
@ -1503,12 +1503,12 @@ static void expand_tilde_internal( wcstring &input )
|
|||
}
|
||||
}
|
||||
|
||||
void expand_tilde( wcstring &input)
|
||||
void expand_tilde(wcstring &input)
|
||||
{
|
||||
if( ! input.empty() && input.at(0) == L'~' )
|
||||
{
|
||||
input.at(0) = HOME_DIRECTORY;
|
||||
expand_tilde_internal( input );
|
||||
expand_home_directory( input );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1631,7 +1631,7 @@ int expand_string( const wcstring &input, std::vector<completion_t> &output, exp
|
|||
{
|
||||
wcstring next = in->at(i).completion;
|
||||
|
||||
expand_tilde_internal(next);
|
||||
expand_home_directory(next);
|
||||
|
||||
|
||||
if( flags & ACCEPT_INCOMPLETE )
|
||||
|
|
1
expand.h
1
expand.h
|
@ -169,7 +169,6 @@ wcstring expand_escape_variable( const wcstring &in );
|
|||
*/
|
||||
void expand_tilde(wcstring &input);
|
||||
|
||||
|
||||
/**
|
||||
Test if the specified argument is clean, i.e. it does not contain
|
||||
any tokens which need to be expanded or otherwise altered. Clean
|
||||
|
|
|
@ -273,7 +273,8 @@ bool is_potential_path(const wcstring &const_path, const wcstring_list_t &direct
|
|||
|
||||
|
||||
/* Given a string, return whether it prefixes a path that we could cd into. Return that path in out_path. Expects path to be unescaped. */
|
||||
static bool is_potential_cd_path(const wcstring &path, const wcstring &working_directory, path_flags_t flags, wcstring *out_path) {
|
||||
static bool is_potential_cd_path(const wcstring &path, const wcstring &working_directory, path_flags_t flags, wcstring *out_path)
|
||||
{
|
||||
wcstring_list_t directories;
|
||||
|
||||
if (string_prefixes_string(L"./", path)) {
|
||||
|
@ -807,7 +808,8 @@ bool autosuggest_suggest_special(const wcstring &str, const wcstring &working_di
|
|||
|
||||
/* Big hack to avoid expanding a tilde inside quotes */
|
||||
path_flags_t path_flags = (quote == L'\0') ? PATH_EXPAND_TILDE : 0;
|
||||
if (unescaped && is_potential_cd_path(unescaped_dir, working_directory, path_flags, &suggested_path)) {
|
||||
if (unescaped && is_potential_cd_path(unescaped_dir, working_directory, path_flags, &suggested_path))
|
||||
{
|
||||
|
||||
/* Note: this looks really wrong for strings that have an "unescapable" character in them, e.g. a \t, because parse_util_escape_string_with_quote will insert that character */
|
||||
wcstring escaped_suggested_path = parse_util_escape_string_with_quote(suggested_path, quote);
|
||||
|
@ -1351,16 +1353,22 @@ void highlight_shell( const wcstring &buff, std::vector<int> &color, size_t pos,
|
|||
{
|
||||
wcstring token(tok_begin, tok_end-tok_begin);
|
||||
const wcstring_list_t working_directory_list(1, working_directory);
|
||||
if (unescape_string(token, 1) && is_potential_path(token, working_directory_list, PATH_EXPAND_TILDE))
|
||||
{
|
||||
for( ptrdiff_t i=tok_begin-cbuff; i < (tok_end-cbuff); i++ )
|
||||
{
|
||||
// Don't color HIGHLIGHT_ERROR because it looks dorky. For example, trying to cd into a non-directory would show an underline and also red.
|
||||
if (! (color.at(i) & HIGHLIGHT_ERROR)) {
|
||||
color.at(i) |= HIGHLIGHT_VALID_PATH;
|
||||
if (unescape_string(token, 1))
|
||||
{
|
||||
/* Big hack: is_potential_path expects a tilde, but unescape_string gives us HOME_DIRECTORY. Put it back. */
|
||||
if (! token.empty() && token.at(0) == HOME_DIRECTORY)
|
||||
token.at(0) = L'~';
|
||||
if (is_potential_path(token, working_directory_list, PATH_EXPAND_TILDE))
|
||||
{
|
||||
for( ptrdiff_t i=tok_begin-cbuff; i < (tok_end-cbuff); i++ )
|
||||
{
|
||||
// Don't color HIGHLIGHT_ERROR because it looks dorky. For example, trying to cd into a non-directory would show an underline and also red.
|
||||
if (! (color.at(i) & HIGHLIGHT_ERROR)) {
|
||||
color.at(i) |= HIGHLIGHT_VALID_PATH;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue