summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/exec/exec-command.c18
-rw-r--r--src/plugins/exec/exec-command.h1
-rw-r--r--src/plugins/exec/exec.c26
-rw-r--r--src/plugins/exec/exec.h1
4 files changed, 40 insertions, 6 deletions
diff --git a/src/plugins/exec/exec-command.c b/src/plugins/exec/exec-command.c
index c56b540b4..97f318f01 100644
--- a/src/plugins/exec/exec-command.c
+++ b/src/plugins/exec/exec-command.c
@@ -247,6 +247,14 @@ exec_command_parse_options (struct t_exec_cmd_options *cmd_options,
{
cmd_options->switch_to_buffer = 0;
}
+ else if (weechat_strcasecmp (argv[i], "-ln") == 0)
+ {
+ cmd_options->line_numbers = 1;
+ }
+ else if (weechat_strcasecmp (argv[i], "-noln") == 0)
+ {
+ cmd_options->line_numbers = 0;
+ }
else if (weechat_strcasecmp (argv[i], "-timeout") == 0)
{
if (i + 1 >= argc)
@@ -464,6 +472,7 @@ exec_command_exec (void *data, struct t_gui_buffer *buffer, int argc,
cmd_options.output_to_buffer = 0;
cmd_options.new_buffer = 0;
cmd_options.switch_to_buffer = 1;
+ cmd_options.line_numbers = -1;
cmd_options.ptr_command_name = NULL;
/* parse default options */
@@ -567,6 +576,8 @@ exec_command_exec (void *data, struct t_gui_buffer *buffer, int argc,
if (cmd_options.switch_to_buffer)
weechat_buffer_set (cmd_options.ptr_buffer, "display", "1");
}
+ new_exec_cmd->line_numbers = (cmd_options.line_numbers < 0) ?
+ cmd_options.new_buffer : cmd_options.line_numbers;
/* execute the command */
if (weechat_exec_plugin->debug >= 1)
@@ -624,7 +635,8 @@ exec_command_init ()
N_("execute external commands"),
N_("-list"
" || [-sh|-nosh] [-bg|-nobg] [-stdin|-nostdin] [-buffer <name>] "
- "[-l|-o|-n] |-sw|-nosw] [-timeout <timeout>] [-name <name>] <command>"
+ "[-l|-o|-n] |-sw|-nosw] [-ln|-noln] [-timeout <timeout>] "
+ "[-name <name>] <command>"
" || -in <id> <text>"
" || -inclose <id> [<text>]"
" || -signal <id> <signal>"
@@ -653,6 +665,8 @@ exec_command_init ()
"with -bg)\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"
+ " -noln: don't display line numbers\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 "
@@ -678,7 +692,7 @@ exec_command_init ()
"exec.command.default_options."),
"-list"
" || -sh|-nosh|-bg|-nobg|-stdin|-nostdin|-buffer|-l|-o|-n|-sw|-nosw|"
- "-timeout|-name|%*"
+ "-ln|-noln|-timeout|-name|%*"
" || -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 4984c1a49..680d60be3 100644
--- a/src/plugins/exec/exec-command.h
+++ b/src/plugins/exec/exec-command.h
@@ -32,6 +32,7 @@ struct t_exec_cmd_options
int output_to_buffer; /* 1 if output is sent to buffer */
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 */
const char *ptr_command_name; /* name of command */
};
diff --git a/src/plugins/exec/exec.c b/src/plugins/exec/exec.c
index ec7ebe870..aea5d0454 100644
--- a/src/plugins/exec/exec.c
+++ b/src/plugins/exec/exec.c
@@ -124,6 +124,7 @@ exec_add ()
new_exec_cmd->end_time = 0;
new_exec_cmd->output_to_buffer = 0;
new_exec_cmd->buffer_full_name = NULL;
+ new_exec_cmd->line_numbers = 0;
new_exec_cmd->stdout_size = 0;
new_exec_cmd->stdout = NULL;
new_exec_cmd->stderr_size = 0;
@@ -193,8 +194,8 @@ void
exec_command_display_output (struct t_exec_cmd *exec_cmd,
struct t_gui_buffer *buffer, int stdout)
{
- char *ptr_output, **lines, str_number[32], str_tags[1024];
- int i, num_lines;
+ char *ptr_output, **lines, *line, str_number[32], str_tags[1024];
+ int i, num_lines, length;
ptr_output = (stdout) ? exec_cmd->stdout : exec_cmd->stderr;
if (!ptr_output)
@@ -214,17 +215,33 @@ exec_command_display_output (struct t_exec_cmd *exec_cmd,
for (i = 0; i < num_lines; i++)
{
if (exec_cmd->output_to_buffer)
- weechat_command (buffer, lines[i]);
+ {
+ if (exec_cmd->line_numbers)
+ {
+ length = 32 + strlen (lines[i]) + 1;
+ line = malloc (length);
+ if (line)
+ {
+ snprintf (line, length, "%d. %s", i + 1, lines[i]);
+ weechat_command (buffer, line);
+ free (line);
+ }
+ }
+ else
+ weechat_command (buffer, lines[i]);
+ }
else
{
+
snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number);
snprintf (str_tags, sizeof (str_tags),
"exec_%s,exec_cmd_%s",
(stdout) ? "stdout" : "stderr",
(exec_cmd->name) ? exec_cmd->name : str_number);
+ snprintf (str_number, sizeof (str_number), "%d\t", i + 1);
weechat_printf_tags (buffer, str_tags,
"%s%s",
- (stdout) ? " \t" : weechat_prefix ("error"),
+ (exec_cmd->line_numbers) ? str_number : " \t",
lines[i]);
}
}
@@ -416,6 +433,7 @@ exec_print_log ()
weechat_log_printf (" end_time. . . . . . . . : %ld", ptr_exec_cmd->end_time);
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 (" 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);
diff --git a/src/plugins/exec/exec.h b/src/plugins/exec/exec.h
index 0b5d2f94c..5ae32708f 100644
--- a/src/plugins/exec/exec.h
+++ b/src/plugins/exec/exec.h
@@ -40,6 +40,7 @@ struct t_exec_cmd
/* buffer */
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 */
/* command output */
int stdout_size; /* number of bytes in stdout */