Repository: cantino/mcfly (language: rust)

Issue:
Customize Prompt?
Is it possible to change the `$` prompt to something custom, perhaps through and environment variable? I'd like to have it match my shell prompt. Sorry if this has been asked before, all I could find was something about `PROMPT_COMMAND` but that did not seem to be relevant.


Discussion / hints:
Not currently, but I'd accept a PR for this change.

On Tue, Jan 24, 2023 at 8:36 PM Ved Kothavade ***@***.***>
wrote:

> Is it possible to change the $ prompt to something custom, perhaps
> through and environment variable? I'd like to have it match my shell
> prompt. Sorry if this has been asked before, all I could find was something
> about PROMPT_COMMAND but that did not seem to be relevant.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/cantino/mcfly/issues/324>, or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAAUO62DUXCZOTBEABH3M2DWUCUUPANCNFSM6AAAAAAUF35MAM>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>

Sounds good, I'll take a stab at it soon.

Fix patch:
diff --git a/README.md b/README.md
index 37a5687c..8d34f2d9 100644
--- a/README.md
+++ b/README.md
@@ -194,8 +194,8 @@ When suggesting a command, McFly takes into consideration:
 * Add below code to your zshrc.
 
     ```zsh
-    zinit ice lucid wait"0a" from"gh-r" as"program" atload'eval "$(mcfly init zsh)"' 
-    zinit light cantino/mcfly 
+    zinit ice lucid wait"0a" from"gh-r" as"program" atload'eval "$(mcfly init zsh)"'
+    zinit light cantino/mcfly
     ```
 * It will download mcfly and install for you.
 * `$(mcfly init zsh)` will be executed after prompt
@@ -312,6 +312,19 @@ fish:
 set -gx MCFLY_RESULTS_SORT LAST_RUN
 ```
 
+### Custom Prompt
+To change the prompt, set `MCFLY_PROMPT` (default: `$`).
+
+bash / zsh:
+```bash
+export MCFLY_PROMPT="❯"
+```
+
+fish:
+```bash
+set -gx MCFLY_PROMPT "❯"
+```
+
 ### Database Location
 
 McFly stores its SQLite database in the standard location for the OS. On OS X, this is in `~/Library/Application Support/McFly` and on Linux it is in `$XDG_DATA_DIR/mcfly/history.db` (default would be `~/.local/share/mcfly/history.db`). For legacy support, if `~/.mcfly/` exists, it is used instead.
diff --git a/src/interface.rs b/src/interface.rs
index ca7f1a2c..2e7dad37 100644
--- a/src/interface.rs
+++ b/src/interface.rs
@@ -175,7 +175,7 @@ impl<'a> Interface<'a> {
         let prompt_line_index = self.prompt_line_index();
         write!(
             screen,
-            "{}{}{}$ {}",
+            "{}{}{}{} {}",
             if self.settings.lightmode {
                 color::Fg(color::Black).to_string()
             } else {
@@ -183,6 +183,7 @@ impl<'a> Interface<'a> {
             },
             cursor::Goto(1, self.prompt_line_index()),
             clear::CurrentLine,
+            self.settings.prompt,
             self.input
         )
         .unwrap();
diff --git a/src/settings.rs b/src/settings.rs
index 7ffb3e32..2dd13c2f 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -86,6 +86,7 @@ pub struct Settings {
     pub interface_view: InterfaceView,
     pub result_sort: ResultSort,
     pub disable_menu: bool,
+    pub prompt: String,
     pub disable_run_command: bool,
 }
 
@@ -116,6 +117,7 @@ impl Default for Settings {
             interface_view: InterfaceView::Top,
             result_sort: ResultSort::Rank,
             disable_menu: false,
+            prompt: String::from("$"),
             disable_run_command: false,
         }
     }
@@ -344,6 +346,12 @@ impl Settings {
             _ => KeyScheme::Emacs,
         };
 
+        if let Ok(prompt) = env::var("MCFLY_PROMPT") {
+            if prompt.chars().count() == 1 {
+                settings.prompt = prompt;
+            }
+        }
+
         settings
     }
 


Test patch: