<commit_before>-- default script for clink, called by init.bat when injecting clink

-- !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED
-- !!! Use "%CMDER_ROOT%\config\<whatever>.lua" to add your lua startup scripts

-- luacheck: globals clink

-- At first, load the original clink.lua file
-- this is needed as we set the script path to this dir and therefore the original
-- clink.lua is not loaded.
local clink_lua_file = clink.get_env('CMDER_ROOT')..'\\vendor\\clink\\clink.lua'
dofile(clink_lua_file)

-- now add our own things...


local function get_uah_color()
  return uah_color or "\x1b[1;33;40m" -- Green = uah = [user]@[hostname]
end

local function get_cwd_color()
  return cwd_color or "\x1b[1;32;40m" -- Yellow cwd = Current Working Directory
end

local function get_lamb_color()
  return lamb_color or "\x1b[1;30;40m" -- Light Grey = Lambda Color
end


local function get_clean_color()
  return clean_color or "\x1b[1;37;40m"
end


local function get_dirty_color()
  return dirty_color or "\x1b[33;3m"
end


local function get_conflict_color()
  return conflict_color or "\x1b[31;1m"
end

---
-- Makes a string safe to use as the replacement in string.gsub
---
local function verbatim(s)
    s = string.gsub(s, "%%", "%%%%")
    return s
end

-- Extracts only the folder name from the input Path
-- Ex: Input C:\Windows\System32 returns System32
---
local function get_folder_name(path)
  local reversePath = string.reverse(path)
  local slashIndex = string.find(reversePath, "\\")
  return string.sub(path, string.len(path) - slashIndex + 2)
end


---
-- Setting the prompt in clink means that commands which rewrite the prompt do
-- not destroy our own prompt. It also means that started cmds (or batch files
-- which echo) don't get the ugly '{lamb}' shown.
---
local function set_prompt_filter()
    -- get_cwd() is differently encoded than the clink.prompt.value, so everything other than
    -- pure ASCII will get garbled. So try to parse the current directory from the original prompt
    -- and only if that doesn't work, use get_cwd() directly.
    -- The matching relies on the default prompt which ends in X:\PATH\PATH>
    -- (no network path possible here!)
    local old_prompt = clink.prompt.value
    local cwd = old_prompt:match('.*(.:[^>]*)>')
    if cwd == nil then cwd = clink.get_cwd() end

    -- environment systems like pythons virtualenv change the PROMPT and usually
    -- set some variable. But the variables are differently named and we would never
    -- get them all, so try to parse the env name out of the PROMPT.
    -- envs are usually put in round or square parentheses and before the old prompt
    local env = old_prompt:match('.*%(([^%)]+)%).+:')
    -- also check for square brackets
    if env == nil then env = old_prompt:match('.*%[([^%]]+)%].+:') end

    -- Much of the below was 'borrowed' from https://github.com/AmrEldib/cmder-powerline-prompt
    -- Symbol displayed for the home dir in the prompt.
    if not prompt_homeSymbol then
      prompt_homeSymbol = "~"
    end

    -- Symbol displayed in the new line below the prompt.
    if not prompt_lambSymbol then
      prompt_lambSymbol = "λ"
    end

    if not prompt_type then
      prompt_type = "full"
    end

    if prompt_useHomeSymbol == nil then
      prompt_useHomeSymbol = false
    end

    if prompt_useUserAtHost == nil then
      prompt_useUserAtHost = false
    end

    if prompt_singleLine == nil then
      prompt_singleLine = false
    end

    if prompt_type == 'folder' then
        cwd = get_folder_name(cwd)
    end

    if prompt_useHomeSymbol and string.find(cwd, clink.get_env("HOME")) then
        cwd = string.gsub(cwd, clink.get_env("HOME"), prompt_homeSymbol)
    end

    uah = ''
    if prompt_useUserAtHost then
        uah = clink.get_env("USERNAME") .. "@" .. clink.get_env("COMPUTERNAME") .. ' '
    end

    cr = "\n"
    if prompt_singleLine then
      cr = ' '
    end

    if env ~= nil then env = "("..env..") " else env = "" end

    prompt = get_uah_color() .. "{uah}" .. get_cwd_color() .. "{cwd}{git}{hg}{svn}" .. get_lamb_color() .. cr .. "{lamb} \x1b[0m"
    prompt = string.gsub(prompt, "{uah}", uah)
    prompt = string.gsub(prompt, "{cwd}", cwd)
    prompt = string.gsub(prompt, "{env}", env)
    clink.prompt.value = string.gsub(prompt, "{lamb}", prompt_lambSymbol)
end

local function percent_prompt_filter()
    clink.prompt.value = string.gsub(clink.prompt.value, "{percent}", "%%")<commit_msg>Fix no env in the prompt string<commit_after>-- default script for clink, called by init.bat when injecting clink

