Skip to content

Commit 583dba4

Browse files
authored
Highlight symlinks in file and dir prompt completions (#15108)
1 parent 3d32967 commit 583dba4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

book/src/themes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ These scopes are used for theming the editor interface:
330330
| `ui.text.inactive` | Same as `ui.text` but when the text is inactive (e.g. suggestions) |
331331
| `ui.text.info` | The key: command text in `ui.popup.info` boxes |
332332
| `ui.text.directory` | Directory names in prompt completion |
333+
| `ui.text.symlink` | Symlink names in prompt completion |
333334
| `ui.virtual.ruler` | Ruler columns (see the [`editor.rulers` config][editor-section]) |
334335
| `ui.virtual.whitespace` | Visible whitespace characters |
335336
| `ui.virtual.indent-guide` | Vertical indent width guides |

helix-term/src/ui/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use std::{error::Error, path::PathBuf};
4040
struct Utf8PathBuf {
4141
path: String,
4242
is_dir: bool,
43+
is_symlink: bool,
4344
}
4445

4546
impl AsRef<str> for Utf8PathBuf {
@@ -658,6 +659,8 @@ pub mod completers {
658659

659660
let path = entry.path();
660661
let is_dir = path.is_dir();
662+
let file_type = entry.file_type();
663+
let is_symlink = file_type.is_some_and(|ft| ft.is_symlink());
661664
let mut path = if is_tilde {
662665
// if it's a single tilde an absolute path is displayed so that when `TAB` is pressed on
663666
// one of the directories the tilde will be replaced with a valid path not with a relative
@@ -674,15 +677,22 @@ pub mod completers {
674677
}
675678

676679
let path = path.into_os_string().into_string().ok()?;
677-
Some(Utf8PathBuf { path, is_dir })
680+
Some(Utf8PathBuf {
681+
path,
682+
is_dir,
683+
is_symlink,
684+
})
678685
})
679686
}) // TODO: unwrap or skip
680687
.filter(|path| !path.path.is_empty());
681688

682689
let directory_color = editor.theme.get("ui.text.directory");
690+
let symlink_color = editor.theme.get("ui.text.symlink");
683691

684692
let style_from_file = |file: Utf8PathBuf| {
685-
if file.is_dir {
693+
if file.is_symlink {
694+
Span::styled(file.path, symlink_color)
695+
} else if file.is_dir {
686696
Span::styled(file.path, directory_color)
687697
} else {
688698
Span::raw(file.path)

0 commit comments

Comments
 (0)