Commit 7d66421863

7d664218631eab010ba3d38a19aa80c4fbfd9605

parent: b57b5b86df

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-09-18 23:40 UTC
committer: <noreply@github.com>

Support user-defined command aliases (#715)

Layout: unified · split

Cargo.lock +4 −4
@@ -3841,9 +3841,9 @@ dependencies = [
38413841
38423842[[package]]
38433843name = "modalkit"
3844version = "0.0.27"
3844version = "0.0.28"
38453845source = "registry+https://github.com/rust-lang/crates.io-index"
3846checksum = "de93aca188fc0e518c7c89782c3cb62ae4e14552398f2baaed9c5168b3ca1b3d"
3846checksum = "b8a62517886d7f5d7b476ac8458805073df47941d99861de81347861f4d03d3e"
38473847dependencies = [
38483848 "anymap2",
38493849 "arboard",
@@ -3865,9 +3865,9 @@ dependencies = [
38653865
38663866[[package]]
38673867name = "modalkit-ratatui"
3868version = "0.0.27"
3868version = "0.0.28"
38693869source = "registry+https://github.com/rust-lang/crates.io-index"
3870checksum = "cf64561c3f42a3a587d564fde9274fdbcf95287281efd56fc0db6a1c12459730"
3870checksum = "2fd45bce81ff69f3cb2126b0d59aafe74c3982a2f8be68f49dc14f3c7c180629"
38713871dependencies = [
38723872 "crossterm 0.29.0",
38733873 "intervaltree",
Cargo.toml +2 −2
@@ -83,13 +83,13 @@ version = "4.12"
8383optional = true
8484
8585[dependencies.modalkit]
86version = "0.0.27"
86version = "0.0.28"
8787default-features = false
8888#git = "https://github.com/ulyssa/modalkit"
8989#rev = "9386f6f75f6984a1cdbd7dddbb0c0bb3e7a37c5d"
9090
9191[dependencies.modalkit-ratatui]
92version = "0.0.27"
92version = "0.0.28"
9393#git = "https://github.com/ulyssa/modalkit"
9494#rev = "9386f6f75f6984a1cdbd7dddbb0c0bb3e7a37c5d"
9595
config.example.toml +10
@@ -73,6 +73,16 @@ split = [
7373[macros."normal|visual"]
7474"V" = "<C-W>m"
7575
76[aliases]
77"c" = "chats"
78"d" = "download"
79"e" = "edit"
80"o" = "open"
81"r" = "rooms"
82"ed" = "editor"
83"ca" = "cancel"
84"red" = "redact"
85
7686[dirs]
7787cache = "/home/user/.cache/iamb/"
7888logs = "/home/user/.local/share/iamb/logs/"
docs/iamb.5 +13
@@ -719,6 +719,19 @@ split = [
719719 { "window" = "#iamb-dev:0x.badd.cafe" }
720720]
721721.Ed
722.Sh "CUSTOM COMMAND ALIASES"
723The
724.Sy aliases
725subsections allow configuring custom aliases.
726.Ss Example 1: Alias commands to single-letter versions
727.Bd -literal -offset indent
728[aliases]
729"c" = "chats"
730"d" = "download"
731"e" = "edit"
732"o" = "open"
733"r" = "rooms"
734.Ed
722735.Sh "CUSTOM KEYBINDINGS"
723736The
724737.Sy macros
src/base.rs +7 −4
@@ -1945,14 +1945,15 @@ pub struct ChatStore {
19451945
19461946impl ChatStore {
19471947 /// Create a new [ChatStore].
1948 pub fn new(worker: Requester, settings: ApplicationSettings) -> Self {
1948 pub fn new(worker: Requester, settings: ApplicationSettings) -> IambResult<Self> {
19491949 let previews = PreviewManager::new(&settings);
1950 let cmds = crate::commands::setup_commands(&settings.aliases)?;
19501951
1951 ChatStore {
1952 let store = ChatStore {
19521953 worker,
19531954 settings,
19541955 previews,
1955 cmds: crate::commands::setup_commands(),
1956 cmds,
19561957 emojis: emoji_map(),
19571958
19581959 collator: Default::default(),
@@ -1966,7 +1967,9 @@ impl ChatStore {
19661967 ring_bell: false,
19671968 focused: true,
19681969 open_notifications: Default::default(),
1969 }
1970 };
1971
1972 Ok(store)
19701973 }
19711974
19721975 /// Get a joined room.
src/commands.rs +33 −25
@@ -1175,12 +1175,16 @@ pub fn add_iamb_commands(cmds: &mut ProgramCommands) {
11751175}
11761176
11771177/// Initialize the default command state.
1178pub fn setup_commands() -> ProgramCommands {
1178pub fn setup_commands(aliases: &HashMap<String, String>) -> Result<ProgramCommands, CommandError> {
11791179 let mut cmds = ProgramCommands::default();
11801180
11811181 add_iamb_commands(&mut cmds);
11821182
1183 return cmds;
1183 for (alias, cmd) in aliases {
1184 cmds.add_alias(alias, cmd)?;
1185 }
1186
1187 Ok(cmds)
11841188}
11851189
11861190#[cfg(test)]
@@ -1191,9 +1195,13 @@ mod tests {
11911195 use modalkit::actions::WindowAction;
11921196 use modalkit::editing::context::EditContext;
11931197
1198 fn setup_test_commands() -> ProgramCommands {
1199 setup_commands(&HashMap::new()).unwrap()
1200 }
1201
11941202 #[test]
11951203 fn test_cmd_verify() {
1196 let mut cmds = setup_commands();
1204 let mut cmds = setup_test_commands();
11971205 let ctx = EditContext::default();
11981206
11991207 let res = cmds.input_cmd(":verify", ctx.clone()).unwrap();
@@ -1251,7 +1259,7 @@ mod tests {
12511259
12521260 #[test]
12531261 fn test_cmd_join() {
1254 let mut cmds = setup_commands();
1262 let mut cmds = setup_test_commands();
12551263 let ctx = EditContext::default();
12561264
12571265 let res = cmds.input_cmd("join #foobar:example.com", ctx.clone()).unwrap();
@@ -1271,7 +1279,7 @@ mod tests {
12711279
12721280 #[test]
12731281 fn test_cmd_room_invalid() {
1274 let mut cmds = setup_commands();
1282 let mut cmds = setup_test_commands();
12751283 let ctx = EditContext::default();
12761284
12771285 let res = cmds.input_cmd("room", ctx.clone());
@@ -1286,7 +1294,7 @@ mod tests {
12861294
12871295 #[test]
12881296 fn test_cmd_room_topic_set() {
1289 let mut cmds = setup_commands();
1297 let mut cmds = setup_test_commands();
12901298 let ctx = EditContext::default();
12911299
12921300 let res = cmds
@@ -1317,7 +1325,7 @@ mod tests {
13171325
13181326 #[test]
13191327 fn test_cmd_room_name_invalid() {
1320 let mut cmds = setup_commands();
1328 let mut cmds = setup_test_commands();
13211329 let ctx = EditContext::default();
13221330
13231331 let res = cmds.input_cmd("room name", ctx.clone());
@@ -1329,7 +1337,7 @@ mod tests {
13291337
13301338 #[test]
13311339 fn test_cmd_room_name_set() {
1332 let mut cmds = setup_commands();
1340 let mut cmds = setup_test_commands();
13331341 let ctx = EditContext::default();
13341342
13351343 let res = cmds.input_cmd("room name set Development", ctx.clone()).unwrap();
@@ -1348,7 +1356,7 @@ mod tests {
13481356
13491357 #[test]
13501358 fn test_cmd_room_name_unset() {
1351 let mut cmds = setup_commands();
1359 let mut cmds = setup_test_commands();
13521360 let ctx = EditContext::default();
13531361
13541362 let res = cmds.input_cmd("room name unset", ctx.clone()).unwrap();
@@ -1361,7 +1369,7 @@ mod tests {
13611369
13621370 #[test]
13631371 fn test_cmd_room_dm_set() {
1364 let mut cmds = setup_commands();
1372 let mut cmds = setup_test_commands();
13651373 let ctx = EditContext::default();
13661374
13671375 let res = cmds.input_cmd("room dm set", ctx.clone()).unwrap();
@@ -1374,7 +1382,7 @@ mod tests {
13741382
13751383 #[test]
13761384 fn test_cmd_room_dm_unset() {
1377 let mut cmds = setup_commands();
1385 let mut cmds = setup_test_commands();
13781386 let ctx = EditContext::default();
13791387
13801388 let res = cmds.input_cmd("room dm unset", ctx.clone()).unwrap();
@@ -1387,7 +1395,7 @@ mod tests {
13871395
13881396 #[test]
13891397 fn test_cmd_room_tag_set() {
1390 let mut cmds = setup_commands();
1398 let mut cmds = setup_test_commands();
13911399 let ctx = EditContext::default();
13921400
13931401 let res = cmds.input_cmd("room tag set favourite", ctx.clone()).unwrap();
@@ -1456,7 +1464,7 @@ mod tests {
14561464
14571465 #[test]
14581466 fn test_cmd_room_tag_unset() {
1459 let mut cmds = setup_commands();
1467 let mut cmds = setup_test_commands();
14601468 let ctx = EditContext::default();
14611469
14621470 let res = cmds.input_cmd("room tag unset favourite", ctx.clone()).unwrap();
@@ -1521,7 +1529,7 @@ mod tests {
15211529
15221530 #[test]
15231531 fn test_cmd_room_notification_mode_set() {
1524 let mut cmds = setup_commands();
1532 let mut cmds = setup_test_commands();
15251533 let ctx = EditContext::default();
15261534
15271535 let cmd = "room notify set mute";
@@ -1542,7 +1550,7 @@ mod tests {
15421550
15431551 #[test]
15441552 fn test_cmd_room_id_show() {
1545 let mut cmds = setup_commands();
1553 let mut cmds = setup_test_commands();
15461554 let ctx = EditContext::default();
15471555
15481556 let res = cmds.input_cmd("room id show", ctx.clone()).unwrap();
@@ -1555,7 +1563,7 @@ mod tests {
15551563
15561564 #[test]
15571565 fn test_cmd_space_child() {
1558 let mut cmds = setup_commands();
1566 let mut cmds = setup_test_commands();
15591567 let ctx = EditContext::default();
15601568
15611569 let cmd = "space";
@@ -1573,7 +1581,7 @@ mod tests {
15731581
15741582 #[test]
15751583 fn test_cmd_space_child_set() {
1576 let mut cmds = setup_commands();
1584 let mut cmds = setup_test_commands();
15771585 let ctx = EditContext::default();
15781586
15791587 let cmd = "space child set !roomid:example.org";
@@ -1624,7 +1632,7 @@ mod tests {
16241632
16251633 #[test]
16261634 fn test_cmd_space_child_remove() {
1627 let mut cmds = setup_commands();
1635 let mut cmds = setup_test_commands();
16281636 let ctx = EditContext::default();
16291637
16301638 let cmd = "space child remove";
@@ -1639,7 +1647,7 @@ mod tests {
16391647
16401648 #[test]
16411649 fn test_cmd_invite() {
1642 let mut cmds = setup_commands();
1650 let mut cmds = setup_test_commands();
16431651 let ctx = EditContext::default();
16441652
16451653 let res = cmds.input_cmd("invite accept", ctx.clone()).unwrap();
@@ -1676,7 +1684,7 @@ mod tests {
16761684
16771685 #[test]
16781686 fn test_cmd_room_kick() {
1679 let mut cmds = setup_commands();
1687 let mut cmds = setup_test_commands();
16801688 let ctx = EditContext::default();
16811689
16821690 let res = cmds.input_cmd("room kick @user:example.com", ctx.clone()).unwrap();
@@ -1711,7 +1719,7 @@ mod tests {
17111719
17121720 #[test]
17131721 fn test_cmd_room_ban_unban() {
1714 let mut cmds = setup_commands();
1722 let mut cmds = setup_test_commands();
17151723 let ctx = EditContext::default();
17161724
17171725 let res = cmds
@@ -1739,7 +1747,7 @@ mod tests {
17391747
17401748 #[test]
17411749 fn test_cmd_redact() {
1742 let mut cmds = setup_commands();
1750 let mut cmds = setup_test_commands();
17431751 let ctx = EditContext::default();
17441752
17451753 let res = cmds.input_cmd("redact", ctx.clone()).unwrap();
@@ -1764,7 +1772,7 @@ mod tests {
17641772
17651773 #[test]
17661774 fn test_cmd_keys() {
1767 let mut cmds = setup_commands();
1775 let mut cmds = setup_test_commands();
17681776 let ctx = EditContext::default();
17691777
17701778 let res = cmds.input_cmd("keys import /a/b/c pword", ctx.clone()).unwrap();
@@ -1791,7 +1799,7 @@ mod tests {
17911799
17921800 #[test]
17931801 fn test_cmd_multiple_trailing() {
1794 let mut cmds = setup_commands();
1802 let mut cmds = setup_test_commands();
17951803 let ctx = EditContext::default();
17961804
17971805 // Trailing arguments disallowed on commands that don't take any:
@@ -1838,7 +1846,7 @@ mod tests {
18381846
18391847 #[test]
18401848 fn test_cmd_room_access() {
1841 let mut cmds = setup_commands();
1849 let mut cmds = setup_test_commands();
18421850 let ctx = EditContext::default();
18431851
18441852 let res = cmds.input_cmd("room access set knock", ctx.clone()).unwrap();
src/config.rs +18
@@ -26,6 +26,7 @@ use serde::{Deserialize, Deserializer, Serialize};
2626use crate::base::{SortColumn, SortFieldRoom, SortFieldUser, SortOrder};
2727use crate::prelude::*;
2828
29type Aliases = HashMap<String, String>;
2930type Macros = HashMap<VimModes, HashMap<Keys, Keys>>;
3031
3132macro_rules! usage {
@@ -1205,6 +1206,7 @@ pub struct ProfileConfig {
12051206 pub dirs: Option<Directories>,
12061207 pub layout: Option<Layout>,
12071208 pub macros: Option<Macros>,
1209 pub aliases: Option<Aliases>,
12081210}
12091211
12101212#[derive(Clone, Deserialize)]
@@ -1215,6 +1217,7 @@ pub struct IambConfig {
12151217 pub dirs: Option<Directories>,
12161218 pub layout: Option<Layout>,
12171219 pub macros: Option<Macros>,
1220 pub aliases: Option<Aliases>,
12181221}
12191222
12201223impl IambConfig {
@@ -1247,6 +1250,7 @@ pub struct ApplicationSettings {
12471250 pub dirs: DirectoryValues,
12481251 pub layout: Layout,
12491252 pub macros: Macros,
1253 pub aliases: Aliases,
12501254
12511255 /// Whether to use the Kitty keyboard protocol. Resolved by
12521256 /// [`ApplicationSettings::probe_enhanced_keys`] once the TUI starts, since
@@ -1295,6 +1299,7 @@ impl ApplicationSettings {
12951299 settings: global,
12961300 layout,
12971301 macros,
1302 aliases,
12981303 } = config;
12991304
13001305 validate_profile_names(&profiles);
@@ -1336,6 +1341,7 @@ impl ApplicationSettings {
13361341 }
13371342 };
13381343
1344 let aliases = merge_maps(profile.aliases.take(), aliases).unwrap_or_default();
13391345 let macros = merge_maps(profile.macros.take(), macros).unwrap_or_default();
13401346 let layout = profile.layout.take().or(layout).unwrap_or_default();
13411347
@@ -1395,6 +1401,7 @@ impl ApplicationSettings {
13951401 dirs,
13961402 layout,
13971403 macros,
1404 aliases,
13981405 enable_enhanced_keys: false,
13991406 };
14001407
@@ -1816,6 +1823,15 @@ mod tests {
18161823 assert_eq!(res, Layout::Config { tabs });
18171824 }
18181825
1826 #[test]
1827 fn test_parse_aliases() {
1828 let res: Aliases = serde_json::from_str("{\"c\":\"chats\"}").unwrap();
1829 assert_eq!(res.len(), 1);
1830
1831 let aliased = res.get("c").unwrap();
1832 assert_eq!(aliased, "chats");
1833 }
1834
18191835 #[test]
18201836 fn test_parse_macros() {
18211837 let res: Macros = serde_json::from_str("{\"i|c\":{\"jj\":\"<Esc>\"}}").unwrap();
@@ -1880,6 +1896,7 @@ mod tests {
18801896 dirs,
18811897 layout,
18821898 macros,
1899 aliases,
18831900 } = &config;
18841901
18851902 // There should be an example object for each top-level field.
@@ -1889,6 +1906,7 @@ mod tests {
18891906 assert!(dirs.is_some());
18901907 assert!(layout.is_some());
18911908 assert!(macros.is_some());
1909 assert!(aliases.is_some());
18921910 }
18931911
18941912 #[test]
src/keybindings.rs +1 −1
@@ -23,7 +23,7 @@ pub fn setup_keybindings() -> Keybindings {
2323 let mut ism = Keybindings::empty();
2424
2525 let vim = VimBindings::default()
26 .submit_on_enter()
26 .submit_on_enter(false)
2727 .cursor_open(MATRIX_ID_WORD.clone());
2828
2929 vim.setup(&mut ism);
src/main.rs +1 −1
@@ -1111,7 +1111,7 @@ async fn run(
11111111
11121112 // Set up the async worker thread and global store.
11131113 let worker = ClientWorker::spawn(client.clone(), settings.clone()).await;
1114 let store = ChatStore::new(worker.clone(), settings.clone());
1114 let store = ChatStore::new(worker.clone(), settings.clone())?;
11151115 let mut store = Store::new(store);
11161116 store.completer = Box::new(IambCompleter);
11171117
src/tests.rs +3 −1
@@ -221,11 +221,13 @@ pub fn mock_settings() -> ApplicationSettings {
221221 dirs: None,
222222 layout: None,
223223 macros: None,
224 aliases: None,
224225 },
225226 tunables: mock_tunables(),
226227 dirs: mock_dirs(),
227228 layout: Default::default(),
228229 macros: HashMap::default(),
230 aliases: HashMap::default(),
229231 enable_enhanced_keys: false,
230232 }
231233}
@@ -242,7 +244,7 @@ pub async fn mock_store() -> ProgramStore {
242244 .unwrap();
243245 let worker = Requester { tx, receipts, client };
244246
245 let mut store = ChatStore::new(worker, mock_settings());
247 let mut store = ChatStore::new(worker, mock_settings()).unwrap();
246248
247249 // Add presence information.
248250 store.presences.get_or_default(TEST_USER1.clone());