-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
142 lines (119 loc) · 3.51 KB
/
Copy pathMicrosoft.PowerShell_profile.ps1
File metadata and controls
142 lines (119 loc) · 3.51 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
# history
# =======
$MaximumHistoryCount = 30000
Set-PSReadLineOption -MaximumHistoryCount 1000000000
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Set-PSReadLineOption -HistoryNoDuplicates
function Search-History {
param(
[Parameter(Position = 0, Mandatory = $true)]
[string]$searchPattern
)
$historyPath = (Get-PSReadLineOption).HistorySavePath
Get-Content -Path $historyPath | Select-String -Pattern $searchPattern -SimpleMatch
}
New-Alias -Name hist -Value Search-History
# prompt stuff
# ============
# disable cursor blinking
if ($PSVersionTable.PSVersion.Major -ge 7) {
Write-Output "`e[?12l"
}
function Get-LastStatus() {
if ($?) {
return '>'
}
else {
return "$($PSStyle.Foreground.BrightRed)>$($PSStyle.Reset)"
}
}
function Get-GitBranch {
if ((Test-Path .git) -or ((git rev-parse --is-inside-work-tree 2>$null) -eq "true")) {
$gitBranch = (git branch --show-current 2>$null) ?? (git rev-parse --short HEAD 2>$null)
return " $($PSStyle.Foreground.BrightCyan)${gitBranch}$($PSStyle.Reset)"
}
}
function prompt {
$lastStatus = Get-LastStatus
$currentDirectory = (Get-Location).path
$gitBranch = Get-GitBranch
"${currentDirectory}${gitBranch}${lastStatus} "
}
# extra
# =====
function Search-File {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[string]$searchPattern
)
process {
Get-ChildItem -Path '.' -Recurse -FollowSymlink -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -Filter "*$searchPattern*" | Select-Object -ExpandProperty FullName
}
}
function Search-File2 {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0)]
[string]$searchPattern
)
fd.exe --follow --hidden $searchPattern
}
function Search-FileContent {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0)]
[string]$searchPattern,
[switch]$Recurse
)
Get-ChildItem -Path '.' -FollowSymlink -Force -File -Recurse:$Recurse |
Where-Object {
try {
$stream = [System.IO.File]::OpenRead($_.FullName)
$buffer = New-Object byte[] 1024
$read = $stream.Read($buffer, 0, 1024)
$stream.Close()
$slice = $buffer[0..($read - 1)]
-not ($slice | Where-Object { $_ -lt 9 -or ($_ -gt 13 -and $_ -lt 32) })
}
catch {
$false
}
finally {
if ($stream) { $stream.Dispose() }
}
} | Select-String -Pattern $searchPattern -SimpleMatch
}
function Search-FileContent2 {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0)]
[string]$searchPattern,
[switch]$Recurse
)
$flags = @('/i', '/p', '/n')
if ($Recurse) { $flags += '/s' }
findstr.exe @flags $searchPattern *
}
function Search-FileContent3 {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0)]
[string]$searchPattern,
[switch]$Recurse
)
$flags = @('--follow', '--hidden', '--search-zip', '--smart-case')
if (-not $Recurse) { $flags += '--max-depth', '1' }
$flags += '-e'
rg.exe @flags $searchPattern
}
function Send-Stuff {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0)]
[ValidateScript({ Test-Path $_ })]
[string]$filePath
)
scp $filePath x230:/home/glg/Downloads/
}
New-Alias -Name scpp -Value Send-Stuff