From 35ed179ab7678de2e236e27c8119e50e9c4c4de8 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/commands/mod.rs | 1 + cli/tests/test_alias.rs | 14 +++++++------- docs/bookmarks.md | 9 +++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 52c03c17437..b469f6311ba 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -77,6 +77,7 @@ enum Command { #[command(subcommand)] Bench(bench::BenchCommand), #[command(subcommand)] + #[command(visible_alias = "b")] Bookmark(bookmark::BookmarkCommand), // TODO: Remove in jj 0.28+ #[command(subcommand, hide = true)] diff --git a/cli/tests/test_alias.rs b/cli/tests/test_alias.rs index ca43e4edb60..d71307a0ff0 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 2eea817d534..590ccc861f8 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 (as `jj b`) and for its subcommands. For example, `jj +bookmark create BRANCH-NAME` can be abbreviated as `jj b c +BRANCH-NAME`. + [design]: design/tracking-branches.md