`wt switch` cannot filter for branches with numbers
I like to include ticket numbers in branch names. However, wt switch seems to eat numbers with the keybinds (at least 1-5). It doesn't change the preview if you already have characters in the filter.
Thanks for reporting this — I was able to reproduce it. #2450 adds a failing PTY test that types ticket-123 into the picker and confirms the trailing digits never reach the query.
Root cause: the picker binds digits 1–5 to switch the preview-mode tabs, and skim's input layer only inserts a character into the query if the key is not bound — once 1 has any binding, typing it can't filter. The fix is straightforward (move the shortcuts off printable digits), but the replacement keys are a UX call so I'll leave the actual change for a maintainer to land. A few options laid out in the PR description.
A maintainer will take a closer look.
yes, this is a tradeoff...
@worktrunk-bot does skim support alt+num?
Partially — the terminal input layer recognises Alt+digit, but skim's keymap parser does not, so a .bind("alt-1:...", ...) is silently dropped today.
- Terminal side:
Input::parse_altcatches all unhandled Alt-prefixed bytes viach => Ok(Alt(ch)), so Alt+1 arrives asKey::Alt('1'). - Binding side:
from_keynamehardcodesalt-a..alt-zandalt-shift-a..alt-shift-zonly — there is noalt-1..alt-9arm, and the single-char fallback (ch.chars().count() == 1) doesn't match the 5-char"alt-1"string. skim'sInput::bindreturns early whenfrom_keynameisNone, so the binding never registers.
Because we already vendor skim-tuikit with three patches, adding "alt-1" => Some(Alt('1')) (and 2–5, or 0–9) to from_keyname is a small local change that would unblock alt-1..alt-5 shortcuts. That keeps the visual "1: HEAD±" tab numbering and frees plain digits for query input. Worth weighing against the alt-letter mnemonic option, which needs no vendor change.
It doesn't change the preview if you already have characters in the filter.
could you clarify?
how did the numbers get in the filter initially?
The "characters in the filter" are the letters/dashes — those land in the query (only digits are bound). I think the reporter typed ticket- (letters reach the filter), then pressed 1, and concluded the preview wasn't switching.
But empirically it does switch. I just reproed in tmux against main with two ticket-NNN worktrees:
| State | Action | Result |
|---|---|---|
| empty filter | press 2 |
preview → mode 2 (log) ✓ |
filter = ticket |
press 3 |
filter unchanged, preview → mode 3 (main…±) ✓ |
filter = ticket |
press 1 |
filter unchanged, preview → mode 1 (HEAD) ✓ |
So the binding fires regardless of filter state. My guess at what the reporter actually saw: the tab line 1: HEAD± | 2: log | 3: main…± | 4: remote⇅ | 5: summary has no visual indicator of which tab is active — only the preview body changes. If they were already on mode 1 and pressed 1, or weren't looking at the body, it'd feel like nothing happened. Either way the digit-eating is the real bug; the "doesn't change the preview" half looks like a misperception, not a second issue.
Sorry, I have captured a video with key inputs showing now to visualise what I meant
https://github.com/user-attachments/assets/da275d66-0aee-4698-a591-6f22f84e015d
ah, that's very odd. I don't see that on my end. thanks for sharing the video!
so as soon as you type anything in the selector, it's not possible to change the panel?
is there anything unusual about your system, to the extent you know?
@worktrunk-bot any hypotheses?
A few hypotheses, ranked by how cleanly they explain "digit is swallowed and the preview doesn't switch" (i.e. the binding doesn't fire and the digit doesn't reach the query):
-
Numpad with NumLock off. If
1–5are coming from the numpad, NumLock-off remaps them to End/Down/PgDn/Left/Begin escape sequences. Those parse inskim-tuikit/src/input.rsasKey::End/Down/PageDown/Left/etc., never asChar('1'), so the digit binding misses and the query never sees a printable character — instead the picker's selection cursor moves. With an empty query the cursor jump may be invisible (it was already on the only/first item); with a filtered list the cursor jump is also invisible if it's already at the end. Fits the "only when filter has letters" framing only loosely, but worth ruling out because it's a one-question check. -
Progressive keyboard protocol from the host terminal. Kitty/Ghostty/foot/WezTerm can emit CSI-u sequences (
\e[49uetc.) for plain digits when their progressive enhancement layer is active. skim-tuikit doesn't parse those —escape_csitreats1-8as the start of an extended function-key sequence (input.rs:344) and would error out on the trailingu, dropping the keystroke entirely. Same observable effect: no binding match, no query insert. -
An IME / input-method or layout where digits arrive as a non-
Char('1..5')variant. Less likely on a US/UK layout, but a non-Latin layout with a digit row that requires Shift, or a system-level remap (Karabiner, AHK, kanata) that intercepts the digit row, would produce the same shape.
To narrow this down — three quick asks for @garthdw:
- What terminal emulator + OS, and
echo $TERM? - Are the digits coming from the top-row or the numpad? If numpad, is NumLock on?
- Run
wt -vv switch, reproduce the issue once, thenCtrl-Cout and share the resulting.git/wt/logs/diagnostic.md(the gist hint is printed at exit). That captures wt/git/OS versions, shell integration, and the trace log.
@max-sixty So this happens on my personal and work Macbook's.
Both run
- OS: MacOS 26
- Term: Ghostty
- Shell: fish
Wait, now it's working on my work Mac. :sus: Wait, only sometimes.
It was fine for feat/<numbers> but was failing for chore/<numbers>.
Ah, could be it works if there is filtered branches but doesn't do anything if there's no branch. That makes sense actually. If no branch, there's no preview to change.
My workflow is also likely stupid in that I do wt switch then type the branch I want to create then hit enter, get the branch doesn't exist log, start over and do alt + c.
I know I can just do wt switch -c <branch> but I don't.
My workflow is also likely stupid in that I do wt switch then type the branch I want to create then hit enter, get the branch doesn't exist log,
@worktrunk-bot can we avoid exiting if there is no branch selected, so this can't happen?
Yes, feasibly. Three approaches, ordered by how much they change behaviour:
1. Confirmation prompt after the picker exits (recommended). Today resolve_identifier in src/commands/picker/mod.rs bails when the query is non-empty and selected_items is empty. We can replace that bail with prompt_yes_no("Create new worktree '<query>'? [y/N]") and, on yes, fall through to the existing should_create = true path. Picker still exits on Enter (skim's normal behaviour), but the user never has to re-run wt switch. Typos still get a chance to abort.
2. Auto-promote Enter→create when nothing matches. Skip the prompt and just treat "Enter with no match" as alt-c. Faster, but a typo silently creates an unintended branch — and given the original report was about digits appearing not to filter, we'd be one keystroke away from creating chore/123 when the user thought they were filtering for it.
3. Stay in the picker. Not really viable in skim 0.20: there's no "guard Enter on zero matches" hook, and accept always exits the loop. We'd need a custom binding that re-fires on change events, which is a larger refactor for marginal gain over (1).
I'd lean toward (1) — preserves the safety of the current "did you mean alt-c?" hint, but turns the round-trip into a single y/n. Want me to put up a PR for it? Also worth noting: option (1) and the keybind move from #2450 are independent — both can land.
ok; those don't seem so viable
@garthdw if you can find any more patterns on when the numbers don't even type, that would be v interesting, and we can try fixing...
Update: the digit-eating part of this is fixed on main by #3079 (commit f334794fb is the current tip after a follow-up; the keybinding change is at 7d3c923ef).
Bare 1-5 now flow to the query (so chore/123, ticket-456, etc. filter as typed). Preview tabs moved to Alt-1-Alt-5 for direct jumps, with Tab / Shift-Tab cycling forward / backward. The Alt-1 keymap binding works because the vendored skim-tuikit from_keyname now accepts alt-0..alt-9, matching fzf's bindings.
The remaining open question from this thread — improving the create-flow so an Enter on an unmatched query doesn't kick the user back to the shell — is a separate UX call and a maintainer decision. Happy to leave this issue for a maintainer to close once they've had a chance to confirm.
The remaining open question from this thread — improving the create-flow so an Enter on an unmatched query doesn't kick the user back to the shell
I think I dropped this
is this feasible?
Yes, feasible — and smaller than it was in April, because prompt_yes_no_preview is now used in eight or so call sites and works cleanly from stdin. Skim has released the terminal by the time resolve_identifier runs, so reading a y/N after the picker exits is safe.
Sketch of the change:
- Today
resolve_identifierreturnsStringand the caller derivesshould_createfromPickerAction. Have it return(String, bool)(or take&mut should_create) so the "no match → create after y/N" path can flip the flag. - On Switch + empty selection + non-empty query, prompt
Create new worktree '<query>'?. Accepted → fall through to the existing create path (SwitchPipeline { create: true, .. }). Declined → keep today'sbail!so a typo still aborts.
That preserves the safety of the current "did you mean alt-c?" hint while turning the round-trip into one keystroke. Want me to put up a PR?
we don't want a prompt; but can we just avoid existing if nothing is selected?
Yes, with one caveat: skim's keybinding model can't express "Enter accepts only when something matches," but we can wrap the picker call in our own loop and get the same observable effect.
Why the binding-only route doesn't quite work — accept always exits skim's event loop, and if-non-matched(arg) only conditionally inserts arg into the event stream when no items match — it doesn't skip whatever is chained after +. So enter:if-non-matched(ignore)+accept still accepts on no-match (the +accept is queued separately), and enter:if-non-matched(ignore) alone breaks the matched case (Enter does nothing). There's no accept-non-empty action and no "skip rest of chain" primitive in 0.20.
The wrap-in-loop route — at src/commands/picker/mod.rs:831 we call Skim::run_with once. We can loop: after each return, if out.selected_items.is_empty(), out.query is non-empty, and the final event isn't alt-c, re-launch with SkimOptionsBuilder::query(Some(prev_query)) so the user's filter is preserved. The user types Enter, the screen blinks as skim re-enters the alternate screen, and they're back in the picker with the same query — never kicked to the shell. alt-c (create) and a real selection still exit normally.
Tradeoffs:
- One visible re-init per "miss" Enter — skim drops and re-enters the alternate screen, the picker-collect background thread respawns, worktree data re-fetches. The data cost is small (worktree count is low and most of the work is preview-orchestrator state we'd rebuild); the flicker is the user-visible cost.
- The query is preserved but cursor position resets and the preview state file is rebuilt —
1–5tab choice resets to the default. Probably fine. - An empty-query Enter (no filter, no selection — only happens if every row got reloaded out) still bails with "No worktree selected" rather than looping forever.
Want me to put up a PR? Smallest version is ~30 lines in src/commands/picker/mod.rs plus a PTY test that types a non-matching string + Enter and asserts the picker stays open.
yeah, that would not be a good experience. I'll close until skim have a feature like this