JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.38k stars 2.39k forks source link

OMP on Clink does not seem to work #1642

Closed SarreqTeryx closed 2 years ago

SarreqTeryx commented 2 years ago

Code of Conduct

What happened?

I get the same issue whether it's under conhost or Windows Terminal: When trying to set up Oh My Posh in Clink won't work. I used the lua script from the installation page: load(io.popen('oh-my-posh --config="c:/users/seanm/powerlevel10k_rainbow.omp.json" --init --shell cmd'):read("*a")) I also tried the full path to the themes folder, with no luck.

Running the embedded OMP command from Clink gives this (error message?):

-- Duration functions

local endedit_time
local last_duration
local tip_word

local function omp_exe()
    return [[C:/Users/seanm/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe]]
end

local function omp_config()
    return [[c:\users\seanm\powerlevel10k_rainbow.omp.json]]
end

local function os_clock_millis()
    -- Clink v1.2.30 has a fix for Lua's os.clock() implementation failing after
    -- the program has been running more than 24 days.  In older versions, call
    -- OMP to get the time in milliseconds.
    if (clink.version_encoded or 0) >= 10020030 then
        return math.floor(os.clock() * 1000)
    else
        return io.popen(omp_exe().." --millis"):read("*n")
    end
end

local function duration_onbeginedit()
    last_duration = 0
    if endedit_time then
        local beginedit_time = os_clock_millis()
        local elapsed = beginedit_time - endedit_time
        if elapsed >= 0 then
            last_duration = elapsed
        end
    end
end

local function duration_onendedit()
    endedit_time = os_clock_millis()
end

-- Prompt functions

local function execution_time_option()
    if last_duration ~= nil then
        return "--execution-time "..last_duration
    end
    return ""
end

local function error_level_option()
    if os.geterrorlevel ~= nil and settings.get("cmd.get_errorlevel") then
        return "--error "..os.geterrorlevel()
    end
    return ""
end

local function get_posh_prompt(rprompt)
    local prompt_exe = string.format('%s --shell=cmd --config="%s" %s %s --rprompt=%s', omp_exe(), omp_config(), execution_time_option(), error_level_option(), rprompt)
    prompt = io.popen(prompt_exe):read("*a")
    return prompt
end

local p = clink.promptfilter(1)
function p:filter(prompt)
    return get_posh_prompt(false)
end
function p:rightfilter(prompt)
    if tip_word == nil then
        return get_posh_prompt(true), false
    end
    local prompt_exe = string.format('%s --shell=cmd --config="%s" --command="%s"', omp_exe(), omp_config(), tip_word)
    tooltip = io.popen(prompt_exe):read("*a")
    if tooltip ~= "" then
        return tooltip, false
    end
    return get_posh_prompt(true), false
end
function p:transientfilter(prompt)
    local prompt_exe = string.format('%s --shell=cmd --config="%s" --print-transient', omp_exe(), omp_config())
    prompt = io.popen(prompt_exe):read("*a")
    if prompt == "" then
        prompt = nil
    end
    return prompt
end
function p:transientrightfilter(prompt)
    return "", false
end

-- Event handlers

local function builtin_modules_onbeginedit()
    _cached_state = {}
    duration_onbeginedit()
end

local function builtin_modules_onendedit()
    duration_onendedit()
end

if clink.onbeginedit ~= nil and clink.onendedit ~= nil then
    clink.onbeginedit(builtin_modules_onbeginedit)
    clink.onendedit(builtin_modules_onendedit)
end

-- Tooltips

