diff --git a/bashline.c b/bashline.c index 3cbb18f..31841fa 100644 --- a/bashline.c +++ b/bashline.c @@ -3478,8 +3478,9 @@ quote_word_break_chars (text) if (mbschr (rl_completer_word_break_characters, *s)) *r++ = '\\'; /* XXX -- check for standalone tildes here and backslash-quote them */ - if (s == text && *s == '~' && file_exists (text)) + if (s == text && *s == '~' && tilde_file_exists (text)) { *r++ = '\\'; + } *r++ = *s; } *r = '\0'; diff --git a/general.c b/general.c index fdadf1d..b279cbe 100644 --- a/general.c +++ b/general.c @@ -544,6 +544,28 @@ file_exists (fn) } int +tilde_file_exists (fn) + char *fn; +{ + struct stat sb; + char *slash, *dirpart; + int istildedir; + + istildedir = 0; + + slash = strchr (fn, '/'); + if ((slash != 0) && (slash != fn)) + { + dirpart = (char *)xmalloc ((slash - fn) + 1); + strncpy (dirpart, fn, (slash - fn) + 1); + istildedir = file_isdir (dirpart); + free (dirpart); + } + + return (!((slash != 0) && (slash != fn) && ! istildedir) && (stat (fn, &sb) == 0)); +} + +int file_isdir (fn) char *fn; { diff --git a/general.h b/general.h index 2b31c58..f6b7ab4 100644 --- a/general.h +++ b/general.h @@ -302,6 +302,7 @@ extern int sh_openpipe __P((int *)); extern int sh_closepipe __P((int *)); extern int file_exists __P((char *)); +extern int tilde_file_exists __P((char *)); extern int file_isdir __P((char *)); extern int file_iswdir __P((char *)); extern int dot_or_dotdot __P((const char *));