Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions book/src/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ The following variables are supported:
| `file_path_absolute` | The absolute path of the currently focused document. For scratch buffers this will default to the current working directory. |
| `line_ending` | A string containing the line ending of the currently focused document. For example on Unix systems this is usually a line-feed character (`\n`) but on Windows systems this may be a carriage-return plus a line-feed (`\r\n`). The line ending kind of the currently focused document can be inspected with the `:line-ending` command. |
| `current_working_directory` | Current working directory |
| `current_working_directory_name` | Basename of the current working directory |
| `workspace_directory` | Nearest ancestor directory of the current working directory that contains `.git`, `.svn`, `jj` or `.helix` |
| `workspace_directory_name` | Basename of the workspace directory |
| `language` | A string containing the language name of the currently focused document.|
| `selection` | A string containing the contents of the primary selection of the currently focused document. |
| `selection_line_start` | The line number of the start of the primary selection in the currently focused document, starting at 1. |
Expand Down
5 changes: 4 additions & 1 deletion book/src/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ 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 |
| `current-working-directory` | The path of the current working directory |
| `current-working-directory-name` | The basename of current working directory |
| `workspace-directory` | Nearest ancestor directory of the current working directory that contains `.git`, `.svn`, `jj` or `.helix` |
| `workspace-directory-name` | Basename of the workspace 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) |
Expand Down
36 changes: 36 additions & 0 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ where
helix_view::editor::StatusLineElement::VersionControl => render_version_control,
helix_view::editor::StatusLineElement::Register => render_register,
helix_view::editor::StatusLineElement::CurrentWorkingDirectory => render_cwd,
helix_view::editor::StatusLineElement::CurrentWorkingDirectoryName => render_cwd_name,
helix_view::editor::StatusLineElement::WorkspaceDirectory => render_workspace,
helix_view::editor::StatusLineElement::WorkspaceDirectoryName => render_workspace_name,
}
}

Expand Down Expand Up @@ -572,6 +575,15 @@ 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.as_path().to_string_lossy().to_string();
write(context, cwd.into())
}

fn render_cwd_name<'a, F>(context: &mut RenderContext<'a>, write: F)
where
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
{
Expand All @@ -583,3 +595,27 @@ where
.to_string();
write(context, cwd.into())
}

fn render_workspace<'a, F>(context: &mut RenderContext<'a>, write: F)
where
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
{
let workspace = helix_loader::find_workspace()
.0
.to_string_lossy()
.to_string();
write(context, workspace.into())
}

fn render_workspace_name<'a, F>(context: &mut RenderContext<'a>, write: F)
where
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
{
let workspace = helix_loader::find_workspace()
.0
.file_name()
.unwrap_or_default()
.to_string_lossy()
.to_string();
write(context, workspace.into())
}
11 changes: 10 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,17 @@ pub enum StatusLineElement {
/// Indicator for selected register
Register,

/// The base of current working directory
/// The path of current working directory
CurrentWorkingDirectory,

/// The basename of current working directory
CurrentWorkingDirectoryName,

/// Nearest ancestor directory of the current working directory that contains `.git`, `.svn`, `jj` or `.helix`
WorkspaceDirectory,

/// Basename of the workspace directory
WorkspaceDirectoryName,
}

// Cursor shape is read and used on every rendered frame and so needs
Expand Down
35 changes: 30 additions & 5 deletions helix-view/src/expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ pub enum Variable {
FilePathAbsolute,
/// A string containing the line-ending of the currently focused document.
LineEnding,
/// Curreng working directory
/// Current working directory
CurrentWorkingDirectory,
/// Basename of the current working directory
CurrentWorkingDirectoryName,
/// Nearest ancestor directory of the current working directory that contains `.git`, `.svn`, `jj` or `.helix`
WorkspaceDirectory,
// The name of current buffers language as set in `languages.toml`
/// Basename of the workspace directory
WorkspaceDirectoryName,
/// The name of current buffers language as set in `languages.toml`
Language,
// Primary selection
/// Primary selection
Selection,
// The one-indexed line number of the start of the primary selection in the currently focused document.
/// The one-indexed line number of the start of the primary selection in the currently focused document.
SelectionLineStart,
// The one-indexed line number of the end of the primary selection in the currently focused document.
/// The one-indexed line number of the end of the primary selection in the currently focused document.
SelectionLineEnd,
}

Expand All @@ -58,7 +62,9 @@ impl Variable {
Self::FilePathAbsolute,
Self::LineEnding,
Self::CurrentWorkingDirectory,
Self::CurrentWorkingDirectoryName,
Self::WorkspaceDirectory,
Self::WorkspaceDirectoryName,
Self::Language,
Self::Selection,
Self::SelectionLineStart,
Expand All @@ -73,7 +79,9 @@ impl Variable {
Self::FilePathAbsolute => "file_path_absolute",
Self::LineEnding => "line_ending",
Self::CurrentWorkingDirectory => "current_working_directory",
Self::CurrentWorkingDirectoryName => "current_working_directory_name",
Self::WorkspaceDirectory => "workspace_directory",
Self::WorkspaceDirectoryName => "workspace_directory_name",
Self::Language => "language",
Self::Selection => "selection",
Self::SelectionLineStart => "selection_line_start",
Expand All @@ -89,7 +97,9 @@ impl Variable {
"file_path_absolute" => Some(Self::FilePathAbsolute),
"line_ending" => Some(Self::LineEnding),
"workspace_directory" => Some(Self::WorkspaceDirectory),
"workspace_directory_name" => Some(Self::WorkspaceDirectoryName),
"current_working_directory" => Some(Self::CurrentWorkingDirectory),
"current_working_directory_name" => Some(Self::CurrentWorkingDirectoryName),
"language" => Some(Self::Language),
"selection" => Some(Self::Selection),
"selection_line_start" => Some(Self::SelectionLineStart),
Expand Down Expand Up @@ -265,12 +275,27 @@ fn expand_variable(editor: &Editor, variable: Variable) -> Result<Cow<'static, s
.to_string_lossy()
.to_string(),
)),
Variable::CurrentWorkingDirectoryName => Ok(std::borrow::Cow::Owned(
helix_stdx::env::current_working_dir()
.file_name()
.unwrap_or_default()
.to_string_lossy()
.to_string(),
)),
Variable::WorkspaceDirectory => Ok(std::borrow::Cow::Owned(
helix_loader::find_workspace()
.0
.to_string_lossy()
.to_string(),
)),
Variable::WorkspaceDirectoryName => Ok(std::borrow::Cow::Owned(
helix_loader::find_workspace()
.0
.file_name()
.unwrap_or_default()
.to_string_lossy()
.to_string(),
)),
Variable::Language => Ok(match doc.language_name() {
Some(lang) => Cow::Owned(lang.to_owned()),
None => Cow::Borrowed("text"),
Expand Down