function ohmyposh_space(rl_buffer)
    rl_buffer:insert(" ")
    local words = string.explode(rl_buffer:getbuffer(), ' ', [["]])
    if words[1] ~= tip_word then
        tip_word = words[1] -- remember the first word for use when filtering the prompt
        clink.refilterprompt() -- invoke the prompt filters so omp can update the prompt per the tip word
    end
end

if rl.setbinding then
    clink.onbeginedit(function () tip_word = nil end)
    rl.setbinding(' ', [["luafunc:ohmyposh_space"]], 'emacs')
end

Theme

powerline10k_rainbow

but any I've tried

What OS are you seeing the problem on?

Windows

Which shell are you using?

other (please specify)

Log output

C:\Users\seanm>oh-my-posh --debug --shell uni --config="$POSH_THEME"
Oh My Posh Error:
 CreateFile C:\Users\seanm\$POSH_THEME: The system cannot find the file specified.

Version: 7.5.1

Segments:

ConsoleTitle(true) -   0 ms -
session(true)  -   0 ms -  seanm@TrashBin 
path(true)     -   1 ms -   ~ 
git(false)     -   8 ms -
battery(true)  -  21 ms -  55 
node(false)    -   0 ms -
shell(true)    -   0 ms -  ﲵ uni 
root(false)    -   0 ms -
text(true)     -   0 ms -  INVALID CONFIG PATH 
exit(true)     -   0 ms -   

Run duration: 33.7898ms

Cache path: C:\Users\seanm\AppData\Local/oh-my-posh

Logs:

2022/01/24 20:41:02 getArgs duration: 0s, args:
2022/01/24 20:41:02 getArgs duration: 0s, args:
2022/01/24 20:41:02 getShellName duration: 0s, args:
2022/01/24 20:41:02 debug: getenv

2022/01/24 20:41:02 getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/01/24 20:41:02 isRunningAsRoot duration: 0s, args:
2022/01/24 20:41:02 getShellName duration: 0s, args:
2022/01/24 20:41:02 lastErrorCode duration: 0s, args:
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 getPathSeperator duration: 0s, args:
2022/01/24 20:41:02 getPathSeperator duration: 0s, args:
2022/01/24 20:41:02 getCurrentUser duration: 0s, args:
2022/01/24 20:41:02 getHostName duration: 0s, args:
2022/01/24 20:41:02 getRuntimeGOOS duration: 0s, args:
2022/01/24 20:41:02 templateCache duration: 0s, args:
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 debug: getenv

2022/01/24 20:41:02 getenv duration: 0s, args: SSH_CONNECTION
2022/01/24 20:41:02 debug: getenv

2022/01/24 20:41:02 getenv duration: 0s, args: SSH_CLIENT
2022/01/24 20:41:02 getCurrentUser duration: 0s, args:
2022/01/24 20:41:02 getRuntimeGOOS duration: 0s, args:
2022/01/24 20:41:02 getHostName duration: 0s, args:
2022/01/24 20:41:02 debug: getenv

2022/01/24 20:41:02 getenv duration: 0s, args: POSH_SESSION_DEFAULT_USER
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 getArgs duration: 0s, args:
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 getRuntimeGOOS duration: 0s, args:
2022/01/24 20:41:02 getRuntimeGOOS duration: 0s, args:
2022/01/24 20:41:02 getPathSeperator duration: 0s, args:
2022/01/24 20:41:02 getPathSeperator duration: 0s, args:
2022/01/24 20:41:02 getPathSeperator duration: 0s, args:
2022/01/24 20:41:02 getRuntimeGOOS duration: 0s, args:
2022/01/24 20:41:02 stackCount duration: 0s, args:
2022/01/24 20:41:02 templateCache duration: 0s, args:
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 getRuntimeGOOS duration: 0s, args:
2022/01/24 20:41:02 error: hasCommand
exec: "git.exe": executable file not found in %PATH%
2022/01/24 20:41:02 hasCommand duration: 8.9897ms, args: git.exe
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 getBatteryInfo duration: 21.9983ms, args:
2022/01/24 20:41:02 templateCache duration: 0s, args:
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 getShellName duration: 0s, args:
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 isRunningAsRoot duration: 0s, args:
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 templateCache duration: 0s, args:
2022/01/24 20:41:02 debug: pwd
C:\Users\seanm
2022/01/24 20:41:02 pwd duration: 0s, args:
2022/01/24 20:41:02 debug: homeDir
C:\Users\seanm
2022/01/24 20:41:02 lastErrorCode duration: 0s, args:
2022/01/24 20:41:02 debug: getenv
C:\Users\seanm\AppData\Local
2022/01/24 20:41:02 getenv duration: 557.8µs, args: LOCALAPPDATA
2022/01/24 20:41:02 getCachePath duration: 686.3µs, args:
JanDeDobbeleer commented 2 years ago

@SarreqTeryx are you using the latest version of clink? Because this should work. The reason the debug command doesn't work is that $POSH_THEME isn't set (and that's not how environment variables work in CMD). You can reference your theme directly, but the debug won't show the issue with clink.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

mattcargile commented 2 years ago

I'm assume there can be some confusion on which Clink to install. There is the mridgers version and the chrisant version. I assume the chrisant version is the one you want as it appears the original creator stopped development and then Chrisant996 picked it back up.

JanDeDobbeleer commented 2 years ago

@mattcargile the docs clearly point to Chris though.

mattcargile commented 2 years ago

I see that now. Oops! I became confused when I was googling around for Clink in general. I'm about to attempt to install it myself. Good thing I always read the docs first! :-)

JanDeDobbeleer commented 2 years ago

@SarreqTeryx can you validate if you installed the right clink?

SarreqTeryx commented 2 years ago

I think that may have been the problem. I googled for Clink the last time, because I didn't notice the link on the installation instructions.

JanDeDobbeleer commented 2 years ago

@SarreqTeryx if confirmed, can you close the issue? Thanks!

github-actions[bot] commented 8 months ago

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.