Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ~ for User's Home directory #2348

Closed
1 of 3 tasks
Lunchb0ne opened this issue Jul 12, 2020 · 5 comments
Closed
1 of 3 tasks

Use ~ for User's Home directory #2348

Lunchb0ne opened this issue Jul 12, 2020 · 5 comments

Comments

@Lunchb0ne
Copy link
Contributor

Purpose of the issue

  • Bug report (encountered problems/errors)
  • Feature request (request for new functionality)
  • Question

Version Information

Cmder : 1.3.15.1010
ConEmu : 19.10.12.0

Windows 10 Pro 2004

Description of the issue

It would be nice to have %USERPROFILE% directory in the prompt to be replaced by a ~ as it does on linux.
Owl-Cmder-Tools does it, but adds the powerline prompt to it.
It would be nice to have it in base cmder too.

@daxgames
Copy link
Member

daxgames commented Jul 12, 2020

Create this file %cmder_root%\config\prompt.lua:

-- Much of the below was 'borrowed' from https://github.com/AmrEldib/cmder-powerline-prompt

if not prompt_useHomeSymbol then 
  prompt_useHomeSymbol = true
end

-- 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

-- 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

function prompt_filter()
    cwd = clink.get_cwd()

    if prompt_useHomeSymbol and string.find(cwd, clink.get_env("HOME")) then 
        cwd = string.gsub(cwd, clink.get_env("HOME"), prompt_homeSymbol)
    end
    prompt = "\x1b[1;32;40m{cwd}{git}{hg}{svn}\x1b[1;30;40m {lamb} \x1b[0m"
    new_value = string.gsub(prompt, "{cwd}", cwd)
    clink.prompt.value = string.gsub(new_value, "{lamb}", prompt_lambSymbol)
end

clink.prompt.register_filter(prompt_filter, 1)

image

You can stop here but you can configure it by creating %cmder_root%\config\prompt_config.lua:

-- MOST of the below was 'borrowed' from https://github.com/AmrEldib/cmder-powerline-prompt

--- REQUIRED. config_prompt_type is whether the displayed prompt is the full path or only the folder name
 -- Use:
 -- "full" for full path like C:\Windows\System32
 -- "folder" for folder name only like System32
 -- "smart" to switch in git repo to folder name instead of full path 
 -- default is full
prompt_type = "smart"
--- REQUIRED. config_prompt_useHomeSymbol is whether to show ~ instead of the full path to the user's home folder
 -- Use true or false
 -- default is true
prompt_useHomeSymbol = true  

-- Symbols
-- REQUIRED. Prompt displayed instead of user's home folder e.g. C:\Users\username
prompt_homeSymbol = "~"

-- REQUIRED. Symbol displayed in the new line below the prompt.
prompt_lambSymbol = "$"

image

@Lunchb0ne
Copy link
Contributor Author

Lunchb0ne commented Jul 13, 2020

Sorry, but the replacement part is not working for me.
image

Should work though 🤔
image

@daxgames
Copy link
Member

Maybe it is cas sensitive? Output of set home?

@daxgames
Copy link
Member

I added a section to the initial script make sure you have it in yours.

@Lunchb0ne
Copy link
Contributor Author

Thanks, it works now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants