Skip to content

Commit 4033aaa

Browse files
fix(zsh): model and provider selection (#1806)
1 parent 028f671 commit 4033aaa

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

crates/forge_main/src/porcelain.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ impl Porcelain {
7474
})
7575
})
7676
}
77+
78+
pub fn swap_cols(self, col1: usize, col2: usize) -> Self {
79+
Porcelain(
80+
self.0
81+
.into_iter()
82+
.map(|mut row| {
83+
if row.len() > col1.max(col2) {
84+
row.swap(col1, col2);
85+
}
86+
row
87+
})
88+
.collect(),
89+
)
90+
}
7791
#[allow(unused)]
7892
pub fn into_body(self) -> Vec<Vec<Option<String>>> {
7993
// Skip headers and return
@@ -389,6 +403,31 @@ mod tests {
389403
assert_eq!(actual, expected)
390404
}
391405

406+
#[test]
407+
fn test_swap_cols() {
408+
let info = Porcelain(vec![
409+
vec![
410+
Some("user1".into()),
411+
Some("Alice".into()),
412+
Some("30".into()),
413+
],
414+
vec![Some("user2".into()), Some("Bob".into()), Some("25".into())],
415+
]);
416+
417+
let actual = info.swap_cols(0, 1).into_rows();
418+
419+
let expected = vec![
420+
vec![
421+
Some("Alice".into()),
422+
Some("user1".into()),
423+
Some("30".into()),
424+
],
425+
vec![Some("Bob".into()), Some("user2".into()), Some("25".into())],
426+
];
427+
428+
assert_eq!(actual, expected)
429+
}
430+
392431
#[test]
393432
fn test_into_long() {
394433
let info = Info::new()

crates/forge_main/src/ui.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,18 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
629629
}
630630

631631
if porcelain {
632-
self.writeln(Porcelain::from(&info).skip(1).map_col(3, |col| {
633-
if col == Some("Supported".to_owned()) {
634-
Some("🛠️".into())
635-
} else {
636-
None
637-
}
638-
}))?;
632+
self.writeln(
633+
Porcelain::from(&info)
634+
.skip(1)
635+
.swap_cols(0, 1)
636+
.map_col(3, |col| {
637+
if col == Some("Supported".to_owned()) {
638+
Some("🛠️".into())
639+
} else {
640+
None
641+
}
642+
}),
643+
)?;
639644
} else {
640645
self.writeln(info)?;
641646
}

shell-plugin/forge.plugin.zsh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function _forge_select_and_set_config() {
102102

103103
if [[ -n "$selected" ]]; then
104104
local name="${selected%% *}"
105-
_forge_exec config set "--$config_flag" "$name"
105+
_forge_exec config set "$config_flag" "$name"
106106
fi
107107
fi
108108
)
@@ -290,7 +290,7 @@ function _forge_action_provider() {
290290

291291
# Action handler: Select model
292292
function _forge_action_model() {
293-
_forge_select_and_set_config "list models" "model" "Model" "1,3.."
293+
_forge_select_and_set_config "list models" "model" "Model" "2,3.."
294294
_forge_reset
295295
}
296296

0 commit comments

Comments
 (0)