chrisant996 / clink-flex-prompt

Flex prompt for Clink
MIT License
135 stars 17 forks source link

Feature request: Add java version in flexprompt #38

Closed Riduidel closed 1 year ago

Riduidel commented 1 year ago

Java version can be obtained by running java -version Which return a line such as

java version "17.0.2" 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)

For an example implementation, starship shell java module uses a Rust regular expression for that: (?:JRE.*\\(|OpenJ9 )(?P<version>[\\d]+(?:\\.\\d+){0,2})

Riduidel commented 1 year ago

Being a noob un LUA, I tried an implementation

-- This is the prompt module function.
local function java_module(args)
    local version_output = io.popen("java -version 2>&1")
    for line in version_output:lines() do
        local version = line:match('^java version "(.*)" .*$')
        if version then
            return " " .. version, "blue"
        end
    end
    version_output:close()

    return "", "magenta"
end

flexprompt.add_module("java", java_module)

Unfortunatly, it only works when java is defined in system PATH, but not in USER path. Any idea why?

chrisant996 commented 1 year ago

Unfortunatly, it only works when java is defined in system PATH, but not in USER path. Any idea why?

@Riduidel What is meant by "USER path"? Do you mean when Java is installed in %USERPROFILE%, and the Java directory is not on the system PATH? How do you normally use Java when the Java directory isn't on the system PATH?

chrisant996 commented 1 year ago

@Riduidel I realized that "SYSTEM path" and "USER path" probably refer to the "System variable" and "User variables" sections in the "Environment Variables" dialog box in the System Properties page of Windows Settings.

If that's the case, then something is running as an Administrator -- an Elevated process or system process. That would be an external issue, due to the configuration being used on the computer. I couldn't guess at specifics, because I know nothing about the computer or its configuration.