diff --git a/README.md b/README.md index d9fe74e1b..b7a30a1b7 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,7 @@ shown below. Can't see yours? Have a look at the [extra platform instructions](h #### Cmd - You need to use [Clink](https://chrisant996.github.io/clink/clink.html) with Cmd. Add the following to a file `starship.lua` and place this file in Clink scripts directory: + You need to use [Clink](https://chrisant996.github.io/clink/clink.html) (v1.2.30+) with Cmd. Add the following to a file `starship.lua` and place this file in Clink scripts directory: ```lua -- starship.lua diff --git a/docs/README.md b/docs/README.md index f160202bb..ec5edce98 100644 --- a/docs/README.md +++ b/docs/README.md @@ -161,7 +161,7 @@ description: Starship is the minimal, blazing fast, and extremely customizable p #### Cmd - You need to use [Clink](https://chrisant996.github.io/clink/clink.html) with Cmd. Add the following to a file `starship.lua` and place this file in Clink scripts directory: + You need to use [Clink](https://chrisant996.github.io/clink/clink.html) (v1.2.30+) with Cmd. Add the following to a file `starship.lua` and place this file in Clink scripts directory: ```lua -- starship.lua diff --git a/install/install.sh b/install/install.sh index 5648ce70d..e358e6200 100755 --- a/install/install.sh +++ b/install/install.sh @@ -347,7 +347,7 @@ print_install() { Typically the path is ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 or ~/.config/powershell/Microsoft.PowerShell_profile.ps1 on -Nix." \ "Invoke-Expression (&starship init powershell)" - printf " %s\n You need to use Clink with Cmd. Add the following to a file %s and place this file in Clink scripts directory:\n\n\t%s\n\n" \ + printf " %s\n You need to use Clink (v1.2.30+) with Cmd. Add the following to a file %s and place this file in Clink scripts directory:\n\n\t%s\n\n" \ "${BOLD}${UNDERLINE}Cmd${NO_COLOR}" \ "${BOLD}starship.lua${NO_COLOR}" \ "load(io.popen('starship init cmd'):read(\"*a\"))()" diff --git a/src/init/starship.lua b/src/init/starship.lua index 601c433b8..f7dad72cd 100644 --- a/src/init/starship.lua +++ b/src/init/starship.lua @@ -1,4 +1,8 @@ -local custom_prompt = clink.promptfilter(5) +if (clink.version_encoded or 0) < 10020030 then + error("Starship requires a newer version of Clink; please upgrade to Clink v1.2.30 or later.") +end + +local starship_prompt = clink.promptfilter(5) start_time = os.clock() end_time = 0 @@ -24,7 +28,7 @@ clink.onendedit(function (curr_line) end end) -function custom_prompt:filter(prompt) +function starship_prompt:filter(prompt) if starship_preprompt_user_func ~= nil then starship_preprompt_user_func(prompt) end @@ -36,7 +40,7 @@ function custom_prompt:filter(prompt) ):read("*a") end -function custom_prompt:rightfilter(prompt) +function starship_prompt:rightfilter(prompt) return io.popen("::STARSHIP:: prompt --right" .." --status="..os.geterrorlevel() .." --cmd-duration="..math.floor(curr_duration*1000) @@ -45,13 +49,12 @@ function custom_prompt:rightfilter(prompt) ):read("*a") end -local characterSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +local characterset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" local randomkey = "" math.randomseed(os.time()) - for i = 1, 16 do - local rand = math.random(#characterSet) - randomkey = randomkey..string.sub(characterSet, rand, rand) + local rand = math.random(#characterset) + randomkey = randomkey..string.sub(characterset, rand, rand) end os.setenv('STARSHIP_SHELL', 'cmd')