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: 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 $
@ -25,7 +25,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R40 2011/06/21
@(#)MIRBSD KSH R40 2011/06/30
description:
Check version of shell.
stdin:

23
edit.c
View File

@ -25,7 +25,7 @@
#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
@ -58,7 +58,7 @@ static X_chars edchars;
#define XCF_FULLPATH BIT(2) /* command completion: store full path */
#define XCF_COMMAND_FILE (XCF_COMMAND | XCF_FILE)
#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 */
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
*/
*flagsp |= XCF_IS_EXTGLOB;
} else if (saw_dollar) {
} else if (saw_dollar || *toglob == '~') {
/* do not append a glob, nor later a space */
*flagsp |= XCF_IS_VARSUB;
} else if (*toglob != '~' || saw_slash) {
*flagsp |= XCF_IS_SUBGLOB;
} else if (saw_slash) {
/* append a glob, this is not just a tilde */
toglob[len] = '*';
toglob[len + 1] = '\0';
@ -2701,9 +2701,12 @@ do_complete(
x_adjust();
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] != '/' &&
!(flags & XCF_IS_VARSUB)) {
!(flags & XCF_IS_SUBGLOB)) {
x_ins(" ");
completed = true;
}
@ -5254,11 +5257,11 @@ complete_word(int cmd, int count)
expanded = NONE;
/*
* append a space if this is not a directory or the
* result of a parameter substitution
* append a space if this is a non-directory match
* and not a parameter or homedir substitution
*/
if (match_len > 0 && match[match_len - 1] != '/' &&
!(flags & XCF_IS_VARSUB))
!(flags & XCF_IS_SUBGLOB))
rval = putbuf(" ", 1, 0);
}
x_free_words(nwords, words);

4
sh.h
View File

@ -151,9 +151,9 @@
#endif
#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
#define MKSH_VERSION "R40 2011/06/21"
#define MKSH_VERSION "R40 2011/06/30"
#ifndef MKSH_INCLUDES_ONLY