Last active
April 8, 2020 03:30
-
-
Save RangerMauve/9e34c05bb0e0e6a0c0d57af5b594b216 to your computer and use it in GitHub Desktop.
Clink script for having a nice command prompt with git branch support and home directory aliasing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function set_prompt() | |
-- Get various env vars | |
local username = clink.get_env("USERNAME") | |
local computername = clink.get_env("COMPUTERNAME") | |
local user_home = clink.get_env("USERPROFILE") | |
local current_directory = clink.get_cwd() | |
-- Initial value | |
local toprompt = "[35;1m".. | |
username.. | |
"[0m@[32;1m".. | |
computername.."[0m ".. | |
"[37;1m".. | |
current_directory:gsub(user_home, "~") | |
-- Get current git branch | |
for line in io.popen("git branch 2>nul"):lines() do | |
local m = line:match("%* (.+)$") | |
if m then | |
toprompt = toprompt.." [34;1m["..m.."][0m " | |
break | |
end | |
end | |
-- Set prompt and add suffix | |
clink.prompt.value = toprompt.." $ " | |
return false; | |
end | |
clink.prompt.register_filter(set_prompt, 420) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment