move some functions to make it more clear how to configure custom functions. - … | |
git clone git://git.codemadness.org/sob | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 9de4bb2f6a8ec555ef56e447e6e7eec995f57873 | |
parent e2dc0e68998bb673bfe3d57aa0149cfb28a85c2b | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Thu, 2 Oct 2014 01:28:25 +0000 | |
move some functions to make it more clear how to configure custom | |
functions. | |
Diffstat: | |
M config.def.h | 22 ++++++++++++++++++++-- | |
M sob.c | 60 ++++++++++++-----------------… | |
2 files changed, 43 insertions(+), 39 deletions(-) | |
--- | |
diff --git a/config.def.h b/config.def.h | |
@@ -1,9 +1,27 @@ | |
static const char *prompt = "> "; | |
-static const char *completewordcmd[] = { "/bin/sh", "-c", "$HOME/.sob/scripts/… | |
+static const char *completenickcmd[] = { "/bin/sh", "-c", "$HOME/.sob/scripts/… | |
static const char *historycmd[] = { "/bin/sh", "-c", "$HOME/.sob/scripts/… | |
static const char *yankcmd[] = { "/bin/sh", "-c", "/bin/xsel -i -p", … | |
static const char *resizecmd = "tmux resize-pane -y 4 2> /dev/null"; | |
+static void | |
+line_yank(void) | |
+{ | |
+ line_pipeto((char**)yankcmd); | |
+} | |
+ | |
+static void | |
+history_menu(void) | |
+{ | |
+ line_pipeto((char**)historycmd); | |
+} | |
+ | |
+static void | |
+complete_nick(void) | |
+{ | |
+ line_wordpipeto((char**)completenickcmd); | |
+} | |
+ | |
static struct keybind { | |
int key; | |
void (*func)(void); | |
@@ -37,5 +55,5 @@ static struct keybind { | |
{ KEY_DOWN, history_menu }, | |
{ CONTROL('P'), history_menu }, | |
{ CONTROL('N'), history_menu }, | |
- { '\t', complete_word }, | |
+ { '\t', complete_nick }, | |
}; | |
diff --git a/sob.c b/sob.c | |
@@ -54,9 +54,7 @@ static void line_prompt(void); | |
static int line_pipeto(char **cmd); | |
static void line_redraw(size_t max); | |
static void line_set(const char *s); | |
-static void line_yank(void); | |
-static void history_menu(void); | |
-static void complete_word(void); | |
+static void line_wordpipeto(char **cmd); | |
static int pipereadline(int fd_in, int fd_out, char *writestr, char *outbuf, | |
size_t outbufsiz); | |
static int pipecmd(char *cmd[], char *writestr, char *outbuf, | |
@@ -323,40 +321,6 @@ line_copywordcursor(char *buf, size_t bufsiz) | |
buf[len + 1] = '\0'; | |
} | |
-static void | |
-complete_word(void) | |
-{ | |
- char wordbuf[BUFSIZ], outbuf[BUFSIZ]; | |
- size_t oldlen = line.len; | |
- | |
- outbuf[0] = '\0'; | |
- wordbuf[0] = '\0'; | |
- line_copywordcursor(wordbuf, sizeof(wordbuf)); | |
- | |
- if(pipecmd((char**)completewordcmd, wordbuf, outbuf, | |
- sizeof(outbuf)) == -1) | |
- return; | |
- if(outbuf[0] == '\0') | |
- return; | |
- | |
- line_delwordcursor(); | |
- line_inserttext(outbuf); | |
- line_redraw(MAX(line.len, oldlen)); | |
- line_cursor_update(); | |
-} | |
- | |
-static void | |
-line_yank(void) | |
-{ | |
- line_pipeto((char**)yankcmd); | |
-} | |
- | |
-static void | |
-history_menu(void) | |
-{ | |
- line_pipeto((char**)historycmd); | |
-} | |
- | |
static int | |
pipereadline(int fd_in, int fd_out, char *writestr, char *outbuf, | |
size_t outbufsiz) | |
@@ -479,6 +443,28 @@ line_pipeto(char **cmd) | |
} | |
static void | |
+line_wordpipeto(char **cmd) | |
+{ | |
+ char wordbuf[BUFSIZ], outbuf[BUFSIZ]; | |
+ size_t oldlen = line.len; | |
+ | |
+ outbuf[0] = '\0'; | |
+ wordbuf[0] = '\0'; | |
+ line_copywordcursor(wordbuf, sizeof(wordbuf)); | |
+ | |
+ if(pipecmd((char**)cmd, wordbuf, outbuf, | |
+ sizeof(outbuf)) == -1) | |
+ return; | |
+ if(outbuf[0] == '\0') | |
+ return; | |
+ | |
+ line_delwordcursor(); | |
+ line_inserttext(outbuf); | |
+ line_redraw(MAX(line.len, oldlen)); | |
+ line_cursor_update(); | |
+} | |
+ | |
+static void | |
sighandler(int signum) | |
{ | |
if(signum == SIGTERM) { |