on master help sign in
Add command for picking files from CWD (#1600)

The `file_picker_at_current_directory` command opens the file picker at the current working directory (CWD). This can be useful when paired with the built-in `:cd` command which changes the CWD. It has been mapped to `space F` by default.

commit562874a720678a238966c69f413cb3d691f74c66 authorgavynriebau <gavyn.riebau@gmail.com> dateSun 10 Apr 2022, 10:30 (5 years ago) parent494306a
2 files changed+8
helix-term/src/commands.rs+7 helix-term/src/keymap/default.rs+1
helix-term/src/commands.rs+7
@@ -259,6 +259,7 @@ impl MappableCommand {
259259 append_mode, "Insert after selection (append)",
260260 command_mode, "Enter command mode",
261261 file_picker, "Open file picker",
262+ file_picker_in_current_directory, "Open file picker at current working directory",
262263 code_action, "Perform code action",
263264 buffer_picker, "Open buffer picker",
264265 symbol_picker, "Open symbol picker",
@@ -2047,6 +2048,12 @@ fn file_picker(cx: &mut Context) {
20472048 cx.push_layer(Box::new(overlayed(picker)));
20482049}
20492050
2051+fn file_picker_in_current_directory(cx: &mut Context) {
2052+ let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("./"));
2053+ let picker = ui::file_picker(cwd, &cx.editor.config());
2054+ cx.push_layer(Box::new(picker));
2055+}
2056+
20502057fn buffer_picker(cx: &mut Context) {
20512058 let current = view!(cx.editor).doc;
20522059
helix-term/src/keymap/default.rs+1
@@ -196,6 +196,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
196196
197197 "space" => { "Space"
198198 "f" => file_picker,
199+ "F" => file_picker_in_current_directory,
199200 "b" => buffer_picker,
200201 "s" => symbol_picker,
201202 "S" => workspace_symbol_picker,