-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.ps1
More file actions
167 lines (139 loc) · 5.58 KB
/
profile.ps1
File metadata and controls
167 lines (139 loc) · 5.58 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
Function prompt {
# Script based on examples provided by Rikard Ronnkvist / snowland.se
# Multicolored prompt with marker for windows started as Admin and marker for providers outside filesystem
# New nice WindowTitle
$Host.UI.RawUI.WindowTitle = "PowerShell v" + (get-host).Version.Major + "." + (get-host).Version.Minor + " (" + $pwd.Provider.Name + ") " + $pwd.Path
# Admin ?
if( (
New-Object Security.Principal.WindowsPrincipal (
[Security.Principal.WindowsIdentity]::GetCurrent())
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
# Admin-mark in WindowTitle
$Host.UI.RawUI.WindowTitle = "[Admin] " + $Host.UI.RawUI.WindowTitle
# Admin-mark on prompt
Write-Host "[" -nonewline -foregroundcolor DarkGray
Write-Host "Admin" -nonewline -foregroundcolor Red
Write-Host "] > " -nonewline -foregroundcolor DarkGray
}
# Show providername if you are outside FileSystem
if ($pwd.Provider.Name -ne "FileSystem") {
Write-Host "[" -nonewline -foregroundcolor DarkGray
Write-Host $pwd.Provider.Name -nonewline -foregroundcolor Gray
Write-Host "] > " -nonewline -foregroundcolor DarkGray
}
# write out username and hostname
Write-Host $env:username -nonewline -foregroundcolor Cyan
Write-Host "@" -nonewline -foregroundcolor Cyan
Write-Host $env:computername -nonewline -foregroundcolor Cyan
Write-Host " > " -nonewline
# Split path and write \ in a gray
$currpath = $pwd.Path.Split("\")
foreach ( $dir in $($currpath -ne $currpath[-1]) ) {
if ($dir[0] -eq ".") {
Write-Host $($dir[0] + $dir[1]) -nonewline -foregroundcolor Yellow
} else {
Write-Host $dir[0] -nonewline -foregroundcolor Yellow
}
Write-Host "\" -nonewline -foregroundcolor Gray
}
Write-Host $currpath[-1] -nonewline -foregroundcolor Yellow
# if posh-git is available, run the relevant bit here.
if (Get-Command Write-VcsStatus -errorAction SilentlyContinue) {
Write-VcsStatus
}
Write-Host " >" -nonewline -foregroundcolor Gray
return " "
}
if (Get-Command starship -ErrorAction SilentlyContinue) {
# if we have starship, ignore everything above and use it instead
Invoke-Expression (&starship init powershell)
}
Function Edit-Profile {
nvim $profile
}
Function Reload-Profile {
if (!(Test-Path -Path $profile )) {
New-Item -Type File -Path $profile -Force
}
. $profile
}
Function List-EmptyDirectories {
# Assumes you are in the correct directory unless told otherwise
Param (
[Parameter(mandatory)] $path
)
Get-ChildItem $path -Directory -Recurse -ErrorAction 'ignore' `
| Where-Object {
($_.GetFileSystemInfos().Count -eq 0) -and ($_.FullName -notmatch '\\\.')
} `
| ForEach-Object { $_.FullName }
}
Function Set-FileTimeStamps {
Param (
# [Parameter(mandatory=$true)]
[string[]]$path,
[datetime]$date = (Get-Date))
if (-not ($path)) {
Throw "Must supply a value for -Path"
}
Get-ChildItem -Path $path |
ForEach-Object {
$_.CreationTime = $_.LastAccessTime = $_.LastWriteTime = $date
}
}
Function Convert-Size {
<#
.SYSNOPSIS
Converts a size in bytes to its upper most value.
.DESCRIPTION
Converts a size in bytes to its upper most value.
.PARAMETER Size
The size in bytes to convert
.NOTES
Author: Boe Prox
Date Created: 22AUG2012
.EXAMPLE
Convert-Size -Size 568956
555 KB
Description
-----------
Converts the byte value 568956 to upper most value of 555 KB
.EXAMPLE
Get-ChildItem | ? {! $_.PSIsContainer} | Select -First 5 | Select Name, @{L='Size';E={$_ | Convert-Size}}
Name Size
---- ----
Data1.cap 14.4 MB
Data2.cap 12.5 MB
Image.iso 5.72 GB
Index.txt 23.9 KB
SomeSite.lnk 1.52 KB
SomeFile.ini 152 bytes
Description
-----------
Used with Get-ChildItem and custom formatting with Select-Object to list the uppermost size.
#>
[cmdletbinding()]
Param (
[parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
[Alias("Length")]
[int64]$Size
)
Begin {
If (-Not $ConvertSize) {
Write-Verbose ("Creating signature from Win32API")
$Signature = @"
[DllImport("Shlwapi.dll", CharSet = CharSet.Auto)]
public static extern long StrFormatByteSize( long fileSize, System.Text.StringBuilder buffer, int bufferSize );
"@
$Global:ConvertSize = Add-Type -Name SizeConverter -MemberDefinition $Signature -PassThru
}
Write-Verbose ("Building buffer for string")
$stringBuilder = New-Object Text.StringBuilder 1024
}
Process {
Write-Verbose ("Converting {0} to upper most size" -f $Size)
$ConvertSize::StrFormatByteSize( $Size, $stringBuilder, $stringBuilder.Capacity ) | Out-Null
$stringBuilder.ToString()
}
}
Set-Alias -Name g -Value git.exe