summaryrefslogtreecommitdiff
path: root/src/plugins/exec
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/exec')
-rw-r--r--src/plugins/exec/exec-buffer.c19
-rw-r--r--src/plugins/exec/exec-buffer.h2
-rw-r--r--src/plugins/exec/exec-command.c49
-rw-r--r--src/plugins/exec/exec-command.h3
-rw-r--r--src/plugins/exec/exec.c63
5 files changed, 110 insertions, 26 deletions
diff --git a/src/plugins/exec/exec-buffer.c b/src/plugins/exec/exec-buffer.c
index 1a4019fde..f8abd3295 100644
--- a/src/plugins/exec/exec-buffer.c
+++ b/src/plugins/exec/exec-buffer.c
@@ -116,13 +116,26 @@ exec_buffer_set_callbacks ()
*/
struct t_gui_buffer *
-exec_buffer_new (const char *name, int switch_to_buffer)
+exec_buffer_new (const char *name, int free_content, int clear_buffer,
+ int switch_to_buffer)
{
struct t_gui_buffer *new_buffer;
+ int buffer_type;
new_buffer = weechat_buffer_search (EXEC_PLUGIN_NAME, name);
if (new_buffer)
+ {
+ buffer_type = weechat_buffer_get_integer (new_buffer, "type");
+ if (((buffer_type == 0) && free_content)
+ || ((buffer_type == 1) && !free_content))
+ {
+ /* change the type of buffer */
+ weechat_buffer_set (new_buffer,
+ "type",
+ (free_content) ? "free" : "formatted");
+ }
goto end;
+ }
new_buffer = weechat_buffer_new (name,
&exec_buffer_input_cb, NULL,
@@ -132,6 +145,8 @@ exec_buffer_new (const char *name, int switch_to_buffer)
if (!new_buffer)
return NULL;
+ if (free_content)
+ weechat_buffer_set (new_buffer, "type", "free");
weechat_buffer_set (new_buffer, "title", _("Executed commands"));
weechat_buffer_set (new_buffer, "localvar_set_type", "exec");
weechat_buffer_set (new_buffer, "localvar_set_no_log", "1");
@@ -139,6 +154,8 @@ exec_buffer_new (const char *name, int switch_to_buffer)
weechat_buffer_set (new_buffer, "input_get_unknown_commands", "0");
end:
+ if (clear_buffer)
+ weechat_buffer_clear (new_buffer);
if (switch_to_buffer)
weechat_buffer_set (new_buffer, "display", "1");
diff --git a/src/plugins/exec/exec-buffer.h b/src/plugins/exec/exec-buffer.h
index 041c73720..fd4cbe9e6 100644
--- a/src/plugins/exec/exec-buffer.h
+++ b/src/plugins/exec/exec-buffer.h
@@ -22,6 +22,8 @@
extern void exec_buffer_set_callbacks ();
extern struct t_gui_buffer *exec_buffer_new (const char *name,
+ int free_content,
+ int clear_buffer,
int switch_to_buffer);
#endif /* WEECHAT_EXEC_BUFFER_H */
diff --git a/src/plugins/exec/exec-command.c b/src/plugins/exec/exec-command.c
index f46419203..d734d83bc 100644
--- a/src/plugins/exec/exec-command.c
+++ b/src/plugins/exec/exec-command.c
@@ -239,6 +239,19 @@ exec_command_parse_options (struct t_exec_cmd_options *cmd_options,
cmd_options->output_to_buffer = 0;
cmd_options->new_buffer = 1;
}
+ else if (weechat_strcasecmp (argv[i], "-nf") == 0)
+ {
+ cmd_options->output_to_buffer = 0;
+ cmd_options->new_buffer = 2;
+ }
+ else if (weechat_strcasecmp (argv[i], "-cl") == 0)
+ {
+ cmd_options->new_buffer_clear = 1;
+ }
+ else if (weechat_strcasecmp (argv[i], "-nocl") == 0)
+ {
+ cmd_options->new_buffer_clear = 0;
+ }
else if (weechat_strcasecmp (argv[i], "-sw") == 0)
{
cmd_options->switch_to_buffer = 1;
@@ -377,7 +390,7 @@ exec_command_run (struct t_gui_buffer *buffer,
struct t_exec_cmd_options cmd_options;
struct t_hashtable *process_options;
struct t_infolist *ptr_infolist;
- struct t_gui_buffer *new_buffer;
+ struct t_gui_buffer *ptr_new_buffer;
/* parse command options */
cmd_options.command_index = -1;
@@ -389,6 +402,7 @@ exec_command_run (struct t_gui_buffer *buffer,
cmd_options.ptr_buffer = buffer;
cmd_options.output_to_buffer = 0;
cmd_options.new_buffer = 0;
+ cmd_options.new_buffer_clear = 0;
cmd_options.switch_to_buffer = 1;
cmd_options.line_numbers = -1;
cmd_options.color = EXEC_COLOR_AUTO;
@@ -472,11 +486,15 @@ exec_command_run (struct t_gui_buffer *buffer,
new_exec_cmd->output_to_buffer = 0;
snprintf (str_buffer, sizeof (str_buffer),
"exec.%s", cmd_options.ptr_buffer_name);
- new_buffer = exec_buffer_new (str_buffer, cmd_options.switch_to_buffer);
- if (new_buffer)
+ ptr_new_buffer = exec_buffer_new (str_buffer,
+ (cmd_options.new_buffer == 2),
+ cmd_options.new_buffer_clear,
+ cmd_options.switch_to_buffer);
+ if (ptr_new_buffer)
{
new_exec_cmd->buffer_full_name =
- strdup (weechat_buffer_get_string (new_buffer, "full_name"));
+ strdup (weechat_buffer_get_string (ptr_new_buffer,
+ "full_name"));
}
}
else if (cmd_options.new_buffer)
@@ -492,11 +510,15 @@ exec_command_run (struct t_gui_buffer *buffer,
snprintf (str_buffer, sizeof (str_buffer),
"exec.%d", new_exec_cmd->number);
}
- new_buffer = exec_buffer_new (str_buffer, cmd_options.switch_to_buffer);
- if (new_buffer)
+ ptr_new_buffer = exec_buffer_new (str_buffer,
+ (cmd_options.new_buffer == 2),
+ cmd_options.new_buffer_clear,
+ cmd_options.switch_to_buffer);
+ if (ptr_new_buffer)
{
new_exec_cmd->buffer_full_name =
- strdup (weechat_buffer_get_string (new_buffer, "full_name"));
+ strdup (weechat_buffer_get_string (ptr_new_buffer,
+ "full_name"));
}
}
else if (cmd_options.ptr_buffer)
@@ -752,7 +774,7 @@ exec_command_init ()
N_("execute external commands"),
N_("-list"
" || [-sh|-nosh] [-bg|-nobg] [-stdin|-nostdin] [-buffer <name>] "
- "[-l|-o|-n] |-sw|-nosw] [-ln|-noln] "
+ "[-l|-o|-n|-nf] [-cl|-nocl] [-sw|-nosw] [-ln|-noln] "
"[-color ansi|auto|irc|weechat|strip] [-rc|-norc] "
"[-timeout <timeout>] [-name <name>] [-pipe <command>] "
"[-hsignal <name>] <command>"
@@ -783,6 +805,11 @@ exec_command_init ()
"(not compatible with option -bg)\n"
" -n: display output of command in a new buffer (not compatible "
"with option -bg)\n"
+ " -nf: display output of command in a new buffer with free "
+ "content (no word-wrap, no limit on number of lines) (not compatible "
+ "with option -bg)\n"
+ " -cl: clear the new buffer before displaying output\n"
+ " -nocl: append to the new buffer without clear (default)\n"
" -sw: switch to the output buffer (default)\n"
" -nosw: don't switch to the output buffer\n"
" -ln: display line numbers (default in new buffer only)\n"
@@ -830,11 +857,13 @@ exec_command_init ()
" /exec -n ls -l /tmp\n"
" /exec -n ps xu | grep weechat\n"
" /exec -n -norc url:http://pastebin.com/raw.php?i=xxxxxxxx\n"
+ " /exec -nf -noln links -dump "
+ "http://weechat.org/files/doc/devel/weechat_user.en.html\n"
" /exec -o uptime\n"
" /exec -pipe \"/print Machine uptime:\" uptime"),
"-list"
- " || -sh|-nosh|-bg|-nobg|-stdin|-nostdin|-buffer|-l|-o|-n|-sw|-nosw|"
- "-ln|-noln|-color|-timeout|-name|-pipe|-hsignal|%*"
+ " || -sh|-nosh|-bg|-nobg|-stdin|-nostdin|-buffer|-l|-o|-n|-nf|"
+ "-cl|-nocl|-sw|-nosw|-ln|-noln|-color|-timeout|-name|-pipe|-hsignal|%*"
" || -in|-inclose|-signal|-kill %(exec_commands_ids)"
" || -killall"
" || -set %(exec_commands_ids) stdin|stdin_close|signal"
diff --git a/src/plugins/exec/exec-command.h b/src/plugins/exec/exec-command.h
index 0e8e323f9..6b9e195d0 100644
--- a/src/plugins/exec/exec-command.h
+++ b/src/plugins/exec/exec-command.h
@@ -30,7 +30,8 @@ struct t_exec_cmd_options
const char *ptr_buffer_name; /* name of buffer */
struct t_gui_buffer *ptr_buffer; /* pointer to buffer */
int output_to_buffer; /* 1 if output is sent to buffer */
- int new_buffer; /* output in a new buffer */
+ int new_buffer; /* 1=new buffer, 2=new buf. free cont*/
+ int new_buffer_clear; /* 1 to clear buffer before output */
int switch_to_buffer; /* switch to the output buffer */
int line_numbers; /* 1 to display line numbers */
int color; /* what to do with ANSI colors */
diff --git a/src/plugins/exec/exec.c b/src/plugins/exec/exec.c
index 93fc18693..a91e52e62 100644
--- a/src/plugins/exec/exec.c
+++ b/src/plugins/exec/exec.c
@@ -352,11 +352,22 @@ exec_display_output (struct t_exec_cmd *exec_cmd,
"exec_%s,exec_cmd_%s",
(out) ? "stdout" : "stderr",
(exec_cmd->name) ? exec_cmd->name : str_number);
- snprintf (str_number, sizeof (str_number), "%d\t", line_nb);
- weechat_printf_tags (buffer, str_tags,
- "%s%s",
- (exec_cmd->line_numbers) ? str_number : " \t",
- line);
+ if (weechat_buffer_get_integer (buffer, "type") == 1)
+ {
+ snprintf (str_number, sizeof (str_number), "%d. ", line_nb);
+ weechat_printf_y (buffer, -1,
+ "%s%s",
+ (exec_cmd->line_numbers) ? str_number : " ",
+ line);
+ }
+ else
+ {
+ snprintf (str_number, sizeof (str_number), "%d\t", line_nb);
+ weechat_printf_tags (buffer, str_tags,
+ "%s%s",
+ (exec_cmd->line_numbers) ? str_number : " \t",
+ line);
+ }
}
free (line);
@@ -375,6 +386,7 @@ exec_end_command (struct t_exec_cmd *exec_cmd, int return_code)
struct t_gui_buffer *ptr_buffer;
struct t_hashtable *hashtable;
char str_number[32], *output;
+ int buffer_type;
if (exec_cmd->hsignal)
{
@@ -418,21 +430,44 @@ exec_end_command (struct t_exec_cmd *exec_cmd, int return_code)
&& !exec_cmd->detached && !exec_cmd->output_to_buffer
&& !exec_cmd->pipe_command)
{
+ buffer_type = weechat_buffer_get_integer (ptr_buffer, "type");
if (return_code >= 0)
{
- weechat_printf_tags (ptr_buffer, "exec_rc",
- _("%s: end of command %d (\"%s\"), "
+ if (buffer_type == 1)
+ {
+ weechat_printf_y (ptr_buffer, -1,
+ ("%s: end of command %d (\"%s\"), "
"return code: %d"),
- EXEC_PLUGIN_NAME, exec_cmd->number,
- exec_cmd->command, return_code);
+ EXEC_PLUGIN_NAME, exec_cmd->number,
+ exec_cmd->command, return_code);
+ }
+ else
+ {
+ weechat_printf_tags (ptr_buffer, "exec_rc",
+ _("%s: end of command %d (\"%s\"), "
+ "return code: %d"),
+ EXEC_PLUGIN_NAME, exec_cmd->number,
+ exec_cmd->command, return_code);
+ }
}
else
{
- weechat_printf_tags (ptr_buffer, "exec_rc",
- _("%s: unexpected end of command %d "
- "(\"%s\")"),
- EXEC_PLUGIN_NAME, exec_cmd->number,
- exec_cmd->command);
+ if (buffer_type == 1)
+ {
+ weechat_printf_y (ptr_buffer, -1,
+ _("%s: unexpected end of command %d "
+ "(\"%s\")"),
+ EXEC_PLUGIN_NAME, exec_cmd->number,
+ exec_cmd->command);
+ }
+ else
+ {
+ weechat_printf_tags (ptr_buffer, "exec_rc",
+ _("%s: unexpected end of command %d "
+ "(\"%s\")"),
+ EXEC_PLUGIN_NAME, exec_cmd->number,
+ exec_cmd->command);
+ }
}
}
}