mirror of
https://github.com/js0ny/dotfiles.git
synced 2025-12-21 08:43:00 +00:00
Update PowerShell Structures
This commit is contained in:
parent
7d933a0b16
commit
d400f65ae7
8 changed files with 100 additions and 222 deletions
|
|
@ -1,33 +0,0 @@
|
|||
function Get-Password {
|
||||
param (
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Name,
|
||||
[Boolean]$Hidden = $true
|
||||
)
|
||||
$result = (bw list items --search $Name | ConvertFrom-Json).login | Select-Object -Property username, password
|
||||
if ($result.Length -eq 0) {
|
||||
Write-Host -ForegroundColor Red "No password found"
|
||||
return
|
||||
}
|
||||
elseif ($result.Length -gt 1) {
|
||||
Write-Host -ForegroundColor Red "More than one password found, please specify"
|
||||
$counter = 0
|
||||
foreach ($username in $result.username) {
|
||||
Write-Host "["$counter "]" $username
|
||||
$counter++
|
||||
}
|
||||
$selector = Read-Host -MaskInput "Select the username"
|
||||
if ($result[$selector] -eq "") {
|
||||
Write-Host -ForegroundColor Red "Invalid selection"
|
||||
return
|
||||
}
|
||||
$result = $result[$selector]
|
||||
}
|
||||
if ($Hidden) {
|
||||
Write-Host -ForegroundColor Green "Password copied to clipboard"
|
||||
Set-Clipboard -Value $result.password
|
||||
} else {
|
||||
Write-Host $result
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
$_userForexToday = (Get-Content ~/.forex | ConvertFrom-Json).conversion_rates
|
||||
|
||||
function Update-ForexData {
|
||||
((Invoke-WebRequest "$_userForexUrl").Content | ConvertFrom-Json).conversion_rates > ~/.forex
|
||||
}
|
||||
function Get-ExchangeRate {
|
||||
param (
|
||||
[string] $From,
|
||||
[string] $To = "CNY",
|
||||
[double] $Value = 1
|
||||
)
|
||||
if (-not $from) {
|
||||
Get-ForexOverview
|
||||
return
|
||||
}
|
||||
Write-Host $From : $To " " -NoNewline -ForegroundColor DarkGreen
|
||||
($Value * ($_userForexToday.$To / $_userForexToday.$From)) | Write-Host -ForegroundColor DarkBlue
|
||||
}
|
||||
|
||||
function Get-ForexOverview {
|
||||
Get-ExchangeRate -From GBP -To CNY -Value 1
|
||||
Get-ExchangeRate -From USD -To CNY -Value 1
|
||||
Get-ExchangeRate -From HKD -To CNY -Value 1
|
||||
Get-ExchangeRate -From EUR -To CNY -Value 1
|
||||
Get-ExchangeRate -From CNY -To JPY -Value 1
|
||||
}
|
||||
|
||||
Set-Alias "forex" "Get-ExchangeRate"
|
||||
86
powershell/shared.ps1
Normal file
86
powershell/shared.ps1
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
### PSReadLine ###
|
||||
|
||||
Set-PSReadLineOption -EditMode vi # Vi Keybindings
|
||||
Set-PSReadLineOption -PredictionViewStyle ListView
|
||||
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
|
||||
Set-PSReadLineOption -ContinuationPrompt "`e[36m CR > "
|
||||
|
||||
### Keybindings ###
|
||||
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+Shift+f" -Function ForwardWord
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+Shift+b" -Function BackwardWord
|
||||
Set-PSReadLineKeyHandler -Chord "Alt+f" -Function ForwardChar
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+b" -Function BackwardChar
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+p" -Function HistorySearchBackward
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+n" -Function HistorySearchForward
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+a" -Function BeginningOfLine
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+e" -Function EndOfLine
|
||||
|
||||
### Navigator ###
|
||||
|
||||
# Relative navigation #
|
||||
|
||||
# ${function:~} = { Set-Location -Path ~ } cd is better
|
||||
${function:...} = { Set-Location -Path ..\.. }
|
||||
${function:....} = { Set-Location -Path ..\..\.. }
|
||||
${function:.....} = { Set-Location -Path ..\..\..\.. }
|
||||
${function:......} = { Set-Location -Path ..\..\..\..\.. }
|
||||
|
||||
# Absolute navigation #
|
||||
|
||||
${function:docs} = { Set-Location -Path ~/Documents }
|
||||
${function:down} = { Set-Location -Path ~/Downloads }
|
||||
${function:dt} = { Set-Location -Path ~/Desktop }
|
||||
${function:mytmp} = { Set-Location -Path ~/Temp }
|
||||
${function:one} = { Set-Location -Path ~/OneDrive }
|
||||
${function:doku} = { Set-Location -Path ~/doku && Get-ChildItem }
|
||||
|
||||
### Alias ###
|
||||
|
||||
# Shell Equivalents #
|
||||
|
||||
Set-Alias "touch" "New-Item"
|
||||
${function:ll} = { Get-ChildItem -Force }
|
||||
|
||||
# Shell Configurations #
|
||||
|
||||
${function:shcfg} = { code $PROFILE }
|
||||
Set-Alias "pwshcfg" "shcfg"
|
||||
${function:reload} = { . $PROFILE }
|
||||
${function:pulldots} = { Set-Location -Path $DOTFILES && git pull }
|
||||
|
||||
# Editors #
|
||||
|
||||
Set-Alias "v" "nvim"
|
||||
Set-Alias "c" "code"
|
||||
Set-Alias "gvi" "neovide"
|
||||
|
||||
# File Creation #
|
||||
|
||||
function mkcd { param ( [string] $dirname) mkdir $dirname && Set-Location $dirname }
|
||||
function tc { param ( [string] $filename) New-Item $filename && code $filename }
|
||||
function tv { param ( [string] $filename) New-Item $filename && nvim $filename }
|
||||
function cdls { param( [string] $dirname) Set-Location $dirname && Get-ChildItem }
|
||||
|
||||
### Dev ###
|
||||
|
||||
# .NET #
|
||||
|
||||
${function:csi} = { dotnet repl --default-kernel csharp}
|
||||
${function:fsi} = { dotnet repl --default-kernel fsharp}
|
||||
|
||||
# Python & Conda #
|
||||
|
||||
Set-Alias "py" "python"
|
||||
${function:pyact} = { conda activate $args[0] }
|
||||
${function:pydact} = { conda deactivate }
|
||||
${function:pylsenvs} = { conda env list }
|
||||
${function:pymkenv} = { conda create --name $args[0] }
|
||||
${function:pyrmenv} = { conda remove --name $args[0] --all }
|
||||
|
||||
# C & C++ #
|
||||
|
||||
|
||||
### Modules ###
|
||||
|
||||
Import-Module CompletionPredictor
|
||||
Loading…
Add table
Add a link
Reference in a new issue