Current working directory status (#10998)

Co-authored-by: mfirhas <mfathirirhas@gmail.com>
This commit is contained in:
Muhammad Fathir Irhas
2025-07-27 04:12:07 +07:00
committed by GitHub
parent fe2291a59b
commit 6ea3677b9f
3 changed files with 18 additions and 0 deletions

View File

@@ -132,6 +132,7 @@ The following statusline elements can be configured:
| `file-name` | The path/name of the opened file |
| `file-absolute-path` | The absolute path/name of the opened file |
| `file-base-name` | The basename of the opened file |
| `current-working-directory` | The current working directory |
| `file-modification-indicator` | The indicator to show whether the file is modified (a `[+]` appears when there are unsaved changes) |
| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
| `file-line-ending` | The file line endings (CRLF or LF) |

View File

@@ -158,6 +158,7 @@ where
helix_view::editor::StatusLineElement::Spacer => render_spacer,
helix_view::editor::StatusLineElement::VersionControl => render_version_control,
helix_view::editor::StatusLineElement::Register => render_register,
helix_view::editor::StatusLineElement::CurrentWorkingDirectory => render_cwd,
}
}
@@ -573,3 +574,16 @@ where
},
);
}
fn render_cwd<'a, F>(context: &mut RenderContext<'a>, write: F)
where
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
{
let cwd = helix_stdx::env::current_working_dir();
let cwd = cwd
.file_name()
.unwrap_or_default()
.to_string_lossy()
.to_string();
write(context, cwd.into())
}

View File

@@ -628,6 +628,9 @@ pub enum StatusLineElement {
/// Indicator for selected register
Register,
/// The base of current working directory
CurrentWorkingDirectory,
}
// Cursor shape is read and used on every rendered frame and so needs