-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
74 lines (64 loc) · 2.04 KB
/
Microsoft.PowerShell_profile.ps1
File metadata and controls
74 lines (64 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# PowerShell Profile
function Get-GitBranch {
# Try to get git status, return empty if not in a git repository
$status = git status --porcelain 2>$null
if ($LASTEXITCODE -eq 0) {
$branch = git rev-parse --abbrev-ref HEAD 2>$null
# Check for changes (untracked or modified files)
$hasChanges = $false
$hasStaged = $false
if ($status) {
foreach ($line in $status) {
# Untracked (??) or modified unstaged (.M) files
if ($line -match '^\?\?|^.M') {
$hasChanges = $true
}
# Staged files (A, M, D, R, C in first column)
if ($line -match '^[MADRC]') {
$hasStaged = $true
}
}
}
$statusStr = ""
if ($hasChanges) {
$statusStr += "*"
}
if ($hasStaged) {
$statusStr += "+"
}
if ($branch) {
return " ($branch)$statusStr"
}
}
return ""
}
function prompt {
# Get virtual environment name if active
$venvPrompt = ""
if ($env:VIRTUAL_ENV) {
if ($env:VIRTUAL_ENV_PROMPT) {
$venvPrompt = $env:VIRTUAL_ENV_PROMPT
}
else {
$venvName = Split-Path -Leaf $env:VIRTUAL_ENV
if ($venvName -eq ".venv") {
$parentDir = Split-Path -Leaf (Split-Path -Parent $env:VIRTUAL_ENV)
$venvPrompt = "($parentDir) "
}
else {
$venvPrompt = "($venvName) "
}
}
}
# Get current directory (replace home path with ~)
$currentPath = $PWD.Path.Replace($HOME, "~")
# Get git branch and status
$gitInfo = Get-GitBranch
# Build prompt
Write-Host "λ " -NoNewline -ForegroundColor Yellow
Write-Host "$venvPrompt" -NoNewline
Write-Host "$currentPath" -NoNewline
Write-Host "$gitInfo" -NoNewline
# Return the prompt character (❯ U+276F)
return " ❯ "
}