exec: add options "-rc"/"-norc" (display return code) in command /exec

This commit is contained in:
Sebastien Helleu 2014-03-13 07:56:20 +01:00
parent 571a7a5dbe
commit 0eca1fd20b
4 changed files with 21 additions and 4 deletions

View File

@ -255,6 +255,14 @@ exec_command_parse_options (struct t_exec_cmd_options *cmd_options,
{
cmd_options->line_numbers = 0;
}
else if (weechat_strcasecmp (argv[i], "-rc") == 0)
{
cmd_options->display_rc = 1;
}
else if (weechat_strcasecmp (argv[i], "-norc") == 0)
{
cmd_options->display_rc = 0;
}
else if (weechat_strcasecmp (argv[i], "-timeout") == 0)
{
if (i + 1 >= argc)
@ -318,6 +326,7 @@ exec_command_run (struct t_gui_buffer *buffer,
cmd_options.new_buffer = 0;
cmd_options.switch_to_buffer = 1;
cmd_options.line_numbers = -1;
cmd_options.display_rc = 1;
cmd_options.ptr_command_name = NULL;
/* parse default options */
@ -429,6 +438,7 @@ exec_command_run (struct t_gui_buffer *buffer,
}
new_exec_cmd->line_numbers = (cmd_options.line_numbers < 0) ?
cmd_options.new_buffer : cmd_options.line_numbers;
new_exec_cmd->display_rc = cmd_options.display_rc;
/* execute the command */
if (weechat_exec_plugin->debug >= 1)
@ -659,8 +669,8 @@ exec_command_init ()
N_("execute external commands"),
N_("-list"
" || [-sh|-nosh] [-bg|-nobg] [-stdin|-nostdin] [-buffer <name>] "
"[-l|-o|-n] |-sw|-nosw] [-ln|-noln] [-timeout <timeout>] "
"[-name <name>] <command>"
"[-l|-o|-n] |-sw|-nosw] [-ln|-noln] [-rc|-norc] "
"[-timeout <timeout>] [-name <name>] <command>"
" || -in <id> <text>"
" || -inclose <id> [<text>]"
" || -signal <id> <signal>"
@ -691,6 +701,8 @@ exec_command_init ()
" -nosw: don't switch to the output buffer\n"
" -ln: display line numbers (default in new buffer only)\n"
" -noln: don't display line numbers\n"
" -rc: display return code (default)\n"
" -norc: don't display return code\n"
"-timeout: set a timeout for the command (in seconds)\n"
" -name: set a name for the command (to name it later with /exec)\n"
" command: the command to execute; if beginning with \"url:\", the "

View File

@ -33,6 +33,7 @@ struct t_exec_cmd_options
int new_buffer; /* output in a new buffer */
int switch_to_buffer; /* switch to the output buffer */
int line_numbers; /* 1 to display line numbers */
int display_rc; /* 1 to display return code */
const char *ptr_command_name; /* name of command */
};

View File

@ -125,6 +125,7 @@ exec_add ()
new_exec_cmd->output_to_buffer = 0;
new_exec_cmd->buffer_full_name = NULL;
new_exec_cmd->line_numbers = 0;
new_exec_cmd->display_rc = 0;
new_exec_cmd->stdout_size = 0;
new_exec_cmd->stdout = NULL;
new_exec_cmd->stderr_size = 0;
@ -268,7 +269,8 @@ exec_end_command (struct t_exec_cmd *exec_cmd, int return_code)
* display return code (only if command is not detached and if output is
* NOT sent to buffer)
*/
if (!exec_cmd->detached && !exec_cmd->output_to_buffer)
if (!exec_cmd->detached && !exec_cmd->output_to_buffer
&& exec_cmd->display_rc)
{
if (return_code >= 0)
{
@ -434,6 +436,7 @@ exec_print_log ()
weechat_log_printf (" output_to_buffer. . . . : %d", ptr_exec_cmd->output_to_buffer);
weechat_log_printf (" buffer_full_name. . . . : '%s'", ptr_exec_cmd->buffer_full_name);
weechat_log_printf (" line_numbers. . . . . . : %d", ptr_exec_cmd->line_numbers);
weechat_log_printf (" display_rc. . . . . . . : %d", ptr_exec_cmd->display_rc);
weechat_log_printf (" stdout_size . . . . . . : %d", ptr_exec_cmd->stdout_size);
weechat_log_printf (" stdout. . . . . . . . . : '%s'", ptr_exec_cmd->stdout);
weechat_log_printf (" stderr_size . . . . . . : %d", ptr_exec_cmd->stderr_size);

View File

@ -37,10 +37,11 @@ struct t_exec_cmd
time_t start_time; /* start time */
time_t end_time; /* end time */
/* buffer */
/* display */
int output_to_buffer; /* 1 if output is sent to buffer */
char *buffer_full_name; /* buffer where output is displayed */
int line_numbers; /* 1 if lines numbers are displayed */
int display_rc; /* 1 if return code is displayed */
/* command output */
int stdout_size; /* number of bytes in stdout */