-- !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED
-- !!! Use "%CMDER_ROOT%\config\<whatever>.lua" to add your lua startup scripts

-- luacheck: globals clink

-- At first, load the original clink.lua file
-- this is needed as we set the script path to this dir and therefore the original
-- clink.lua is not loaded.
local clink_lua_file = clink.get_env('CMDER_ROOT')..'\\vendor\\clink\\clink.lua'
dofile(clink_lua_file)

-- now add our own things...


local function get_uah_color()
  return uah_color or "\x1b[1;33;40m" -- Green = uah = [user]@[hostname]
end

local function get_cwd_color()
  return cwd_color or "\x1b[1;32;40m" -- Yellow cwd = Current Working Directory
end

local function get_lamb_color()
  return lamb_color or "\x1b[1;30;40m" -- Light Grey = Lambda Color
end


local function get_clean_color()
  return clean_color or "\x1b[1;37;40m"
end


local function get_dirty_color()
  return dirty_color or "\x1b[33;3m"
end


local function get_conflict_color()
  return conflict_color or "\x1b[31;1m"
end

---
-- Makes a string safe to use as the replacement in string.gsub
---
local function verbatim(s)
    s = string.gsub(s, "%%", "%%%%")
    return s
end

-- Extracts only the folder name from the input Path
-- Ex: Input C:\Windows\System32 returns System32
---
local function get_folder_name(path)
  local reversePath = string.reverse(path)
  local slashIndex = string.find(reversePath, "\\")
  return string.sub(path, string.len(path) - slashIndex + 2)
end


---
-- Setting the prompt in clink means that commands which rewrite the prompt do
-- not destroy our own prompt. It also means that started cmds (or batch files
-- which echo) don't get the ugly '{lamb}' shown.
---
local function set_prompt_filter()
    -- get_cwd() is differently encoded than the clink.prompt.value, so everything other than
    -- pure ASCII will get garbled. So try to parse the current directory from the original prompt
    -- and only if that doesn't work, use get_cwd() directly.
    -- The matching relies on the default prompt which ends in X:\PATH\PATH>
    -- (no network path possible here!)
    local old_prompt = clink.prompt.value
    local cwd = old_prompt:match('.*(.:[^>]*)>')
    if cwd == nil then cwd = clink.get_cwd() end

    -- environment systems like pythons virtualenv change the PROMPT and usually
    -- set some variable. But the variables are differently named and we would never
    -- get them all, so try to parse the env name out of the PROMPT.
    -- envs are usually put in round or square parentheses and before the old prompt
    local env = old_prompt:match('.*%(([^%)]+)%).+:')
    -- also check for square brackets
    if env == nil then env = old_prompt:match('.*%[([^%]]+)%].+:') end

    -- Much of the below was 'borrowed' from https://github.com/AmrEldib/cmder-powerline-prompt
    -- Symbol displayed for the home dir in the prompt.
    if not prompt_homeSymbol then
      prompt_homeSymbol = "~"
    end

    -- Symbol displayed in the new line below the prompt.
    if not prompt_lambSymbol then
      prompt_lambSymbol = "λ"
    end

    if not prompt_type then
      prompt_type = "full"
    end

    if prompt_useHomeSymbol == nil then
      prompt_useHomeSymbol = false
    end

    if prompt_useUserAtHost == nil then
      prompt_useUserAtHost = false
    end

    if prompt_singleLine == nil then
      prompt_singleLine = false
    end

    if prompt_type == 'folder' then
        cwd = get_folder_name(cwd)
    end

    if prompt_useHomeSymbol and string.find(cwd, clink.get_env("HOME")) then
        cwd = string.gsub(cwd, clink.get_env("HOME"), prompt_homeSymbol)
    end

    uah = ''
    if prompt_useUserAtHost then
        uah = clink.get_env("USERNAME") .. "@" .. clink.get_env("COMPUTERNAME") .. ' '
    end

    cr = "\n"
    if prompt_singleLine then
      cr = ' '
    end

    if env ~= nil then env = "("..env..") " else env = "" end

    prompt = get_uah_color() .. "{uah}" .. get_cwd_color() .. "{cwd}{git}{hg}{svn}" .. get_lamb_color() .. cr .. "{env}{lamb} \x1b[0m"
    prompt = string.gsub(prompt, "{uah}", uah)
    prompt = string.gsub(prompt, "{cwd}", cwd)
    prompt = string.gsub(prompt, "{env}", env)
    clink.prompt.value = string.gsub(prompt, "{lamb}", prompt_lambSymbol)
end

local function percent_prompt_filter()
    clink.prompt.value = string.gsub(clink.prompt.value, "{percent}", "%%")
{'fraction_non_alphanumeric': 0.12027223028004017, 'fraction_numerical': 0.008702443378333147, 'mean_word_length': 3.1519221861973135, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '460463', 'n_tokens_mistral': 3027, 'n_tokens_neox': 2860, 'n_words': 974}