diff options
author | 2014-09-22 21:30:44 -0700 | |
---|---|---|
committer | 2014-09-22 21:30:44 -0700 | |
commit | 5b33e6075283a4f0def2c87ccf789da824980f8a (patch) | |
tree | cfabe544ca416ef4f7f20260fe81dc78772aada3 /builtin.cpp | |
parent | 80078491bd1f3555051a64da6ec0daa397792f76 (diff) |
Support `bind SEQ` to print a binding for `SEQ`
Diffstat (limited to 'builtin.cpp')
-rw-r--r-- | builtin.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/builtin.cpp b/builtin.cpp index ab258acd..a8478c4f 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -516,23 +516,24 @@ static int get_terminfo_sequence(const wchar_t *seq, wcstring *out_seq) { return 1; } + wcstring eseq = escape_string(seq, 0); switch (errno) { case ENOENT: { - append_format(stderr_buffer, _(L"%ls: No key with name '%ls' found\n"), L"bind", seq); + append_format(stderr_buffer, _(L"%ls: No key with name '%ls' found\n"), L"bind", eseq.c_str()); break; } case EILSEQ: { - append_format(stderr_buffer, _(L"%ls: Key with name '%ls' does not have any mapping\n"), L"bind", seq); + append_format(stderr_buffer, _(L"%ls: Key with name '%ls' does not have any mapping\n"), L"bind", eseq.c_str()); break; } default: { - append_format(stderr_buffer, _(L"%ls: Unknown error trying to bind to key named '%ls'\n"), L"bind", seq); + append_format(stderr_buffer, _(L"%ls: Unknown error trying to bind to key named '%ls'\n"), L"bind", eseq.c_str()); break; } } @@ -763,8 +764,33 @@ static int builtin_bind(parser_t &parser, wchar_t **argv) case 1: { - res = STATUS_BUILTIN_ERROR; - append_format(stderr_buffer, _(L"%ls: Expected zero or at least two parameters, got %d\n"), argv[0], argc-woptind); + wcstring seq; + if (use_terminfo) + { + if (!get_terminfo_sequence(argv[woptind], &seq)) + { + res = STATUS_BUILTIN_ERROR; + // get_terminfo_sequence already printed the error + break; + } + } + else + { + seq = argv[woptind]; + } + if (!builtin_bind_list_one(seq, bind_mode)) + { + res = STATUS_BUILTIN_ERROR; + wcstring eseq = escape_string(argv[woptind], 0); + if (use_terminfo) + { + append_format(stderr_buffer, _(L"%ls: No binding found for key '%ls'\n"), argv[0], eseq.c_str()); + } + else + { + append_format(stderr_buffer, _(L"%ls: No binding found for sequence '%ls'\n"), argv[0], eseq.c_str()); + } + } break; } |