Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat(switch): add [switch.picker] preview setting to open the picker list-only (#4428)

Worktrunk Bot86674a2d1ff2
diff --git a/dev/config.example.toml b/dev/config.example.toml
index 8aa6c17ae..87ce8049b 100644
--- a/dev/config.example.toml
+++ b/dev/config.example.toml
@@ -212,6 +212,7 @@
#
# [switch.picker]
# pager = "delta --paging=never" # Example: override git's core.pager for diff preview
+# preview = true # Show the preview panel on open (Alt-p toggles)
#
# ### Step
#
diff --git a/docs/src/content/docs/config.md b/docs/src/content/docs/config.md
index 11bcb83b7..01a413f68 100644
--- a/docs/src/content/docs/config.md
+++ b/docs/src/content/docs/config.md
@@ -318,6 +318,7 @@ cd = true # Change directory after switching (--no-cd to skip)
[switch.picker]
pager = "delta --paging=never" # Example: override git's core.pager for diff preview
+preview = true # Show the preview panel on open (Alt-p toggles)
```
### Step
diff --git a/docs/src/content/docs/switch.md b/docs/src/content/docs/switch.md
index d4629882b..69f224280 100644
--- a/docs/src/content/docs/switch.md
+++ b/docs/src/content/docs/switch.md
@@ -146,6 +146,8 @@ The comparison base is the merge-base with the default branch, or with its upstr
pager = "delta --paging=never --width=$COLUMNS"
```
+**Starting list-only:** Set `preview = false` under `[switch.picker]` to open the picker with the preview hidden; `Alt-p` still shows it.
+
## Pull requests and merge requests
The `pr:<number>` / `mr:<number>` shortcut and the PR/MR's web URL both resolve to its branch. For same-repo PRs/MRs, worktrunk switches to the branch directly. For fork PRs/MRs, it fetches the ref (`refs/pull/N/head` or `refs/merge-requests/N/head`) and configures `pushRemote` to the fork URL.
diff --git a/plugins/worktrunk/skills/worktrunk/reference/config.md b/plugins/worktrunk/skills/worktrunk/reference/config.md
index a7aff2f5c..cebe4960a 100644
--- a/plugins/worktrunk/skills/worktrunk/reference/config.md
+++ b/plugins/worktrunk/skills/worktrunk/reference/config.md
@@ -310,6 +310,7 @@ cd = true # Change directory after switching (--no-cd to skip)
[switch.picker]
pager = "delta --paging=never" # Example: override git's core.pager for diff preview
+preview = true # Show the preview panel on open (Alt-p toggles)
```
### Step
diff --git a/plugins/worktrunk/skills/worktrunk/reference/switch.md b/plugins/worktrunk/skills/worktrunk/reference/switch.md
index b64e58733..92358763e 100644
--- a/plugins/worktrunk/skills/worktrunk/reference/switch.md
+++ b/plugins/worktrunk/skills/worktrunk/reference/switch.md
@@ -122,6 +122,8 @@ The comparison base is the merge-base with the default branch, or with its upstr
pager = "delta --paging=never --width=$COLUMNS"
```
+**Starting list-only:** Set `preview = false` under `[switch.picker]` to open the picker with the preview hidden; `Alt-p` still shows it.
+
## Pull requests and merge requests
The `pr:<number>` / `mr:<number>` shortcut and the PR/MR's web URL both resolve to its branch. For same-repo PRs/MRs, worktrunk switches to the branch directly. For fork PRs/MRs, it fetches the ref (`refs/pull/N/head` or `refs/merge-requests/N/head`) and configures `pushRemote` to the fork URL.
diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.md
index a7aff2f5c..cebe4960a 100644
--- a/skills/worktrunk/reference/config.md
+++ b/skills/worktrunk/reference/config.md
@@ -310,6 +310,7 @@ cd = true # Change directory after switching (--no-cd to skip)
[switch.picker]
pager = "delta --paging=never" # Example: override git's core.pager for diff preview
+preview = true # Show the preview panel on open (Alt-p toggles)
```
### Step
diff --git a/skills/worktrunk/reference/switch.md b/skills/worktrunk/reference/switch.md
index b64e58733..92358763e 100644
--- a/skills/worktrunk/reference/switch.md
+++ b/skills/worktrunk/reference/switch.md
@@ -122,6 +122,8 @@ The comparison base is the merge-base with the default branch, or with its upstr
pager = "delta --paging=never --width=$COLUMNS"
```
+**Starting list-only:** Set `preview = false` under `[switch.picker]` to open the picker with the preview hidden; `Alt-p` still shows it.
+
## Pull requests and merge requests
The `pr:<number>` / `mr:<number>` shortcut and the PR/MR's web URL both resolve to its branch. For same-repo PRs/MRs, worktrunk switches to the branch directly. For fork PRs/MRs, it fetches the ref (`refs/pull/N/head` or `refs/merge-requests/N/head`) and configures `pushRemote` to the fork URL.
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 7a229a757..a3c9ea865 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -763,6 +763,8 @@ The comparison base is the merge-base with the default branch, or with its upstr
pager = "delta --paging=never --width=$COLUMNS"
```
+**Starting list-only:** Set `preview = false` under `[switch.picker]` to open the picker with the preview hidden; `Alt-p` still shows it.
+
## Pull requests and merge requests
The `pr:<number>` / `mr:<number>` shortcut and the PR/MR's web URL both resolve to its branch. For same-repo PRs/MRs, worktrunk switches to the branch directly. For fork PRs/MRs, it fetches the ref (`refs/pull/N/head` or `refs/merge-requests/N/head`) and configures `pushRemote` to the fork URL.
@@ -2298,6 +2300,7 @@ cd = true # Change directory after switching (--no-cd to skip)
[switch.picker]
pager = "delta --paging=never" # Example: override git's core.pager for diff preview
+preview = true # Show the preview panel on open (Alt-p toggles)
```
### Step
diff --git a/src/commands/picker/mod.rs b/src/commands/picker/mod.rs
index b28f5b683..60fb898fe 100644
--- a/src/commands/picker/mod.rs
+++ b/src/commands/picker/mod.rs
@@ -1829,7 +1829,14 @@ pub fn handle_picker(
state
.initial_layout
.dimensions_for(term_width, term_height, num_items_estimate);
- let preview_window_spec = state.initial_layout.spec_for(preview_dims);
+ let mut preview_window_spec = state.initial_layout.spec_for(preview_dims);
+ // `[switch.picker] preview = false` opens list-only. skim's `hidden`
+ // modifier is the same flag `alt-p:toggle-preview` flips, so the toggle
+ // reveals the pane at the size computed above. Background pre-rendering
+ // still runs, so the first reveal is as warm as an always-shown preview.
+ if !config.switch_picker.preview() {
+ preview_window_spec.push_str(":hidden");
+ }
// When summary generation is unavailable, prime the Summary cache with
// config guidance instead of showing a perpetual "Generating…" placeholder.
diff --git a/src/config/user/sections.rs b/src/config/user/sections.rs
index 5a615e4e0..107653850 100644
--- a/src/config/user/sections.rs
+++ b/src/config/user/sections.rs
@@ -415,6 +415,13 @@ pub struct SwitchPickerConfig {
/// Example: `pager = "delta --paging=never"`
#[serde(skip_serializing_if = "Option::is_none")]
pub pager: Option<String>,
+
+ /// Show the preview panel when the picker opens (default: true)
+ ///
+ /// With `preview = false` the picker opens list-only; `Alt-p` still
+ /// toggles the preview.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub preview: Option<bool>,
}
impl SwitchPickerConfig {
@@ -422,12 +429,18 @@ impl SwitchPickerConfig {
pub fn pager(&self) -> Option<&str> {
self.pager.as_deref()
}
+
+ /// Show the preview panel when the picker opens (default: true)
+ pub fn preview(&self) -> bool {
+ self.preview.unwrap_or(true)
+ }
}
impl Merge for SwitchPickerConfig {
fn merge_with(&self, other: &Self) -> Self {
Self {
pager: other.pager.clone().or_else(|| self.pager.clone()),
+ preview: other.preview.or(self.preview),
}
}
}
diff --git a/src/config/user/tests.rs b/src/config/user/tests.rs
index cee54139c..13d8da976 100644
--- a/src/config/user/tests.rs
+++ b/src/config/user/tests.rs
@@ -1119,11 +1119,14 @@ fn test_switch_picker_config_accessor_methods() {
let config = SwitchPickerConfig::default();
assert!(config.pager().is_none());
+ assert!(config.preview());
let config = SwitchPickerConfig {
pager: Some("delta --paging=never".to_string()),
+ preview: Some(false),
};
assert_eq!(config.pager(), Some("delta --paging=never"));
+ assert!(!config.preview());
}
#[test]
@@ -1131,10 +1134,12 @@ fn test_switch_picker_config_parse_toml() {
let content = r#"
[switch.picker]
pager = "delta --paging=never"
+preview = false
"#;
let config: UserConfig = toml::from_str(content).unwrap();
let picker = config.switch.picker.as_ref().unwrap();
assert_eq!(picker.pager.as_deref(), Some("delta --paging=never"));
+ assert_eq!(picker.preview, Some(false));
}
#[test]
@@ -1143,13 +1148,16 @@ fn test_switch_picker_merge() {
let base = SwitchPickerConfig {
pager: Some("delta".to_string()),
+ preview: Some(false),
};
let override_config = SwitchPickerConfig {
pager: None, // Fall back to base
+ preview: Some(true),
};
let merged = base.merge_with(&override_config);
assert_eq!(merged.pager.as_deref(), Some("delta"));
+ assert_eq!(merged.preview, Some(true));
}
#[test]
@@ -1160,11 +1168,15 @@ fn test_switch_config_merge() {
let base = SwitchConfig {
picker: Some(SwitchPickerConfig {
pager: Some("delta".to_string()),
+ ..Default::default()
}),
..Default::default()
};
let other = SwitchConfig {
- picker: Some(SwitchPickerConfig { pager: None }),
+ picker: Some(SwitchPickerConfig {
+ pager: None,
+ ..Default::default()
+ }),
..Default::default()
};
let merged = base.merge_with(&other);
@@ -1320,6 +1332,7 @@ fn test_switch_picker_project_override() {
switch: SwitchConfig {
picker: Some(SwitchPickerConfig {
pager: Some("delta".to_string()),
+ ..Default::default()
}),
..Default::default()
},
@@ -1332,6 +1345,7 @@ fn test_switch_picker_project_override() {
switch: SwitchConfig {
picker: Some(SwitchPickerConfig {
pager: Some("bat".to_string()),
+ ..Default::default()
}),
..Default::default()
},
@@ -1394,6 +1408,7 @@ fn test_resolved_config_for_project() {
switch: SwitchConfig {
picker: Some(SwitchPickerConfig {
pager: Some("less".to_string()),
+ ..Default::default()
}),
..Default::default()
},
diff --git a/tests/integration_tests/switch_picker.rs b/tests/integration_tests/switch_picker.rs
index 2b9427a8f..57a27ee67 100644
--- a/tests/integration_tests/switch_picker.rs
+++ b/tests/integration_tests/switch_picker.rs
@@ -1115,6 +1115,46 @@ pager = 'echo PROJECT-PAGER; cat'
);
}
+/// `[switch.picker] preview = false` opens the picker list-only, and `alt-p`
+/// still reveals the preview (its controls line is part of the preview content).
+#[rstest]
+fn test_switch_picker_preview_hidden_by_config(repo: TestRepo) {
+ repo.write_test_config(
+ r#"[switch.picker]
+preview = false
+"#,
+ );
+
+ let env_vars = repo.test_env_vars();
+ let PickerSession {
+ child,
+ _master,
+ writer,
+ rx,
+ mut parser,
+ } = boot_picker_pty(
+ wt_bin().to_str().unwrap(),
+ &["switch"],
+ repo.root_path(),
+ &env_vars,
+ );
+
+ let hidden = screen_text(&parser);
+ send_input_awaiting_content(&writer, &rx, &mut parser, "\x1bp", Some("Enter: switch"));
+ let shown = screen_text(&parser);
+ let exit_code = abort_and_exit_code(child, writer, rx);
+ assert_valid_abort_exit_code(exit_code);
+
+ assert!(
+ !hidden.contains("Enter: switch"),
+ "the preview should start hidden:\n{hidden}"
+ );
+ assert!(
+ shown.contains("Enter: switch"),
+ "alt-p should reveal the preview:\n{shown}"
+ );
+}
+
/// The completed diff proves pager selection has finished before checking that
/// an interactive fallback was not launched. All cases run from outside -C.
#[cfg(unix)]
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
index 7652a4c7b..59e320412 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
@@ -289,6 +289,7 @@ Creates ~/.config/worktrunk/config.toml with the following content:
  #
  # [switch.picker]
  # pager = "delta --paging=never" # Example: override git's core.pager for diff preview
+  # preview = true # Show the preview panel on open (Alt-p toggles)
  #
  # ### Step
  #
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
index d0c672e66..7bc14723d 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
@@ -336,6 +336,7 @@ Persistent flag values for wt remove. Override on command line as needed
 
  [switch.picker]
  pager = "delta --paging=never" # Example: override git's core.pager for diff preview
+  preview = true # Show the preview panel on open (Alt-p toggles)
Step
diff --git a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
index 5da984218..a63241715 100644
--- a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
@@ -254,6 +254,8 @@ The comparison base is the merge-base with the default branch, or with its upstr
  [switch.picker]
  pager = "delta --paging=never --width=$COLUMNS"
+Starting list-only: Set preview = false under [switch.picker] to open the picker with the preview hidden; Alt-p still shows it.
+
Pull requests and merge requests
The pr:<number> / mr:<number> shortcut and the PR/MR's web URL both resolve to its branch. For same-repo PRs/MRs, worktrunk switches to the branch directly. For fork PRs/MRs, it fetches the ref (refs/pull/N/head or refs/merge-requests/N/head) and configures pushRemote to the fork URL.