I want to print current username using Crystal-lang, does anyone know how to help me?
I want to print current username using Crystal-lang, does anyone know how to help me?
Yes this is still somewhat missing in the standard library. There's an ongoing discussion about it here: https://github.com/crystal-lang/crystal/issues/7829
Meanwhile we can quickly bind getuid(2) or geteuid(2) ourselves and combine it with System::User:
require "system/user"
lib LibC
fun getuid : UidT
end
user = System::User.find_by id: LibC.getuid.to_s
pp user.username