summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Wendorf <github@danwendorf.com>2019-12-06 11:19:11 -0800
committerMatan Kushner <hello@matchai.me>2019-12-06 14:19:11 -0500
commitdee25c7b35284a23cfc189fbfcf26f6db7f51af0 (patch)
treeb65126cb760a42200b06ac672846aa9bfa08dac1
parent9f574eaabdf4bf0d021f3bf7bb89231420b73bf7 (diff)
feat: Add prefix config to directory module (#642)
-rw-r--r--docs/config/README.md1
-rw-r--r--docs/de-DE/config/README.md1
-rw-r--r--docs/fr-FR/config/README.md1
-rw-r--r--docs/ja-JP/config/README.md1
-rw-r--r--docs/ru-RU/config/README.md1
-rw-r--r--docs/zh-CN/config/README.md1
-rw-r--r--docs/zh-TW/config/README.md1
-rw-r--r--src/configs/directory.rs6
-rw-r--r--src/modules/directory.rs2
-rw-r--r--tests/testsuite/directory.rs16
10 files changed, 28 insertions, 3 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index 4ceff8719..75780d92c 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 35e166282..42d201340 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 6642ae8e5..3e3ba66c3 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 299d2267b..1447dc201 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 919c1d5ee..ecabec497 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 6b8c6d853..5f300c607 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 f6c4405d4..7a7eef8bb 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 40574fd1d..3d44b14dd 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 e6f3c5974..a221515e2 100644
--- a/src/modules/directory.rs
+++ b/src/modules/directory.rs
@@ -89,7 +89,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
},
);
- 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 006764ae8..2ead974e5 100644
--- a/tests/testsuite/directory.rs
+++ b/tests/testsuite/directory.rs
@@ -96,6 +96,22 @@ fn root_directory() -> io::Result<()> {
}
#[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<()> {
let output = common::render_module("directory")