Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for CMD #21

Closed
rashil2000 opened this issue Sep 23, 2020 · 19 comments
Closed

Support for CMD #21

rashil2000 opened this issue Sep 23, 2020 · 19 comments
Assignees
Labels
🤩 enhancement Improvement of a feature

Comments

@rashil2000
Copy link

rashil2000 commented Sep 23, 2020

Since this is a (almost) platform-agnostic shell themer, is there a way to support Command Prompt in Windows?

For inspiration, you can check out how Cmder does it.
For the most part, it just requires changing the prompt environment variable. Like this, for example:

SETX /M PROMPT "$E[1;32;40m→ $E[1;36;40m$p$E[1;35;40m› $E[1;37;40m" 
@JanDeDobbeleer
Copy link
Owner

In theory you should be able to call the executable just like you would on Powershell. Let me check and add that info to the README

@JanDeDobbeleer JanDeDobbeleer added the 🤩 enhancement Improvement of a feature label Sep 23, 2020
@JanDeDobbeleer JanDeDobbeleer self-assigned this Sep 23, 2020
Repository owner locked and limited conversation to collaborators Sep 23, 2020
Repository owner unlocked this conversation Sep 23, 2020
@JanDeDobbeleer
Copy link
Owner

Never mind the previous activity, that was me fighting the Github Android app 😅

@rashil2000
Copy link
Author

In theory you should be able to call the executable just like you would on Powershell.

That'd be really slick!

@JanDeDobbeleer
Copy link
Owner

You'd think this should be possible, right? Well, turns out my friend CMD only works with strings... I'm looking for a way to bypass that, it can print the prompt though :-)

@rashil2000
Copy link
Author

Yes I tried fighting with it too. Calling the .exe momentarily printed the prompt, but the PROMPT variable takes only strings and some escape characters, because specifying the path of go-my-posh in PROMPT just printed out the path :)

@JanDeDobbeleer
Copy link
Owner

It's more limited to my friend CMD than anything else, but maybe there's an out-of-the-box solution nobody's thinking off.

@JanDeDobbeleer
Copy link
Owner

Doesn't seem to be possible yet with everything I've tried, I'll keep this open in case I (or someone else) has a brilliant idea that might work.

@rashil2000
Copy link
Author

Sure!
Thanks for your effort!

@JanDeDobbeleer
Copy link
Owner

Had a look once again and it's just not possible as far as I can tell.

@rashil2000
Copy link
Author

@JanDeDobbeleer Yes, it seemed really difficult.

Any idea how Cmder achieved a custom prompt though? Was it terminal-specific?

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Oct 14, 2020

You can change it once, but not change it on the fly and as elaborate as oh-my-posh does.

I will have a look though. If what conemu does works on every prompt invocation, it might work.

@JanDeDobbeleer
Copy link
Owner

image

I reached this point but as I feared, you can't update the path and other information once you set the string meaning you would need to return the standard variables CMD understands for them to be dynamic. Conemu can do a bit more magic as they own the shell, meaning they have some magic variables they can inject at runtime, but that's not something I can offer. Therefore we can't support CMD 😢

@rashil2000
Copy link
Author

I understand.

Thank you for your efforts though! OMP3 looks really in all other shells btw!

@rashil2000
Copy link
Author

rashil2000 commented Dec 25, 2020

Hey @JanDeDobbeleer, sorry for bumping this old thread again, but I think I finally figured it out!

It might be out of scope of this project, but Conemu actually uses Clink under the hood, which offers it the ability to have a custom prompt with the help of Lua scripting - Customizing the Prompt - as mentioned here. With a simple function like this:

local custom_prompt = clink.promptfilter(50)
function custom_prompt:filter(prompt)
    return io.popen("oh-my-posh --config C:\\Users\\RashilGandhi\\.oh-my-posh\\honukai.omp.json"):read("*a")
end

I was able to have a dynamic and fully working prompt

image

I say this is out of scope because, well anyone looking for using OMP with CMD will have to install Clink then.

Anyways, just wanted to share!

@AbdelrahmanHafez
Copy link

Thanks @rashil2000

I'd like to extend your answer a little bit more, in case anyone comes across this issue who is also using ConEmu, most of the tutorials out there only specify how it would work for PowerShell, and I am not a fan. I prefer Cmder.

In order to get oh-my-posh working:
1- Locate cmder installation folder.
2- Create a new file vendor\clink-completions\custom.lua
Paste the following as the content:

local custom_prompt = clink.promptfilter(50)
function custom_prompt:filter(prompt)
    return io.popen("oh-my-posh"):read("*a")
end

@JanDeDobbeleer
Thank you for the great work, would consider repoening this since Cmder is quite popular on the Windows scene?

@JanDeDobbeleer
Copy link
Owner

@AbdelrahmanHafez it's documentation so I don't mind having this info in the docs tbh.

@rashil2000
Copy link
Author

Clink's (the extension framework that Cmder uses) own documentation also has a section for oh-my-posh, maybe that can be referred - https://chrisant996.github.io/clink/clink.html#oh-my-posh

@yaseer-13
Copy link

👍 This command worked for me to make changes in the command prompt!

load(io.popen('oh-my-posh.exe --config="C:/Users/YourName/AppData/Local/Programs/oh-my-posh/themes/themeName.omp.json" --init --shell cmd'):read("*a"))()

Copy link

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues.
If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🤩 enhancement Improvement of a feature
Projects
None yet
Development

No branches or pull requests

4 participants