dotfiles/win/profile.ps1

109 lines
3.2 KiB
PowerShell
Raw Normal View History

2020-06-20 13:41:13 +00:00
# adminstration powershell:
2020-05-10 07:20:40 +00:00
# Set-ExecutionPolicy RemoteSigned
# new-item -ItemType SymbolicLink -Target "D:\Nextcloud\klesh\config\win\profile.ps1" -Path $profile
2021-06-06 03:42:40 +00:00
#$env:POSH_GIT_ENABLED = $true
2020-05-10 07:20:40 +00:00
Set-PSReadLineOption -EditMode Emacs
2020-09-10 02:43:27 +00:00
Set-PSReadLineOption -PredictionSource History
2021-01-14 04:56:57 +00:00
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r'
2021-02-26 10:12:32 +00:00
Import-Module posh-git
Import-Module oh-my-posh
2020-09-10 02:43:27 +00:00
2021-01-16 06:05:46 +00:00
$Dir = (Get-Item (Get-Item $PSCommandPath).Target).Directory.FullName
$Env:Path += ";$Dir\bin"
$Env:PSModulePath += ";$Dir\Modules"
$Env:KUBE_EDITOR = 'nvim'
$Env:EDITOR = 'nvim'
2021-01-30 03:32:56 +00:00
$Env:VIM_MODE = 'enhanced'
2020-07-27 02:41:32 +00:00
Set-Alias -Name k kubectl
2021-01-17 08:50:51 +00:00
Set-Alias -Name bm Open-Bookmark
2021-01-21 16:17:26 +00:00
Set-Alias -Name v nvim
$isPs7 = $host.Version.Major -ge 7
if ( $isPs7 ) {
2021-06-06 03:42:40 +00:00
$GitPromptSettings.EnableFileStatus = $false
2021-02-26 10:12:32 +00:00
if ((Get-Module oh-my-posh).Version.Major -eq 3) {
2021-06-06 03:42:40 +00:00
Set-PoshPrompt -Theme fish
2021-02-26 10:12:32 +00:00
} else {
2021-06-06 03:42:40 +00:00
Set-Prompt -Theme fish
2021-02-26 10:12:32 +00:00
}
}
2020-07-27 02:41:32 +00:00
function kcc { k config get-contexts $args }
function kcu { k config use-context $args}
function kgd { k get deployment $args}
function ked { k edit deployment $args}
2020-08-17 02:28:27 +00:00
function kgp { k get pod -o 'custom-columns=NAME:.metadata.name,IMG:.spec.containers[*].image,STATUS:.status.phase' $args}
2020-07-27 02:41:32 +00:00
function kl { k logs -f --all-containers $args}
2020-08-17 02:28:27 +00:00
function issh { ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" $args }
2020-08-23 03:08:19 +00:00
function rf { ri -Recurse -Force $args }
2020-07-27 02:41:32 +00:00
2020-05-10 07:20:40 +00:00
2020-05-24 09:34:33 +00:00
function dp {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,ValueFromRemainingArguments)]
[String[]]
$words
)
$word = $words | Join-String -Separator ' '
2020-05-10 07:20:40 +00:00
Add-Type -AssemblyName presentationCore
$tmpPath = Join-Path -Path $env:Temp -ChildPath 'sound.mp3'
Invoke-WebRequest -Uri "http://dict.youdao.com/dictvoice?audio=$Word&type=1" -OutFile $tmpPath
$mediaPlayer = New-Object system.windows.media.mediaplayer
$mediaPlayer.Open($tmpPath)
$mediaPlayer.Play()
Start-Sleep -Seconds 2
$mediaPlayer.Close()
}
2020-05-24 09:34:33 +00:00
function d {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,ValueFromRemainingArguments)]
[String[]]
$words
)
$word = $words | Join-String -Separator ' '
$res = Invoke-WebRequest -Uri "https://cn.bing.com/dict/search" -Method GET -Body @{q=$word}
if ($res.Content -match '<meta name="description" content="(.+?)" />') {
$explain = $Matches[1] -replace '必应词典为您提供.+的释义,(.+)','$1'
$explain = $explain -replace ' 网络释义',"`r`n网络释义"
$explain = $explain -replace '',"`r`n"
Write-Host $explain
} else {
throw 'meta description not found'
}
}
function vsbuild {
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Enter-VsDevShell 56e7bf1c
2020-06-20 04:38:36 +00:00
}
function ssh-copy-id {
[Cmdletbinding()]
param (
[Parameter()]
[String]
$IdentityFile="~/.ssh/id_rsa.pub",
[Parameter(Mandatory=$true, Position=0)]
[String]
$UserHost
)
Get-Content $IdentityFile | ssh $UserHost "umask 077; mkdir -p .ssh ; cat >> .ssh/authorized_keys"
}
2021-01-14 04:56:57 +00:00
2021-03-21 10:09:58 +00:00
function f {
[Cmdletbinding()]
$tmpfile = New-TemporaryFile
lf -last-dir-path $tmpfile
$lastdir = Get-Content $tmpfile
Remove-Item $tmpfile
cd $lastdir
}