From 4bcab44d651e7f1712ab79c4c4505b2a549e1f22 Mon Sep 17 00:00:00 2001 From: Julien Moutinho Date: Thu, 18 Dec 2025 00:37:53 +0100 Subject: [PATCH] +funct/appro(jujutsu): add aliases --- home-manager/profiles/bash.nix | 9 +++-- home-manager/profiles/essential.nix | 2 +- home-manager/profiles/jujutsu.nix | 10 ++++++ home-manager/profiles/jujutsu/jj/config.toml | 37 +++++++++++++++++++- nixos/profiles/system.nix | 2 +- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/home-manager/profiles/bash.nix b/home-manager/profiles/bash.nix index a116efe..c560785 100644 --- a/home-manager/profiles/bash.nix +++ b/home-manager/profiles/bash.nix @@ -14,11 +14,10 @@ with lib; emacs = "emacsclient --create-frame"; grep = "grep --color"; du = "du --apparent-size"; # ExplanationNote: shows the size __before__ ZFS' compression. - j = "jj"; # jujutsu - jnl-b = "sudo journalctl -b"; - jnl-f = "sudo journalctl -f -u"; - jnl-f200 = "sudo journalctl -f -n 200 -u"; - jnl-ftoday = "sudo journalctl -f --since today -u"; + jb = "sudo journalctl -b"; + jf = "sudo journalctl -f -u"; + jf200 = "sudo journalctl -f -n 200 -u"; + jftoday = "sudo journalctl -f --since today -u"; lu = "journalctl --user -u"; l = "ls -alh"; ll = "ls -al"; diff --git a/home-manager/profiles/essential.nix b/home-manager/profiles/essential.nix index 9316d9f..f020477 100644 --- a/home-manager/profiles/essential.nix +++ b/home-manager/profiles/essential.nix @@ -90,7 +90,7 @@ ]; home.sessionPath = [ "${config.home.homeDirectory}/bin" ]; home.sessionVariables = { - EDITOR = "vim"; + EDITOR = "vi"; LANG = "fr_FR.UTF-8"; LESS = "-FRSX"; # NixOS generates a customized pkgs.glibcLocales in config.i18n.glibcLocales diff --git a/home-manager/profiles/jujutsu.nix b/home-manager/profiles/jujutsu.nix index 3d94047..500e050 100644 --- a/home-manager/profiles/jujutsu.nix +++ b/home-manager/profiles/jujutsu.nix @@ -13,4 +13,14 @@ ]; xdg.configFile."jj".source = jujutsu/jj; xdg.configFile."jjui".source = jujutsu/jjui; + programs.bash = lib.mkIf config.programs.git.enable { + shellAliases = { + je = "jj-edit"; + jer = "jj-edit-review"; + }; + initExtra = '' + jj-edit () { local revs=$1; shift; $EDITOR $(jj diff -r "$revs" --name-only "$@"); } + jj-edit-review () { local revs=$1; shift; $EDITOR $(jj diff -r "review($revs)" --name-only "$@"); } + ''; + }; } diff --git a/home-manager/profiles/jujutsu/jj/config.toml b/home-manager/profiles/jujutsu/jj/config.toml index fe759e5..c11d4f7 100644 --- a/home-manager/profiles/jujutsu/jj/config.toml +++ b/home-manager/profiles/jujutsu/jj/config.toml @@ -50,6 +50,36 @@ fi """, ""] upp = ["util", "exec", "--", "sh", "-c", "jj up && jj git push", ""] +track-github-PR = ["util", "exec", "--", 'sh', '-euxc', ''' + PR=$1 + gh pr view --json headRepository,headRefName,headRepositoryOwner $PR --jq '" + set_remote() { + jj 2>/dev/null git remote add \"$1\" \"$2\" || + jj git remote set-url \"$1\" \"$2\" + } + set_remote \(.headRepositoryOwner.login) git@github.com:\(.headRepositoryOwner.login)/\(.headRepository.name) + jj git fetch --remote \(.headRepositoryOwner.login) --branch \(.headRefName) + jj bookmark track \(.headRefName)@\(.headRepositoryOwner.login) + origin=$(gh repo view --json owner,name --jq .owner.login) + set_remote \"$origin\" \"$(gh repo view --json sshUrl --jq .sshUrl)\" + git fetch --force --update-head-ok \"$origin\" \"refs/pull/'"$PR"'/head:refs/remotes/$origin/pull/'"$PR"'\" + "' | + sh -euxs +''', "jj-track-github-PR"] + +untrack-github-PR = ["util", "exec", "--", 'sh', '-euxc', ''' + PR=$1 + gh pr view --json headRepository,headRefName,headRepositoryOwner $PR --jq '" + jj bookmark forget \(.headRefName) || true + origin=$(gh repo view --json owner,name --jq .owner.login) + git for-each-ref --format \"delete %(refname)\" \\ + \"refs/remotes/\(.headRepositoryOwner.login)/\(.headRefName)\" \\ + \"refs/remotes/$origin/pull/'"$PR"'\" | + tee /dev/stderr | + git update-ref --stdin + "' | + sh -euxs +''', "jj-untrack-github-PR"] # Get all open stacks of work. open = ["log", "-r", "open()"] @@ -114,10 +144,15 @@ jj bookmark move -f "$bookmark" -t "$bookmark+" ''', 'jj-to'] [revsets] -log = "@ | trunk()::visible_heads()" +# Focus current commit, trunk(), on local work and remote work by removing ancestors of trunk() +log = "@ | trunk() | ancestors_and_children(bookmarks() | tracked_remote_bookmarks()) ~ ..trunk()" [revset-aliases] "active(rev)" = "(ancestors(rev) | descendants(rev)) ~ immutable()" +"ancestors_and_children(x)" = "..x | x::" + +# Remote commits not merged in trunk() +"review(x)" = "ancestors_and_children(remote_bookmarks(x)) ~ ..trunk()" # Authored or committed by specified user 'user(x)' = 'author(x) | committer(x)' diff --git a/nixos/profiles/system.nix b/nixos/profiles/system.nix index 881e489..596b95d 100644 --- a/nixos/profiles/system.nix +++ b/nixos/profiles/system.nix @@ -39,7 +39,7 @@ with lib; programs.vim.defaultEditor = mkDefault true; programs.vim.enable = mkDefault true; environment.variables = { - EDITOR = "vim"; + EDITOR = "vi"; NIXPKGS_CONFIG = mkForce ""; PAGER = "less -R"; SYSTEMD_LESS = "FKMRX"; -- 2.49.0