-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprofile.ps1
More file actions
211 lines (169 loc) · 6.42 KB
/
Copy pathprofile.ps1
File metadata and controls
211 lines (169 loc) · 6.42 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
sv USERAPPS (Join-Path $HOME Apps) -Option ReadOnly, AllScope
sv USERCOMMANDS (Join-Path $HOME Commands) -Option ReadOnly, AllScope
sv DESKTOP ([Environment]::GetFolderPath([Environment+SpecialFolder]::Desktop)) -Option ReadOnly, AllScope
sv DOWNLOADS (Join-Path $HOME Downloads) -Option ReadOnly, AllScope
sv PROFILEDIR (Split-Path $PROFILE) -Option ReadOnly, AllScope
Add-Member -InputObject $PROFILEDIR -Name Private -Value "$HOME\.psprofiles" -MemberType NoteProperty
sv SCRIPTS (Join-Path $HOME Scripts) -Option ReadOnly, AllScope
sal gcb Get-Clipboard
sal scb Set-Clipboard
sal FromJson ConvertFrom-Json
sal ToJson ConvertTo-Json
sal FromZip Expand-Archive
sal ToZip Compress-Archive
sal c code
sal d docker
sal dc docker-compose
sal g git
sal s syntax
sal .n dotnet
function .nb { dotnet build @Args }
function .nr { dotnet run @Args }
function .nt { dotnet test @Args }
function helpo { Get-Help @Args -Online }
function l { gci @Args | Format-Wide Name -AutoSize }
function la { gci @Args -Force | Format-Wide Name -AutoSize }
function ll { gci @Args | ? Name -NotLike .* }
function lla { gci @Args -Force }
function more { $input | Out-Host -Paging }
function .. { sl .. }
function ... { sl ../.. }
function .... { sl ../../.. }
function c. { code . }
function codes { code $SCRIPTS }
function cssh {
param (
[string]
$Name = 'default',
[Parameter(HelpMessage = 'e.g. /home/me or home/me')]
[string]
$Path = 'home'
)
code --folder-uri "vscode-remote://ssh-remote+$Name/$Path"
}
function cwsl {
param (
[string]
$Name = 'default',
[Parameter(HelpMessage = 'e.g. /home/me')]
[string]
$Path
)
code --remote "wsl+$Name" $Path
}
Register-ArgumentCompleter -ParameterName Name -ScriptBlock {
param ($commandName, $parameterName, $wordToComplete)
$tmp, $env:WSL_UTF8 = $env:WSL_UTF8, 1
wsl --list --quiet | ? { $_ -like "$wordToComplete*" }
$env:WSL_UTF8 = $tmp
} -CommandName @(
'cwsl'
)
function nop { pwsh -nop -c ($Args -join ' ') }
function Update-Profile { pushd $PROFILEDIR; git pull --rebase; popd }
Set-PSReadlineOption -BellStyle None
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineKeyHandler -Key Ctrl+R -Function ForwardSearchHistory
if ($IsLinux) {
Set-PSReadlineKeyHandler -Chord Tab -Function TabCompleteNext
Set-PSReadlineKeyHandler -Chord Shift+Tab -Function TabCompletePrevious
}
$env:PSModulePath = @(
(Join-Path $PROFILEDIR PSModules)
$env:PSModulePath
) -join [System.IO.Path]::PathSeparator
ipmo Core
$env:Path = @(
$SCRIPTS
"$PSScriptRoot\PSScripts"
if ($IsWindows) {
$USERCOMMANDS
(Get-ChildItem $USERCOMMANDS -Directory)
}
$env:Path
) -join [System.IO.Path]::PathSeparator
$env:DOTNET_CLI_UI_LANGUAGE = 'en'
[System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
function Use-Sed { Add-PathEnv "$HOME\scoop\apps\git\current\usr\bin" }
function google {
[CmdletBinding(DefaultParameterSetName = 'Default')]
param (
[Parameter(Position=0, ValueFromRemainingArguments)]
$Query,
[ValidateSet('en', 'ja', 'ko')]
$Lang,
[switch]
$Edge
)
$uri = 'https://www.google.com/search?q={0}&lr=lang_{1}' -f ($Query -join '+'), $Lang
if ($Edge) {
$uri = 'microsoft-edge:' + $uri
}
Start-Process -FilePath $uri
}
. $PSScriptRoot\Completers.ps1
if ([System.Net.ServicePointManager]::SecurityProtocol -ne [System.Net.SecurityProtocolType]::SystemDefault) {
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
}
$PSDefaultParameterValues['Import-Module:Force'] = $true
$PSDefaultParameterValues['Trace-Command:PSHost'] = $true
function prompt {
return "`u{1F4BB} PS-$($PSVersionTable.PSVersion.ToString()) $(Get-Date -Format 'yy-MM-ddTHH:mm:ssK') $([System.Environment]::UserName)@$($env:WSL_DISTRO_NAME ?? [System.Environment]::MachineName) $($PSStyle.FileInfo.Directory)$($ExecutionContext.SessionState.Path.CurrentLocation)$($PSStyle.Reset)`n$('$' * ($NestedPromptLevel + 1)) "
}
if (Test-Path $PROFILEDIR\PwshProxy.xml) {
$pwshProxy = Import-Clixml $PROFILEDIR\PwshProxy.xml
$proxy = $pwshProxy.Proxy
$proxyCredential = $pwshProxy.ProxyCredential
if ($PSVersionTable.PSVersion.Major -le 6) {
$PSDefaultParameterValues['Invoke-WebRequest:Proxy'] = $proxy
$PSDefaultParameterValues['Invoke-RestMethod:Proxy'] = $proxy
}
$PSDefaultParameterValues['Install-Module:Proxy'] = $proxy
$PSDefaultParameterValues['Register-PackageSource:Proxy'] = $proxy
$PSDefaultParameterValues['Register-PSRepository:Proxy'] = $proxy
$PSDefaultParameterValues['Save-Module:Proxy'] = $proxy
$PSDefaultParameterValues['Save-Package:Proxy'] = $proxy
$PSDefaultParameterValues['Install-AWSToolsModule:Proxy'] = $proxy
$PSDefaultParameterValues['Update-AWSToolsModule:Proxy'] = $proxy
[System.Net.WebRequest]::DefaultWebProxy = New-Object System.Net.WebProxy $proxy
if ($proxyCredential) {
if ($PSVersionTable.PSVersion.Major -le 6) {
$PSDefaultParameterValues['Invoke-WebRequest:ProxyCredential'] = $proxyCredential
$PSDefaultParameterValues['Invoke-RestMethod:ProxyCredential'] = $proxyCredential
}
$PSDefaultParameterValues['Install-Module:ProxyCredential'] = $proxyCredential
$PSDefaultParameterValues['Register-PackageSource:ProxyCredential'] = $proxyCredential
$PSDefaultParameterValues['Register-PSRepository:ProxyCredential'] = $proxyCredential
$PSDefaultParameterValues['Save-Module:ProxyCredential'] = $proxyCredential
$PSDefaultParameterValues['Save-Package:ProxyCredential'] = $proxyCredential
$PSDefaultParameterValues['Install-AWSToolsModule:ProxyCredential'] = $proxyCredential
$PSDefaultParameterValues['Update-AWSToolsModule:ProxyCredential'] = $proxyCredential
[System.Net.WebRequest]::DefaultWebProxy.Credentials = $proxyCredential
$httpProxyEnv = @(
$proxyCredential.GetNetworkCredential().UserName
$proxyCredential.GetNetworkCredential().Password
$proxy.Authority
)
$env:http_proxy = 'http://{0}:{1}@{2}' -f $httpProxyEnv
$env:https_proxy = 'https://{0}:{1}@{2}' -f $httpProxyEnv
Remove-Variable proxyCredential, httpProxyEnv
} else {
$env:http_proxy = 'http://{0}' -f $proxy.Authority
$env:https_proxy = 'https://{0}' -f $proxy.Authority
}
Remove-Variable pwshProxy, proxy
}
if (Test-Path $PROFILEDIR.Private) {
function codep {
$params = @(
$PROFILEDIR
$PROFILE.CurrentUserAllHosts
(Get-ChildItem $PROFILEDIR.Private -File)
)
code @params
}
. "$($PROFILEDIR.Private)\profile.ps1"
} else {
function codep { code $PROFILEDIR $PROFILE.CurrentUserAllHosts }
}