diff --git a/docs/config/README.md b/docs/config/README.md index 4ceff871..75780d92 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -327,6 +327,7 @@ it would have been `nixpkgs/pkgs`. | ------------------- | ------------- | -------------------------------------------------------------------------------- | | `truncation_length` | `3` | The number of parent folders that the current directory should be truncated to. | | `truncate_to_repo` | `true` | Whether or not to truncate to the root of the git repo that you're currently in. | +| `prefix` | `"in "` | Prefix to display immediately before the directory. | | `style` | `"bold cyan"` | The style for the module. | | `disabled` | `false` | Disables the `directory` module. | diff --git a/docs/de-DE/config/README.md b/docs/de-DE/config/README.md index 35e16628..42d20134 100644 --- a/docs/de-DE/config/README.md +++ b/docs/de-DE/config/README.md @@ -303,6 +303,7 @@ For example, given `~/Dev/Nix/nixpkgs/pkgs` where `nixpkgs` is the repo root, an | ------------------- | ------------- | -------------------------------------------------------------------------------- | | `truncation_length` | `3` | Die Anzahl der übergeordneten Ordner, die angezeigt werden. | | `truncate_to_repo` | `true` | Whether or not to truncate to the root of the git repo that you're currently in. | +| `prefix` | `"in "` | Prefix to display immediately before the directory. | | `style` | `"bold cyan"` | Stil für dieses Modul. | | `disabled` | `false` | Deaktiviert das `directory`-Modul. | diff --git a/docs/fr-FR/config/README.md b/docs/fr-FR/config/README.md index 6642ae8e..3e3ba66c 100644 --- a/docs/fr-FR/config/README.md +++ b/docs/fr-FR/config/README.md @@ -303,6 +303,7 @@ For example, given `~/Dev/Nix/nixpkgs/pkgs` where `nixpkgs` is the repo root, an | ------------------- | ------------- | -------------------------------------------------------------------------------- | | `truncation_length` | `3` | The number of parent folders that the current directory should be truncated to. | | `truncate_to_repo` | `true` | Whether or not to truncate to the root of the git repo that you're currently in. | +| `prefix` | `"in "` | Prefix to display immediately before the directory. | | `style` | `"bold cyan"` | The style for the module. | | `disabled` | `false` | Disables the `directory` module. | diff --git a/docs/ja-JP/config/README.md b/docs/ja-JP/config/README.md index 299d2267..1447dc20 100644 --- a/docs/ja-JP/config/README.md +++ b/docs/ja-JP/config/README.md @@ -304,6 +304,7 @@ fishスタイルのpwdオプションを使用すると、切り捨てられた | ------------------- | ------------- | ----------------------------- | | `truncation_length` | `3` | 現在のディレクトリを切り捨てる親フォルダーの数です。 | | `truncate_to_repo` | `true` | 現在いるgitリポジトリのルートに切り捨てるかどうかです。 | +| `prefix` | `"in "` | Prefix to display immediately before the directory. | | `style` | `"bold cyan"` | モジュールのスタイルです。 | | `disabled` | `false` | `directory`モジュールを無効にします。 | diff --git a/docs/ru-RU/config/README.md b/docs/ru-RU/config/README.md index 919c1d5e..ecabec49 100644 --- a/docs/ru-RU/config/README.md +++ b/docs/ru-RU/config/README.md @@ -303,6 +303,7 @@ style = "dimmed green" | ------------------- | ------------- | ---------------------------------------------------------------------------- | | `truncation_length` | `3` | Количество родительских папок, к которым должен быть усечен текущий каталог. | | `truncate_to_repo` | `true` | Следует или нет обрезать до корня репозитория git, в котором вы находитесь. | +| `prefix` | `"in "` | Prefix to display immediately before the directory. | | `style` | `"bold cyan"` | Стиль модуля. | | `disabled` | `false` | Отключает модуль `directory`. | diff --git a/docs/zh-CN/config/README.md b/docs/zh-CN/config/README.md index 6b8c6d85..5f300c60 100644 --- a/docs/zh-CN/config/README.md +++ b/docs/zh-CN/config/README.md @@ -303,6 +303,7 @@ For example, given `~/Dev/Nix/nixpkgs/pkgs` where `nixpkgs` is the repo root, an | ------------------- | ------------- | -------------------------------------------------------------------------------- | | `truncation_length` | `3` | The number of parent folders that the current directory should be truncated to. | | `truncate_to_repo` | `true` | Whether or not to truncate to the root of the git repo that you're currently in. | +| `prefix` | `"in "` | Prefix to display immediately before the directory. | | `style` | `"bold cyan"` | The style for the module. | | `disabled` | `false` | Disables the `directory` module. | diff --git a/docs/zh-TW/config/README.md b/docs/zh-TW/config/README.md index f6c4405d..7a7eef8b 100644 --- a/docs/zh-TW/config/README.md +++ b/docs/zh-TW/config/README.md @@ -303,6 +303,7 @@ style = "dimmed green" | ------------------- | ------------- | ------------------------- | | `truncation_length` | `3` | 到達現在資料夾的路徑中,要被裁減掉的資料夾數目。 | | `truncate_to_repo` | `true` | 是否要裁減到你現在所在的 git 儲存庫的根目錄。 | +| `prefix` | `"in "` | Prefix to display immediately before the directory. | | `style` | `"bold cyan"` | 這個模組的風格。 | | `disabled` | `false` | 停用 `directory` 模組。 | diff --git a/src/configs/directory.rs b/src/configs/directory.rs index 40574fd1..3d44b14d 100644 --- a/src/configs/directory.rs +++ b/src/configs/directory.rs @@ -4,22 +4,24 @@ use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; #[derive(Clone, ModuleConfig)] -pub struct DirectoryConfig { +pub struct DirectoryConfig<'a> { pub truncation_length: i64, pub truncate_to_repo: bool, pub fish_style_pwd_dir_length: i64, pub use_logical_path: bool, + pub prefix: &'a str, pub style: Style, pub disabled: bool, } -impl<'a> RootModuleConfig<'a> for DirectoryConfig { +impl<'a> RootModuleConfig<'a> for DirectoryConfig<'a> { fn new() -> Self { DirectoryConfig { truncation_length: 3, truncate_to_repo: true, fish_style_pwd_dir_length: 0, use_logical_path: true, + prefix: "in ", style: Color::Cyan.bold(), disabled: false, } diff --git a/src/modules/directory.rs b/src/modules/directory.rs index e6f3c597..a221515e 100644 --- a/src/modules/directory.rs +++ b/src/modules/directory.rs @@ -89,7 +89,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { }, ); - module.get_prefix().set_value("in "); + module.get_prefix().set_value(config.prefix); Some(module) } diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index 006764ae..2ead974e 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -95,6 +95,22 @@ fn root_directory() -> io::Result<()> { Ok(()) } +#[test] +fn test_prefix() -> io::Result<()> { + let output = common::render_module("directory") + .arg("--path=/") + .use_config(toml::toml! { + [directory] + prefix = "sample " + }) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + + let expected = format!("sample {} ", Color::Cyan.bold().paint("/")); + assert_eq!(expected, actual); + Ok(()) +} + #[test] #[cfg(not(target_os = "windows"))] fn directory_in_root() -> io::Result<()> {