summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlum <lum@cvs.openbsd.org>2013-05-22 19:23:46 +0000
committerlum <lum@cvs.openbsd.org>2013-05-22 19:23:46 +0000
commit66c7d133da963b397a4082f7ef322af85691d672 (patch)
treec5a2caee1ab9cc57ffd543e0612d4f60910c4eb0
parent729a995971b16881ce84094346831442fe210c83 (diff)
Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@ Testing Sunil Nimmagadda
-rw-r--r--usr.bin/mg/def.h3
-rw-r--r--usr.bin/mg/funmap.c3
-rw-r--r--usr.bin/mg/keymap.c9
-rw-r--r--usr.bin/mg/mg.18
-rw-r--r--usr.bin/mg/region.c46
5 files changed, 56 insertions, 13 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 11aa3eaf167..90d1fcc723c 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.135 2013/03/25 11:41:44 florian Exp $ */
+/* $OpenBSD: def.h,v 1.136 2013/05/22 19:23:45 lum Exp $ */
/* This file is in the public domain. */
@@ -592,6 +592,7 @@ int region_get_data(struct region *, char *, int);
void region_put_data(const char *, int);
int markbuffer(int, int);
int piperegion(int, int);
+int shellcommand(int, int);
int pipeio(const char * const, char * const[], char * const, int,
struct buffer *);
diff --git a/usr.bin/mg/funmap.c b/usr.bin/mg/funmap.c
index a675b6ec1fc..e8bf7113a85 100644
--- a/usr.bin/mg/funmap.c
+++ b/usr.bin/mg/funmap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: funmap.c,v 1.45 2012/12/27 18:51:52 florian Exp $ */
+/* $OpenBSD: funmap.c,v 1.46 2013/05/22 19:23:45 lum Exp $ */
/* This file is in the public domain */
@@ -179,6 +179,7 @@ static struct funmap functnames[] = {
{setfillcol, "set-fill-column",},
{setmark, "set-mark-command",},
{setprefix, "set-prefix-string",},
+ {shellcommand, "shell-command",},
{piperegion, "shell-command-on-region",},
{shrinkwind, "shrink-window",},
#ifdef NOTAB
diff --git a/usr.bin/mg/keymap.c b/usr.bin/mg/keymap.c
index 94aead6560e..bd5cff15d4e 100644
--- a/usr.bin/mg/keymap.c
+++ b/usr.bin/mg/keymap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: keymap.c,v 1.50 2012/06/07 15:15:04 lum Exp $ */
+/* $OpenBSD: keymap.c,v 1.51 2013/05/22 19:23:45 lum Exp $ */
/* This file is in the public domain. */
@@ -217,8 +217,9 @@ static PF metacV[] = {
pagenext /* ^V */
};
-static PF metasp[] = {
- justone /* space */
+static PF metaspex[] = {
+ justone, /* space */
+ shellcommand /* ! */
};
static PF metapct[] = {
@@ -317,7 +318,7 @@ struct KEYMAPE (8 + IMAPEXT) metamap = {
CCHR('V'), CCHR('V'), metacV, NULL
},
{
- ' ', ' ', metasp, NULL
+ ' ', '!', metaspex, NULL
},
{
'%', '%', metapct, NULL
diff --git a/usr.bin/mg/mg.1 b/usr.bin/mg/mg.1
index 3c0df23fe1d..bf16c478c16 100644
--- a/usr.bin/mg/mg.1
+++ b/usr.bin/mg/mg.1
@@ -1,7 +1,7 @@
-.\" $OpenBSD: mg.1,v 1.75 2012/12/28 16:12:50 naddy Exp $
+.\" $OpenBSD: mg.1,v 1.76 2013/05/22 19:23:45 lum Exp $
.\" This file is in the public domain.
.\"
-.Dd $Mdocdate: December 28 2012 $
+.Dd $Mdocdate: May 22 2013 $
.Dt MG 1
.Os
.Sh NAME
@@ -268,6 +268,8 @@ suspend-emacs
scroll-other-window
.It M-SPC
just-one-space
+.It M-!
+shell-command
.It M-.
find-tag
.It M-*
@@ -835,6 +837,8 @@ Used by auto-fill-mode.
Sets the mark in the current window to the current dot location.
.It set-prefix-string
Sets the prefix string to be used by the 'prefix-region' command.
+.It shell-command
+Execute external command from mini-buffer.
.It shell-command-on-region
Provide the text in region to the shell command as input.
.It shrink-window
diff --git a/usr.bin/mg/region.c b/usr.bin/mg/region.c
index 80b65a5dcbd..4095cd5694e 100644
--- a/usr.bin/mg/region.c
+++ b/usr.bin/mg/region.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: region.c,v 1.32 2012/12/27 18:49:59 florian Exp $ */
+/* $OpenBSD: region.c,v 1.33 2013/05/22 19:23:45 lum Exp $ */
/* This file is in the public domain. */
@@ -28,6 +28,7 @@ static int iomux(int, char * const, int, struct buffer *);
static int preadin(int, struct buffer *);
static void pwriteout(int, char **, int *);
static int setsize(struct region *, RSIZE);
+static int shellcmdoutput(char * const[], char * const, int);
/*
* Kill the region. Ask "getregion" to figure out the bounds of the region.
@@ -406,9 +407,8 @@ int
piperegion(int f, int n)
{
struct region region;
- struct buffer *bp;
- int len, ret;
- char *cmd, cmdbuf[NFILEN], *shellp, *text;
+ int len;
+ char *cmd, cmdbuf[NFILEN], *text;
char *argv[] = {"sh", "-c", (char *) NULL, (char *) NULL};
/* C-u M-| is not supported yet */
@@ -436,6 +436,43 @@ piperegion(int f, int n)
return (FALSE);
}
+ region_get_data(&region, text, len);
+
+ return shellcmdoutput(argv, text, len);
+}
+
+/*
+ * Get command from mini-buffer and execute externally.
+ */
+/*ARGSUSED */
+int
+shellcommand(int f, int n)
+{
+
+ char *cmd, cmdbuf[NFILEN];
+ char *argv[] = {"sh", "-c", (char *) NULL, (char *) NULL};
+
+ if (n > 1)
+ return (ABORT);
+
+ if ((cmd = eread("Shell command: ", cmdbuf, sizeof(cmdbuf),
+ EFNEW | EFCR)) == NULL || (cmd[0] == '\0'))
+ return (ABORT);
+
+ argv[2] = cmd;
+
+ return shellcmdoutput(argv, NULL, 0);
+}
+
+
+int
+shellcmdoutput(char* const argv[], char* const text, int len)
+{
+
+ struct buffer *bp;
+ char *shellp;
+ int ret;
+
bp = bfind("*Shell Command Output*", TRUE);
bp->b_flag |= BFREADONLY;
if (bclear(bp) != TRUE) {
@@ -443,7 +480,6 @@ piperegion(int f, int n)
return (FALSE);
}
- region_get_data(&region, text, len);
shellp = getenv("SHELL");
ret = pipeio(shellp, argv, text, len, bp);