Skip to content

Commit 4a3d90a

Browse files
committedJul 26, 2017
external cmd opt flag + for "echo first line"
to status bar.
1 parent f51f8fc commit 4a3d90a

File tree

8 files changed

+36
-14
lines changed

8 files changed

+36
-14
lines changed
 

‎doc/tigrc.5.adoc

+5
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ the command that should be executed.
640640
|=============================================================================
641641
|! |Run the command in the foreground with output shown.
642642
|@ |Run the command in the background with no output.
643+
|+ |Run the command synchronously, and echo the first line
644+
of output to the status bar.
643645
|? |Prompt the user before executing the command.
644646
|< |Exit Tig after executing the command.
645647
|=============================================================================
@@ -704,6 +706,9 @@ bind main S !git format-patch -1 %(commit)
704706
705707
# Create and checkout a new branch; specify custom prompt
706708
bind main B ?git checkout -b "%(prompt Enter new branch name: )"
709+
710+
# Show commit statistics for the author under the cursor
711+
bind main U +sh -c 'git --no-pager shortlog -s --author="$(git show -s --format=%aE %(commit))" </dev/tty'
707712
--------------------------------------------------------------------------
708713

709714
Advanced shell-like commands

‎include/tig/display.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bool save_view(struct view *view, const char *path);
5252
bool vertical_split_is_enabled(enum vertical_split vsplit, int height, int width);
5353
int apply_vertical_split(int base_width);
5454

55-
bool open_external_viewer(const char *argv[], const char *dir, bool silent, bool confirm, bool refresh, const char *notice);
55+
bool open_external_viewer(const char *argv[], const char *dir, bool silent, bool confirm, bool echo, bool refresh, const char *notice);
5656
void open_editor(const char *file, unsigned int lineno);
5757
void enable_mouse(bool enable);
5858

‎include/tig/keys.h

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct run_request_flags {
8282
bool confirm;
8383
bool exit;
8484
bool internal;
85+
bool echo;
8586
};
8687

8788
struct run_request {

‎src/display.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,22 @@ open_script(const char *path)
5656
}
5757

5858
bool
59-
open_external_viewer(const char *argv[], const char *dir, bool silent, bool confirm, bool refresh, const char *notice)
59+
open_external_viewer(const char *argv[], const char *dir, bool silent, bool confirm, bool echo, bool refresh, const char *notice)
6060
{
6161
bool ok;
6262

63-
if (silent || is_script_executing()) {
63+
if (echo) {
64+
char buf[SIZEOF_STR] = "";
65+
66+
io_run_buf(argv, buf, sizeof(buf), dir, false);
67+
if (*buf) {
68+
report("%s", buf);
69+
return true;
70+
} else {
71+
report("No output");
72+
return false;
73+
}
74+
} else if (silent || is_script_executing()) {
6475
ok = io_run_bg(argv, dir);
6576

6677
} else {
@@ -127,7 +138,7 @@ open_editor(const char *file, unsigned int lineno)
127138
if (lineno && opt_editor_line_number && string_format(lineno_cmd, "+%u", lineno))
128139
editor_argv[argc++] = lineno_cmd;
129140
editor_argv[argc] = file;
130-
if (!open_external_viewer(editor_argv, repo.cdup, false, false, true, EDITOR_LINENO_MSG))
141+
if (!open_external_viewer(editor_argv, repo.cdup, false, false, false, true, EDITOR_LINENO_MSG))
131142
opt_editor_line_number = false;
132143
}
133144

‎src/keys.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ static size_t run_requests;
450450

451451
DEFINE_ALLOCATOR(realloc_run_requests, struct run_request, 8)
452452

453-
#define COMMAND_FLAGS ":!?@<"
453+
#define COMMAND_FLAGS ":!?@<+"
454454

455455
enum status_code
456456
parse_run_request_flags(struct run_request_flags *flags, const char **argv)
@@ -469,6 +469,8 @@ parse_run_request_flags(struct run_request_flags *flags, const char **argv)
469469
flags->confirm = 1;
470470
} else if (*argv[0] == '<') {
471471
flags->exit = 1;
472+
} else if (*argv[0] == '+') {
473+
flags->echo = 1;
472474
} else if (*argv[0] != '!') {
473475
break;
474476
}
@@ -529,6 +531,8 @@ format_run_request_flags(const struct run_request *req)
529531
flags[flagspos++] = '?';
530532
if (req->flags.exit)
531533
flags[flagspos++] = '<';
534+
if (req->flags.echo)
535+
flags[flagspos++] = '+';
532536
if (flagspos > 1)
533537
flags[flagspos++] = 0;
534538

‎src/prompt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ exec_run_request(struct view *view, struct run_request *req)
10431043

10441044
if (confirmed)
10451045
open_external_viewer(argv, repo.cdup, req->flags.silent,
1046-
!req->flags.exit, false, "");
1046+
!req->flags.exit, req->flags.echo, false, "");
10471047
}
10481048

10491049
if (argv)

‎src/status.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ open_mergetool(const char *file)
676676
{
677677
const char *mergetool_argv[] = { "git", "mergetool", file, NULL };
678678

679-
open_external_viewer(mergetool_argv, repo.cdup, false, true, true, "");
679+
open_external_viewer(mergetool_argv, repo.cdup, false, true, false, true, "");
680680
}
681681

682682
static enum request

‎test/tigrc/parse-test

+8-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ bind main 1 !external command
5252
bind main 2 @silent command
5353
bind main 3 ?prompted command
5454
bind main 4 <quitting command
55-
bind main 0 !@?<all modifiers
55+
bind main 5 +echoed command
56+
bind main 0 !@?<+all modifiers
5657
5758
# Non-ending multi-line command
5859
c\\
@@ -98,9 +99,9 @@ tig warning: ~/.tigrc:25: Unknown color attribute: normally
9899
tig warning: ~/.tigrc:34: Unknown option \`visibility' for column line-number
99100
tig warning: ~/.tigrc:36: Invalid key binding: bind keymap key action
100101
tig warning: ~/.tigrc:37: Invalid key binding: bind keymap key action
101-
tig warning: ~/.tigrc:38: Unknown command flag '%'; expected one of :!?@<
102-
tig warning: ~/.tigrc:39: Unknown command flag '|'; expected one of :!?@<
103-
tig warning: ~/.tigrc:56: Unknown option command: c
102+
tig warning: ~/.tigrc:38: Unknown command flag '%'; expected one of :!?@<+
103+
tig warning: ~/.tigrc:39: Unknown command flag '|'; expected one of :!?@<+
104+
tig warning: ~/.tigrc:57: Unknown option command: c
104105
tig warning: Errors while loading HOME/.tigrc.
105106
EOF
106107

@@ -120,7 +121,8 @@ External commands:
120121
2 @silent command
121122
3 ?prompted command
122123
4 <quitting command
123-
0 @?<all modifiers
124+
5 +echoed command
125+
0 @?<+all modifiers
124126
125127
126128
@@ -132,6 +134,5 @@ External commands:
132134
133135
134136
135-
136-
[help] - line 1 of 16 100%
137+
[help] - line 1 of 17 100%
137138
EOF

0 commit comments

Comments
 (0)
Please sign in to comment.