tabcomplete ~ and ~foo like $FOO (idea by yofuh)

This commit is contained in:
tg 2011-06-30 13:48:13 +00:00
parent 535649cc60
commit edaab2cafe
3 changed files with 17 additions and 14 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.468 2011/06/21 21:50:23 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.469 2011/06/30 13:48:09 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -25,7 +25,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh # http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R40 2011/06/21 @(#)MIRBSD KSH R40 2011/06/30
description: description:
Check version of shell. Check version of shell.
stdin: stdin:

23
edit.c
View File

@ -25,7 +25,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.215 2011/06/04 16:44:30 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.216 2011/06/30 13:48:12 tg Exp $");
/* /*
* in later versions we might use libtermcap for this, but since external * in later versions we might use libtermcap for this, but since external
@ -58,7 +58,7 @@ static X_chars edchars;
#define XCF_FULLPATH BIT(2) /* command completion: store full path */ #define XCF_FULLPATH BIT(2) /* command completion: store full path */
#define XCF_COMMAND_FILE (XCF_COMMAND | XCF_FILE) #define XCF_COMMAND_FILE (XCF_COMMAND | XCF_FILE)
#define XCF_IS_COMMAND BIT(3) /* return flag: is command */ #define XCF_IS_COMMAND BIT(3) /* return flag: is command */
#define XCF_IS_VARSUB BIT(4) /* return flag: is $FOO substitution */ #define XCF_IS_SUBGLOB BIT(4) /* return flag: is $FOO or ~foo substitution */
#define XCF_IS_EXTGLOB BIT(5) /* return flag: is foo* expansion */ #define XCF_IS_EXTGLOB BIT(5) /* return flag: is foo* expansion */
static char editmode; static char editmode;
@ -574,10 +574,10 @@ x_cf_glob(int *flagsp, const char *buf, int buflen, int pos, int *startp,
* a parameter expansion as we have a glob * a parameter expansion as we have a glob
*/ */
*flagsp |= XCF_IS_EXTGLOB; *flagsp |= XCF_IS_EXTGLOB;
} else if (saw_dollar) { } else if (saw_dollar || *toglob == '~') {
/* do not append a glob, nor later a space */ /* do not append a glob, nor later a space */
*flagsp |= XCF_IS_VARSUB; *flagsp |= XCF_IS_SUBGLOB;
} else if (*toglob != '~' || saw_slash) { } else if (saw_slash) {
/* append a glob, this is not just a tilde */ /* append a glob, this is not just a tilde */
toglob[len] = '*'; toglob[len] = '*';
toglob[len + 1] = '\0'; toglob[len + 1] = '\0';
@ -2701,9 +2701,12 @@ do_complete(
x_adjust(); x_adjust();
completed = true; completed = true;
} }
/* add space if single non-dir match and not parameter substitution */ /*
* append a space if this is a single non-directory match
* and not a parameter or homedir substitution
*/
if (nwords == 1 && words[0][nlen - 1] != '/' && if (nwords == 1 && words[0][nlen - 1] != '/' &&
!(flags & XCF_IS_VARSUB)) { !(flags & XCF_IS_SUBGLOB)) {
x_ins(" "); x_ins(" ");
completed = true; completed = true;
} }
@ -5254,11 +5257,11 @@ complete_word(int cmd, int count)
expanded = NONE; expanded = NONE;
/* /*
* append a space if this is not a directory or the * append a space if this is a non-directory match
* result of a parameter substitution * and not a parameter or homedir substitution
*/ */
if (match_len > 0 && match[match_len - 1] != '/' && if (match_len > 0 && match[match_len - 1] != '/' &&
!(flags & XCF_IS_VARSUB)) !(flags & XCF_IS_SUBGLOB))
rval = putbuf(" ", 1, 0); rval = putbuf(" ", 1, 0);
} }
x_free_words(nwords, words); x_free_words(nwords, words);

4
sh.h
View File

@ -151,9 +151,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.479 2011/06/21 21:50:25 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.480 2011/06/30 13:48:13 tg Exp $");
#endif #endif
#define MKSH_VERSION "R40 2011/06/21" #define MKSH_VERSION "R40 2011/06/30"
#ifndef MKSH_INCLUDES_ONLY #ifndef MKSH_INCLUDES_ONLY