Skip to content

Commit 7352200

Browse files
theteachrhadronized
authored andcommitted
Add a status line element that shows just the basename of the file (helix-editor#5318)
1 parent 10b27ea commit 7352200

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

book/src/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
429450
fn render_separator<F>(context: &mut RenderContext, write: F)
430451
where
431452
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,

helix-view/src/editor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,10 @@ pub enum StatusLineElement {
414414
/// The LSP activity spinner
415415
Spinner,
416416

417-
/// The file nane/path, including a dirty flag if it's unsaved
417+
/// The base file name, including a dirty flag if it's unsaved
418+
FileBaseName,
419+
420+
/// The relative file path, including a dirty flag if it's unsaved
418421
FileName,
419422

420423
/// The file encoding

0 commit comments

Comments
 (0)