How to add current date/time to clink/cmder prompt
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT
Music by Eric Matyas
https://www.soundimage.org
Track title: Realization
--
Chapters
00:00 How To Add Current Date/Time To Clink/Cmder Prompt
00:19 Accepted Answer Score 10
00:46 Answer 2 Score 12
01:30 Answer 3 Score 0
01:52 Answer 4 Score 0
02:33 Thank you
--
Full question
https://superuser.com/questions/702563/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#windows #commandline #clink #cmder
#avk47
ANSWER 1
Score 12
The answer provided by Maximus is no longer valid for cmder 1.3+
You have to create a .lua
file (for ex. my_prompt.lua
) inside your cmder config
folder with your customized definition (source).
Below my customization:
function custom_prompt()
cwd = clink.get_cwd()
prompt = "\x1b[1;32;40m{cwd} {git}{hg} \n\x1b[1;30;40m{time}\n{lamb} \x1b[0m"
new_value = string.gsub(prompt, "{cwd}", cwd)
add_time = string.gsub(new_value, "{time}", os.date("%x - %X"))
clink.prompt.value = string.gsub(add_time, "{lamb}", "λ")
end
clink.prompt.register_filter(custom_prompt, 1)
And this is the resulting prompt
C:\
03/25/17 - 20:56:14
λ
You can find more customization options for the time output in the Lua manual
update for comment reported error
function time_prompt()
os.setlocale ("", "time")
local cwd = clink.get_cwd()
local prompt = "\x1b[1;32m{cwd} {git}{hg} \n\x1b[30m{time}\n{lamb} \x1b[0m"
local new_value = string.gsub(prompt, "{cwd}", cwd)
local add_time = string.gsub(new_value, "{time}", os.date("%x - %X"))
clink.prompt.value = string.gsub(add_time, "{lamb}", "λ")
end
ACCEPTED ANSWER
Score 10
Try this prompt settings (example only, it's show how you can call any console application inside "prompt printing"). Note! It works in ConEmu only.
prompt $p$s$e]9;7;"cmd /c echo (%DATE% %TIME%)"$e\$g
But, as Bob said, there is an easier way:
prompt $p$s$d$s$t$s$g
And for cmder
you should edit the supplied init.bat
as that defines the prompt settings.
ANSWER 3
Score 0
One line modification for cmder. Put it to cmder\config\my_config.lua
function my_prompt_filter()
cwd = clink.get_cwd()
prompt = "\x1b[1;32;40m{cwd}{git}{hg} $> \x1b[33;40m"
new_value = string.gsub(prompt, "{cwd}", cwd)
clink.prompt.value = string.gsub(new_value, "{lamb}", "λ")
end
clink.prompt.register_filter(my_prompt_filter, 1)
result:
C:\Users\user1 $>
C:\Users\user1 $> date
The current date is: 02.02.2018
C:\Users\user1 $>
ANSWER 4
Score 0
None of the solutions here worked for me, so I ended up with adding the following line in my .bashrc
:
alias myprompt='export PS1="\[\e]9;9;"\w"\007\e]9;12\007\]\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]\[\033[32m\]\u@\h \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\] \D{%T}\nλ "'
That last part \D{%T}
is what shows the current time (don't care about the date, as usually I need to know how much time has ellapsed since I started a task).
Of course, this doesn't automatically change the prompt on all git bash terminals. You have to execute the myprompt
command on the default prompt to change it.
I tried to just do the above export inside the .bashrc
file but I was getting an error. Maybe someone will have a better idea on how to get around that.