Skip to content

Support shorthand #406

Closed
Closed

Description

@tarrencev

wt ls wt rm etc

Activity

  1. max-sixty commented on Jan 4, 2026

    @max-sixty
    Owner

    my sense is that these can be local aliases, but quite open-minded

    one downside of shorthands is that wt r<tab> doesn't complete to wt remove (though we could likely exclude shorthand from completions to handle this)

    let's leave this open for a bit and see what others think

  2. vforsh commented on Jan 5, 2026

    @vforsh

    +1

    ls and rm were the 1st things i tried after installing and playing with wt

  3. razor-x commented on Jan 15, 2026

    @razor-x
    Contributor

    This could be packaged as a shell plugin, similar to https://github.com/jhillyerd/plugin-git and https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git/ either part of this repo or maintained separately (or even PRed into those plugins, however they may not accept scope outside of git)

  4. added a commit that references this issue on Jan 22, 2026
    ba4d88a
  5. KieranP commented on Apr 6, 2026

    @KieranP

    Hello. Just started using Worktrunk and similarly hoping that we can get native short aliases, either built in or via git style alias mapping/

  6. max-sixty commented on Apr 7, 2026

    @max-sixty
    Owner

    we have aliases! They are currently on wt step foo, but it's viable to alias ws to wt step and then ws ls could be wt step ls etc...

  7. KieranP commented on Apr 7, 2026

    @KieranP

    Hmm, not quite the same. Shell command aliases requires engineers to edit their own .zshrc. While having built in alias support in worktrunk means the worktrunk config in the git repo can apply to everyone when they are in the project. Would prefer native and top level support for aliases within a project rather than asking engineers to go make changes to their global shell.

  8. markjaquith commented on Apr 9, 2026

    @markjaquith

    I fairly immediately tried to do both rm and ls and grumbled a bit when they didn't work.

    Having this as silent (not auto-completed, maybe not even advertised) shortcuts would be a nice QOL improvement, without much downside.

  9. jrdncstr commented on Apr 17, 2026

    @jrdncstr

    I'll try using shell aliases to see whether they stick.

  10. max-sixty commented on Apr 17, 2026

    @max-sixty
    Owner

    We now have aliases support at the root!

    @worktrunk-bot can you write out the config that would let folks have the shorthand please?

  11. worktrunk-bot commented on Apr 17, 2026

    @worktrunk-bot
    Collaborator

    Drop this into either user config (~/.config/worktrunk/config.toml, trusted, applies everywhere) or project config (.config/wt.toml, shared with teammates, approval prompt on first run):

    [aliases]
    ls = "wt list"
    rm = "wt remove"
    sw = "wt switch"

    Then wt ls, wt rm, wt sw all work. See Aliases for docs.

    One caveat: aliases don't forward bare positional arguments — wt rm my-branch errors with Unexpected argument 'my-branch'. Flags-as-vars work, so you can do wt rm --branch=my-branch if you template it as rm = "wt remove {{ branch }}", but there's no way today to make wt rm my-branch route through. For those cases stick with the full command name.

  12. max-sixty commented on Apr 17, 2026

    @max-sixty
    Owner

    One caveat: aliases don't forward bare positional arguments — wt rm my-branch errors with Unexpected argument 'my-branch'. Flags-as-vars work, so you can do wt rm --branch=my-branch if you template it as rm = "wt remove {{ branch }}", but there's no way today to make wt rm my-branch route through. For those cases stick with the full command name.

    erm, OK, sorry. I will think about this before declaring victory. Need to consider how to have wt CLI options work; possibly will force them to be before the alias

  13. max-sixty commented on Apr 19, 2026

    @max-sixty
    Owner

    I think with 0.40 this should be ready! @worktrunk-bot please confirm?

  14. worktrunk-bot commented on Apr 19, 2026

    @worktrunk-bot
    Collaborator

    Confirmed — 0.40 closes that gap. Smart routing (#2304) sends --KEY=VALUE tokens to matching {{ KEY }} vars and forwards everything else — including bare positionals — as {{ args }}. The shorthand config now looks like:

    [aliases]
    ls = "wt list {{ args }}"
    rm = "wt remove {{ args }}"
    sw = "wt switch {{ args }}"

    With {{ args }} in the template, wt rm feature, wt sw other-branch, and wt ls --format=json all route through. Preview any invocation with wt config alias dry-run <name> -- <args>.

  15. max-sixty commented on Apr 19, 2026

    @max-sixty
    Owner

    great! feel free to post here for any issues / problems / hints / questions for @worktrunk-bot / etc. Will close.

    thanks for the ideas!

  16. KieranP commented on Apr 21, 2026

    @KieranP

    @max-sixty Aliases don't like commands that need interaction :-(

    ~/.config/worktrunk/config.toml

    worktree-path = "{{ repo_path }}/.worktrees/{{ branch | sanitize }}"
    
    [aliases]
    ls = "wt list {{ args }}"
    rm = "wt remove {{ args }}"
    sw = "wt switch {{ args }}"

    Shell:

    › wt sw
    ◎ Running alias sw
    ✗ Interactive picker requires an interactive terminal
    
  17. worktrunk-bot commented on Apr 21, 2026

    @worktrunk-bot
    Collaborator

    Real bug — thanks for the report, and apologies for the half-victory lap. Alias execution pipes the template context (branch, repo, args, ...) as JSON to each child command's stdin, which displaces the controlling terminal. The picker's stdin().is_terminal() check in src/commands/picker/mod.rs then fails. Same pipe would break skim's keyboard input even if the guard were removed.

    Verified with a diag alias:

    [aliases]
    diag = "if [ -t 0 ]; then echo STDIN_IS_TTY; else echo STDIN_IS_PIPE; fi"
    $ wt diag
    ◎ Running alias diag
    STDIN_IS_PIPE

    Workaround until this is fixed properly: reopen /dev/tty on stdin in the alias body so the child sees the real terminal again:

    [aliases]
    sw = "wt switch {{ args }} < /dev/tty"
    rm = "wt remove {{ args }}"
    ls = "wt list {{ args }}"

    Only sw needs it (the other two are non-interactive). /dev/tty always refers to the controlling terminal of the session, regardless of how stdin was redirected into wt.

    @max-sixty — worth a proper fix on the alias side (don't pipe stdin when the child is a wt subcommand, or make it opt-in). Happy to file an issue to track.

  18. max-sixty commented on Apr 22, 2026

    @max-sixty
    Owner

    @max-sixty — worth a proper fix on the alias side (don't pipe stdin when the child is a wt subcommand, or make it opt-in). Happy to file an issue to track.

    we don't want to track whether it's a subcommand, or add configs. Is there an uncomplicated option to attach stdin? Otherwise we could remove the json piping, I have heard exactly zero people using it (at least in aliases)

  19. worktrunk-bot commented on Apr 22, 2026

    @worktrunk-bot
    Collaborator

    Good news — the hook/alias split already exists in code, so no subcommand sniffing or new configs needed. The JSON-on-stdin is a documented feature for hooks (docs/content/hook.md has a "JSON context" section with a Python example, and there are tests test_post_create_json_stdin / test_post_start_json_stdin asserting it), but not for aliases — it just leaked into aliases because they share the executor path.

    At the single call site in src/commands/command_executor.rs:450-456, run_one_command already knows the origin (CommandOrigin::Hook vs CommandOrigin::Alias). The uncomplicated fix is:

    let stdin_json = match origin {
        CommandOrigin::Hook { .. } => Some(cmd.context_json.as_str()),
        CommandOrigin::Alias { .. } => None,
    };
    let result = execute_shell_command(wt_path, command_str, stdin_json, ...);

    Then in execute_shell_command (src/output/handlers.rs:1440), if stdin_content is None set .stdin(Stdio::inherit()) instead of leaving it as the current null default. That's what gives the picker back its terminal.

    Net: hooks keep their documented JSON-on-stdin contract, aliases inherit the tty. Want me to put up a PR?

  20. max-sixty commented on Apr 22, 2026

    @max-sixty
    Owner

    yes please

  21. worktrunk-bot commented on Apr 22, 2026

    @worktrunk-bot
    Collaborator

    Opened #2380 with the fix: hooks keep the documented JSON-on-stdin contract, aliases inherit stdin so wt sw (and any other interactive alias) keeps its tty. Once it lands the < /dev/tty workaround won't be needed.

  22. max-sixty commented on Apr 22, 2026

    @max-sixty
    Owner

    I think this should be good now! I've also really optimized away any excess commands to prepare the context, so it should be down to 30ms overhead.

    I'll close but let me know any final things that aren't quite up to scratch.

  23. KieranP commented on Apr 27, 2026

    @KieranP

    @max-sixty Just had a chance to test this. It seems to freeze. "wt switch" opens the interactive switcher as expected but "wt sw" (aliased) does nothing, blank screen. So something still not quite right here.

  24. worktrunk-bot commented on Apr 27, 2026

    @worktrunk-bot
    Collaborator

    Reproduced — apologies, the prior fix only got half the bug. The blank screen is a job-control issue separate from the stdin one.

    Aliases run their child shell with forward_signals(), which calls cmd.process_group(0) to put the inner shell (and its wt switch grandchild) in a new process group. That new pgroup never becomes the controlling terminal's foreground pgroup, so when skim's tuikit calls tcsetattr on /dev/tty to enter raw mode (here), POSIX requires the kernel to send SIGTTOU to that pgroup, which stops it. The picker initializes, then freezes mid-render — exactly what KieranP saw.

    Proof from ps while a wt sw is hung:

    PID  PGID  SID  STAT  WCHAN   COMM
    366  366   366  Ssl+  hrtime  wt          ← parent: foreground pgroup (the +)
    379  378   366  Tl    do_sig  wt switch   ← child: STOPPED (T), parked in signal handler
    

    The T state plus do_sig wchan is the diagnostic — the inner wt switch is suspended on SIGTTOU inside tcsetattr. Direct wt switch runs in the parent process, shares the foreground pgroup, and never hits this path.

    Verified by patching out the cmd.process_group(0) line and rebuilding: wt sw then renders the picker normally (escape-sequence stream goes from 0 bytes to 1KB+ in the captured PTY).

    Proposed fix: when an alias inherits stdin (the interactive case we already detect for the JSON-on-stdin gating), skip the new pgroup. Parent and child share the foreground pgroup, the user's Ctrl-C reaches both via the kernel, and tcsetattr succeeds. The new-pgroup isolation only matters when wt needs kill(child_pgid) to take down a tree — for interactive aliases that's redundant since the kernel already sends SIGINT to the shared pgroup.

    Alternative is the standard shell job-control pattern (tcsetpgrp to make the new pgroup foreground, restore on exit), but that's more moving parts for the same outcome.

    @max-sixty want me to put up a PR for option 1?

  25. max-sixty commented on Apr 27, 2026

    @max-sixty
    Owner

    yes please @worktrunk-bot

    @KieranP thanks for the report, and your patience

  26. worktrunk-bot commented on Apr 28, 2026

    @worktrunk-bot
    Collaborator

    Opened #2444 with the fix. Cmd::inherit_stdin() now keeps the child in wt's process group when the alias body inherits stdin, so skim's tcsetattr on /dev/tty no longer raises SIGTTOU mid-render. Concurrent aliases still get their own pgroups (separate executor in output/concurrent.rs), so the existing wt step tear-down behaviour is unchanged.

    Once it lands, wt sw (aliased to wt switch {{ args }}) should render the picker normally — no < /dev/tty workaround needed. @KieranP if you're up for it, a fresh test on your config after the PR merges would be valuable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions