From 404fd75679938d37b1c6476aba06d8fa80036ca2 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 1 Dec 2016 16:20:42 -0500 Subject: [PATCH] added : shortcut for executing sed commands on selection --- libedit/exec.c | 4 ++-- xedit.c | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/libedit/exec.c b/libedit/exec.c index 403b7dd..be0ee21 100644 --- a/libedit/exec.c +++ b/libedit/exec.c @@ -87,7 +87,7 @@ void cmdwrite(char** cmd, char* text, char** err) { perror("failed to execute"); return; } - if (write(proc.in, text, strlen(text)) < 0) { + if (text && write(proc.in, text, strlen(text)) < 0) { perror("failed to write"); return; } @@ -102,7 +102,7 @@ char* cmdwriteread(char** cmd, char* text, char** err) { perror("failed to execute"); return NULL; } - if (write(proc.in, text, strlen(text)) < 0) { + if (text && write(proc.in, text, strlen(text)) < 0) { perror("failed to write"); return NULL; } diff --git a/xedit.c b/xedit.c index 793c088..5426b20 100644 --- a/xedit.c +++ b/xedit.c @@ -160,6 +160,7 @@ static char* PasteCmd[] = { "xsel", "-bo", NULL }; static char* ShellCmd[] = { "/bin/sh", "-c", NULL, NULL }; static char* PickFileCmd[] = { "xfilepick", ".", NULL }; static char* OpenCmd[] = { "xedit", NULL, NULL }; +static char* SedCmd[] = { "sed", "-e", NULL, NULL }; /* Main Routine *****************************************************************************/ @@ -523,7 +524,7 @@ static void tag_exec(Tag* tag, char* arg) { static void cmd_exec(char* cmd) { char op = '\0'; - if (*cmd == '!' || *cmd == '<' || *cmd == '|' || *cmd == '>') + if (*cmd == ':' || *cmd == '!' || *cmd == '<' || *cmd == '|' || *cmd == '>') op = *cmd, cmd++; ShellCmd[2] = cmd; /* execute the command */ @@ -531,11 +532,14 @@ static void cmd_exec(char* cmd) { enum RegionId dest = EDIT; input = view_getstr(getview(EDIT), NULL); if (op == '!') { - printf("null: '%s'\n", cmd); + cmdrun(ShellCmd, NULL); } else if (op == '>') { cmdwrite(ShellCmd, input, &error); } else if (op == '|') { output = cmdwriteread(ShellCmd, input, &error); + } else if (op == ':') { + SedCmd[2] = cmd; + output = cmdwriteread(SedCmd, input, &error); } else { if (op != '<') dest = Focused; output = cmdread(ShellCmd, &error); @@ -630,11 +634,3 @@ static enum RegionId getregion(size_t x, size_t y) { } return NREGIONS; } - -#if 0 -void move_pointer(size_t x, size_t y) { - x = (x * Fonts.base.width) + (Fonts.base.width / 2); - y = ((y+1) * Fonts.base.height) + (Fonts.base.height / 2); - x11_warp_mouse(x,y); -} -#endif -- 2.51.0