on master help sign in
Add a status line element that shows just the basename of the file (#5318)
commitc9ed42cdec95b67b0d0ed15218daff37358ca86f authorNick <sop.theteachr@gmail.com> dateSat 31 Dec 2022, 19:48 (4 years ago) parent63dcaae
3 files changed+26−1
book/src/configuration.md+1 helix-term/src/ui/statusline.rs+21 helix-view/src/editor.rs+4−1
book/src/configuration.md+1
@@ -97,6 +97,7 @@ The following statusline elements can be configured:
9797| `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) |
9898| `spinner` | A progress spinner indicating LSP activity |
9999| `file-name` | The path/name of the opened file |
100+| `file-base-name` | The basename of the opened file |
100101| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
101102| `file-line-ending` | The file line endings (CRLF or LF) |
102103| `total-line-numbers` | The total line numbers of the opened file |
helix-term/src/ui/statusline.rs+21
@@ -139,6 +139,7 @@ where
139139 match element_id {
140140 helix_view::editor::StatusLineElement::Mode => render_mode,
141141 helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
142+ helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name,
142143 helix_view::editor::StatusLineElement::FileName => render_file_name,
143144 helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding,
144145 helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
@@ -426,6 +427,26 @@ where
426427 write(context, title, None);
427428}
428429
430+fn render_file_base_name<F>(context: &mut RenderContext, write: F)
431+where
432+ F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
433+{
434+ let title = {
435+ let rel_path = context.doc.relative_path();
436+ let path = rel_path
437+ .as_ref()
438+ .and_then(|p| p.as_path().file_name().map(|s| s.to_string_lossy()))
439+ .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
440+ format!(
441+ " {}{} ",
442+ path,
443+ if context.doc.is_modified() { "[+]" } else { "" }
444+ )
445+ };
446+
447+ write(context, title, None);
448+}
449+
429450fn render_separator<F>(context: &mut RenderContext, write: F)
430451where
431452 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
helix-view/src/editor.rs+4−1
@@ -314,7 +314,10 @@ pub enum StatusLineElement {
314314 /// The LSP activity spinner
315315 Spinner,
316316
317− /// The file nane/path, including a dirty flag if it's unsaved
317+ /// The base file name, including a dirty flag if it's unsaved
318+ FileBaseName,
319+
320+ /// The relative file path, including a dirty flag if it's unsaved
318321 FileName,
319322
320323 /// The file encoding