@@ -1310,6 +1310,7 @@ fn global_search(cx: &mut Context) {
13101310
13111311 cx.push_layer(Box::new(prompt));
13121312
1313+ let root = find_root(None).unwrap_or_else(|| PathBuf::from("./"));
13131314 let show_picker = async move {
13141315 let all_matches: Vec<(usize, PathBuf)> =
13151316 UnboundedReceiverStream::new(all_matches_rx).collect().await;
@@ -1321,7 +1322,13 @@ fn global_search(cx: &mut Context) {
13211322 }
13221323 let picker = FilePicker::new(
13231324 all_matches,
1324− move |(_line_num, path)| path.to_str().unwrap().into(),
1325+ move |(_line_num, path)| {
1326+ path.strip_prefix(&root)
1327+ .unwrap_or(path)
1328+ .to_str()
1329+ .unwrap()
1330+ .into()
1331+ },
13251332 move |editor: &mut Editor, (line_num, path), action| {
13261333 match editor.open(path.into(), action) {
13271334 Ok(_) => {}
@@ -1504,7 +1511,7 @@ mod cmd {
15041511 #[derive(Clone)]
15051512 pub struct TypableCommand {
15061513 pub name: &'static str,
1507− pub alias: Option<&'static str>,
1514+ pub aliases: &'static [&'static str],
15081515 pub doc: &'static str,
15091516 // params, flags, helper, completer
15101517 pub fun: fn(&mut compositor::Context, &[&str], PromptEvent) -> anyhow::Result<()>,
@@ -2178,238 +2185,238 @@ mod cmd {
21782185 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
21792186 TypableCommand {
21802187 name: "quit",
2181− alias: Some("q"),
2188+ aliases: &["q"],
21822189 doc: "Close the current view.",
21832190 fun: quit,
21842191 completer: None,
21852192 },
21862193 TypableCommand {
21872194 name: "quit!",
2188− alias: Some("q!"),
2195+ aliases: &["q!"],
21892196 doc: "Close the current view.",
21902197 fun: force_quit,
21912198 completer: None,
21922199 },
21932200 TypableCommand {
21942201 name: "open",
2195− alias: Some("o"),
2202+ aliases: &["o"],
21962203 doc: "Open a file from disk into the current view.",
21972204 fun: open,
21982205 completer: Some(completers::filename),
21992206 },
22002207 TypableCommand {
22012208 name: "write",
2202− alias: Some("w"),
2209+ aliases: &["w"],
22032210 doc: "Write changes to disk. Accepts an optional path (:write some/path.txt)",
22042211 fun: write,
22052212 completer: Some(completers::filename),
22062213 },
22072214 TypableCommand {
22082215 name: "new",
2209− alias: Some("n"),
2216+ aliases: &["n"],
22102217 doc: "Create a new scratch buffer.",
22112218 fun: new_file,
22122219 completer: Some(completers::filename),
22132220 },
22142221 TypableCommand {
22152222 name: "format",
2216− alias: Some("fmt"),
2223+ aliases: &["fmt"],
22172224 doc: "Format the file using a formatter.",
22182225 fun: format,
22192226 completer: None,
22202227 },
22212228 TypableCommand {
22222229 name: "indent-style",
2223− alias: None,
2230+ aliases: &[],
22242231 doc: "Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.)",
22252232 fun: set_indent_style,
22262233 completer: None,
22272234 },
22282235 TypableCommand {
22292236 name: "line-ending",
2230− alias: None,
2237+ aliases: &[],
22312238 doc: "Set the document's default line ending. Options: crlf, lf, cr, ff, nel.",
22322239 fun: set_line_ending,
22332240 completer: None,
22342241 },
22352242 TypableCommand {
22362243 name: "earlier",
2237− alias: Some("ear"),
2244+ aliases: &["ear"],
22382245 doc: "Jump back to an earlier point in edit history. Accepts a number of steps or a time span.",
22392246 fun: earlier,
22402247 completer: None,
22412248 },
22422249 TypableCommand {
22432250 name: "later",
2244− alias: Some("lat"),
2251+ aliases: &["lat"],
22452252 doc: "Jump to a later point in edit history. Accepts a number of steps or a time span.",
22462253 fun: later,
22472254 completer: None,
22482255 },
22492256 TypableCommand {
22502257 name: "write-quit",
2251− alias: Some("wq"),
2258+ aliases: &["wq", "x"],
22522259 doc: "Writes changes to disk and closes the current view. Accepts an optional path (:wq some/path.txt)",
22532260 fun: write_quit,
22542261 completer: Some(completers::filename),
22552262 },
22562263 TypableCommand {
22572264 name: "write-quit!",
2258− alias: Some("wq!"),
2265+ aliases: &["wq!", "x!"],
22592266 doc: "Writes changes to disk and closes the current view forcefully. Accepts an optional path (:wq! some/path.txt)",
22602267 fun: force_write_quit,
22612268 completer: Some(completers::filename),
22622269 },
22632270 TypableCommand {
22642271 name: "write-all",
2265− alias: Some("wa"),
2272+ aliases: &["wa"],
22662273 doc: "Writes changes from all views to disk.",
22672274 fun: write_all,
22682275 completer: None,
22692276 },
22702277 TypableCommand {
22712278 name: "write-quit-all",
2272− alias: Some("wqa"),
2279+ aliases: &["wqa", "xa"],
22732280 doc: "Writes changes from all views to disk and close all views.",
22742281 fun: write_all_quit,
22752282 completer: None,
22762283 },
22772284 TypableCommand {
22782285 name: "write-quit-all!",
2279− alias: Some("wqa!"),
2286+ aliases: &["wqa!", "xa!"],
22802287 doc: "Writes changes from all views to disk and close all views forcefully (ignoring unsaved changes).",
22812288 fun: force_write_all_quit,
22822289 completer: None,
22832290 },
22842291 TypableCommand {
22852292 name: "quit-all",
2286− alias: Some("qa"),
2293+ aliases: &["qa"],
22872294 doc: "Close all views.",
22882295 fun: quit_all,
22892296 completer: None,
22902297 },
22912298 TypableCommand {
22922299 name: "quit-all!",
2293− alias: Some("qa!"),
2300+ aliases: &["qa!"],
22942301 doc: "Close all views forcefully (ignoring unsaved changes).",
22952302 fun: force_quit_all,
22962303 completer: None,
22972304 },
22982305 TypableCommand {
22992306 name: "theme",
2300− alias: None,
2307+ aliases: &[],
23012308 doc: "Change the theme of current view. Requires theme name as argument (:theme <name>)",
23022309 fun: theme,
23032310 completer: Some(completers::theme),
23042311 },
23052312 TypableCommand {
23062313 name: "clipboard-yank",
2307− alias: None,
2314+ aliases: &[],
23082315 doc: "Yank main selection into system clipboard.",
23092316 fun: yank_main_selection_to_clipboard,
23102317 completer: None,
23112318 },
23122319 TypableCommand {
23132320 name: "clipboard-yank-join",
2314− alias: None,
2321+ aliases: &[],
23152322 doc: "Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc.
23162323 fun: yank_joined_to_clipboard,
23172324 completer: None,
23182325 },
23192326 TypableCommand {
23202327 name: "primary-clipboard-yank",
2321− alias: None,
2328+ aliases: &[],
23222329 doc: "Yank main selection into system primary clipboard.",
23232330 fun: yank_main_selection_to_primary_clipboard,
23242331 completer: None,
23252332 },
23262333 TypableCommand {
23272334 name: "primary-clipboard-yank-join",
2328− alias: None,
2335+ aliases: &[],
23292336 doc: "Yank joined selections into system primary clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc.
23302337 fun: yank_joined_to_primary_clipboard,
23312338 completer: None,
23322339 },
23332340 TypableCommand {
23342341 name: "clipboard-paste-after",
2335− alias: None,
2342+ aliases: &[],
23362343 doc: "Paste system clipboard after selections.",
23372344 fun: paste_clipboard_after,
23382345 completer: None,
23392346 },
23402347 TypableCommand {
23412348 name: "clipboard-paste-before",
2342− alias: None,
2349+ aliases: &[],
23432350 doc: "Paste system clipboard before selections.",
23442351 fun: paste_clipboard_before,
23452352 completer: None,
23462353 },
23472354 TypableCommand {
23482355 name: "clipboard-paste-replace",
2349− alias: None,
2356+ aliases: &[],
23502357 doc: "Replace selections with content of system clipboard.",
23512358 fun: replace_selections_with_clipboard,
23522359 completer: None,
23532360 },
23542361 TypableCommand {
23552362 name: "primary-clipboard-paste-after",
2356− alias: None,
2363+ aliases: &[],
23572364 doc: "Paste primary clipboard after selections.",
23582365 fun: paste_primary_clipboard_after,
23592366 completer: None,
23602367 },
23612368 TypableCommand {
23622369 name: "primary-clipboard-paste-before",
2363− alias: None,
2370+ aliases: &[],
23642371 doc: "Paste primary clipboard before selections.",
23652372 fun: paste_primary_clipboard_before,
23662373 completer: None,
23672374 },
23682375 TypableCommand {
23692376 name: "primary-clipboard-paste-replace",
2370− alias: None,
2377+ aliases: &[],
23712378 doc: "Replace selections with content of system primary clipboard.",
23722379 fun: replace_selections_with_primary_clipboard,
23732380 completer: None,
23742381 },
23752382 TypableCommand {
23762383 name: "show-clipboard-provider",
2377− alias: None,
2384+ aliases: &[],
23782385 doc: "Show clipboard provider name in status bar.",
23792386 fun: show_clipboard_provider,
23802387 completer: None,
23812388 },
23822389 TypableCommand {
23832390 name: "change-current-directory",
2384− alias: Some("cd"),
2391+ aliases: &["cd"],
23852392 doc: "Change the current working directory (:cd <dir>).",
23862393 fun: change_current_directory,
23872394 completer: Some(completers::directory),
23882395 },
23892396 TypableCommand {
23902397 name: "show-directory",
2391− alias: Some("pwd"),
2398+ aliases: &["pwd"],
23922399 doc: "Show the current working directory.",
23932400 fun: show_current_directory,
23942401 completer: None,
23952402 },
23962403 TypableCommand {
23972404 name: "encoding",
2398− alias: None,
2405+ aliases: &[],
23992406 doc: "Set encoding based on `https://encoding.spec.whatwg.org`",
24002407 fun: set_encoding,
24012408 completer: None,
24022409 },
24032410 TypableCommand {
24042411 name: "reload",
2405− alias: None,
2412+ aliases: &[],
24062413 doc: "Discard changes and reload from the source file.",
24072414 fun: reload,
24082415 completer: None,
24092416 },
24102417 TypableCommand {
24112418 name: "tree-sitter-scopes",
2412− alias: None,
2419+ aliases: &[],
24132420 doc: "Display tree sitter scopes, primarily for theming and development.",
24142421 fun: tree_sitter_scopes,
24152422 completer: None,
@@ -2437,14 +2444,14 @@ mod cmd {
24372444 },
24382445 TypableCommand {
24392446 name: "vsplit",
2440− alias: Some("vs"),
2447+ aliases: &["vs"],
24412448 doc: "Open the file in a vertical split.",
24422449 fun: vsplit,
24432450 completer: Some(completers::filename),
24442451 },
24452452 TypableCommand {
24462453 name: "hsplit",
2447− alias: Some("sp"),
2454+ aliases: &["hs", "sp"],
24482455 doc: "Open the file in a horizontal split.",
24492456 fun: hsplit,
24502457 completer: Some(completers::filename),
@@ -2452,16 +2459,13 @@ mod cmd {
24522459 ];
24532460
24542461 pub static COMMANDS: Lazy<HashMap<&'static str, &'static TypableCommand>> = Lazy::new(|| {
2455− let mut map = HashMap::new();
2456−
2457− for cmd in TYPABLE_COMMAND_LIST {
2458− map.insert(cmd.name, cmd);
2459− if let Some(alias) = cmd.alias {
2460− map.insert(alias, cmd);
2461− }
2462− }
2463−
2464− map
2462+ TYPABLE_COMMAND_LIST
2463+ .iter()
2464+ .flat_map(|cmd| {
2465+ std::iter::once((cmd.name, cmd))
2466+ .chain(cmd.aliases.iter().map(move |&alias| (alias, cmd)))
2467+ })
2468+ .collect()
24652469 });
24662470}
24672471