From 05c6d62c681598697d345e18f802f5e601dac1f7 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 16 Sep 2024 21:45:09 +0200 Subject: [PATCH] bookmark: add "b" alias `jj bookmark` is a frequently used command. Its subcommands already have one letter aliases. Defining `jj b` as an alias for `jj bookmarks` make bookmarks really easy to use. --- cli/src/config/misc.toml | 1 + cli/tests/test_alias.rs | 14 +++++++------- docs/bookmarks.md | 9 +++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cli/src/config/misc.toml b/cli/src/config/misc.toml index 3a45e73033..0f2306fda5 100644 --- a/cli/src/config/misc.toml +++ b/cli/src/config/misc.toml @@ -2,6 +2,7 @@ # all aliases from here. [aliases] amend = ["squash"] +b = ["bookmark"] co = ["checkout"] unamend = ["unsquash"] diff --git a/cli/tests/test_alias.rs b/cli/tests/test_alias.rs index ca43e4edb6..d71307a0ff 100644 --- a/cli/tests/test_alias.rs +++ b/cli/tests/test_alias.rs @@ -24,9 +24,9 @@ fn test_alias_basic() { test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); let repo_path = test_env.env_root().join("repo"); - test_env.add_config(r#"aliases.b = ["log", "-r", "@", "-T", "bookmarks"]"#); + test_env.add_config(r#"aliases.bk = ["log", "-r", "@", "-T", "bookmarks"]"#); test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "my-bookmark"]); - let stdout = test_env.jj_cmd_success(&repo_path, &["b"]); + let stdout = test_env.jj_cmd_success(&repo_path, &["bk"]); insta::assert_snapshot!(stdout, @r###" @ my-bookmark │ @@ -41,9 +41,9 @@ fn test_alias_legacy_section() { let repo_path = test_env.env_root().join("repo"); // Can define aliases in [alias] section - test_env.add_config(r#"alias.b = ["log", "-r", "@", "-T", "bookmarks"]"#); + test_env.add_config(r#"alias.bk = ["log", "-r", "@", "-T", "bookmarks"]"#); test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "my-bookmark"]); - let stdout = test_env.jj_cmd_success(&repo_path, &["b"]); + let stdout = test_env.jj_cmd_success(&repo_path, &["bk"]); insta::assert_snapshot!(stdout, @r###" @ my-bookmark │ @@ -51,10 +51,10 @@ fn test_alias_legacy_section() { "###); // The same alias (name) in both [alias] and [aliases] sections is an error - test_env.add_config(r#"aliases.b = ["bookmark", "list"]"#); - let stderr = test_env.jj_cmd_failure(&repo_path, &["b"]); + test_env.add_config(r#"aliases.bk = ["bookmark", "list"]"#); + let stderr = test_env.jj_cmd_failure(&repo_path, &["bk"]); insta::assert_snapshot!(stderr, @r###" - Error: Alias "b" is defined in both [aliases] and [alias] + Error: Alias "bk" is defined in both [aliases] and [alias] Hint: [aliases] is the preferred section for aliases. Please remove the alias from [alias]. "###); } diff --git a/docs/bookmarks.md b/docs/bookmarks.md index 2eea817d53..59472120cc 100644 --- a/docs/bookmarks.md +++ b/docs/bookmarks.md @@ -218,4 +218,13 @@ To resolve a conflicted state in a remote bookmark (e.g. `main@origin`), simply pull from the remote (e.g. `jj git fetch`). The conflict resolution will also propagate to the local bookmark (which was presumably also conflicted). +## Ease of use + +The use of bookmarks is frequent in some workflows, for example, when +interacting with Git repositories containing branches. To this end, +one-letter shortcuts have been implemented, both for the `jj bookmark` +command itself through an alias (as `jj b`), and for its subcommands. +For example, `jj bookmark create BOOKMARK-NAME` can be abbreviated as +`jj b c BOOKMARK-NAME`. + [design]: design/tracking-branches.md