mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 15:53:12 +02:00
exec: add options -nf and -cl/-nocl in command /exec
-nf: create a new buffer with free content -cl: clear new buffer -nocl: append in new buffer
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 */
|
||||
|
||||
+49
-14
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user