1
0
Fork 0
forked from murx/murx

Made -p more comfortable. Now uses just a letter instead of the C- prefix.

This commit is contained in:
Johannes Findeisen 2026-11-15 23:24:20 +01:00
commit 435d8e6092
2 changed files with 11 additions and 12 deletions

View file

@ -7,7 +7,7 @@ dependencies.
make -B CC=clang make -B CC=clang
./moerx # session "0" ./moerx # session "0"
./moerx work # separate named session ./moerx work # separate named session
./moerx -p C-x work # use Ctrl-X as this client's prefix ./moerx -p x work # use Ctrl-X as this client's prefix
./moerx --help # all shortcuts ./moerx --help # all shortcuts
``` ```
@ -16,13 +16,13 @@ Detach with `Ctrl-A d`. Run `moerx` again to reattach.
Every shortcut is a chain that starts with the prefix (by default `Ctrl-A`): Every shortcut is a chain that starts with the prefix (by default `Ctrl-A`):
press it, release it, then press the rest of the chain. press it, release it, then press the rest of the chain.
Use `-p C-x` or `--prefix C-x` to choose Ctrl-X instead. Control letters Use `-p x` or `--prefix x` to choose Ctrl-X instead. Letters
`C-a` through `C-z` are supported, case-insensitively. The choice applies to `a` through `z` select Ctrl-A through Ctrl-Z, case-insensitively. The choice applies to
this attached client; use the option again when reattaching, or set a shell this attached client; use the option again when reattaching, or set a shell
alias such as `alias moerx='moerx -p C-x'`. Clients attached to the same session alias such as `alias moerx='moerx -p x'`. Clients attached to the same session
can choose different prefixes. can choose different prefixes.
With `-p C-x`, detach with `Ctrl-X d`, send a literal Ctrl-X with `Ctrl-X a`, With `-p x`, detach with `Ctrl-X d`, send a literal Ctrl-X with `Ctrl-X a`,
and switch to the last window with `Ctrl-X Ctrl-X`. Doubling the prefix takes and switch to the last window with `Ctrl-X Ctrl-X`. Doubling the prefix takes
priority over any other control-key binding; `Ctrl-X x` still locks the client. priority over any other control-key binding; `Ctrl-X x` still locks the client.
Ctrl-A is sent straight to the pane. All tables below show the default prefix; Ctrl-A is sent straight to the pane. All tables below show the default prefix;

13
moerx.c
View file

@ -3838,14 +3838,14 @@ static int run_client(int fd, const char *name, unsigned char prefix) {
static void print_help(FILE *out) { static void print_help(FILE *out) {
fprintf(out, fprintf(out,
"usage: moerx [-p C-key] [session]\n" "usage: moerx [-p letter] [session]\n"
" moerx -h | --help\n" " moerx -h | --help\n"
"\n" "\n"
"Attach to a running session, or start it if it is not running.\n" "Attach to a running session, or start it if it is not running.\n"
"The session name defaults to \"0\".\n" "The session name defaults to \"0\".\n"
"\n" "\n"
"Use -p C-x (or --prefix C-x) to choose Ctrl-X as this client's prefix.\n" "Use -p x (or --prefix x) to choose Ctrl-X as this client's prefix.\n"
"Keys C-a through C-z are supported; the default is C-a.\n" "Letters a through z are supported (case-insensitive); the default is a (Ctrl-A).\n"
"The shortcuts below use the default Ctrl-A prefix. Replace it with\n" "The shortcuts below use the default Ctrl-A prefix. Replace it with\n"
"your chosen prefix, including both keys in the last-window shortcut.\n" "your chosen prefix, including both keys in the last-window shortcut.\n"
"Prefix then a sends the chosen prefix literally to the pane.\n" "Prefix then a sends the chosen prefix literally to the pane.\n"
@ -3903,9 +3903,8 @@ static void print_help(FILE *out) {
} }
static int parse_prefix(const char *text, unsigned char *prefix) { static int parse_prefix(const char *text, unsigned char *prefix) {
if (!text || strlen(text) != 3 || if (!text || strlen(text) != 1) return 0;
(text[0] != 'C' && text[0] != 'c') || text[1] != '-') return 0; unsigned char letter = (unsigned char)text[0];
unsigned char letter = (unsigned char)text[2];
if (letter >= 'A' && letter <= 'Z') letter += 'a' - 'A'; if (letter >= 'A' && letter <= 'Z') letter += 'a' - 'A';
if (letter < 'a' || letter > 'z') return 0; if (letter < 'a' || letter > 'z') return 0;
*prefix = letter - 'a' + 1; *prefix = letter - 'a' + 1;
@ -3926,7 +3925,7 @@ int main(int argc, char **argv) {
} }
if (strcmp(option, "-p") == 0 || strcmp(option, "--prefix") == 0) { if (strcmp(option, "-p") == 0 || strcmp(option, "--prefix") == 0) {
if (argi >= argc || !parse_prefix(argv[argi], &prefix)) { if (argi >= argc || !parse_prefix(argv[argi], &prefix)) {
fprintf(stderr, "moerx: %s requires a key from C-a through C-z\n", option); fprintf(stderr, "moerx: %s requires a letter from a through z\n", option);
return 2; return 2;
} }
argi++; argi++;