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
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -13,3 +13,4 @@ test/
|
||||||
*.gz
|
*.gz
|
||||||
*.tar
|
*.tar
|
||||||
*.zip
|
*.zip
|
||||||
|
*_private/
|
||||||
|
|
@ -2,100 +2,21 @@
|
||||||
|
|
||||||
$DOTFILES = "$HOME\.dotfiles"
|
$DOTFILES = "$HOME\.dotfiles"
|
||||||
|
|
||||||
### PSReadLine ###
|
### Load Configs ###
|
||||||
|
|
||||||
Set-PSReadLineOption -EditMode vi # Vi Keybindings
|
Get-ChildItem -Path $DOTFILES\powershell -Filter *.ps1 | ForEach-Object {. $_}
|
||||||
Set-PSReadLineOption -PredictionViewStyle ListView # Prediction View Style
|
Get-ChildItem -Path $DOTFILES\powershell_private -Filter *.ps1 | ForEach-Object {. $_}
|
||||||
Set-PSReadLineOption -PredictionSource HistoryAndPlugin # Prediction Source
|
|
||||||
Set-PSReadLineOption -ContinuationPrompt "`e[36m CR > " # Continuation Prompt
|
|
||||||
|
|
||||||
### Keybindings ###
|
## Aliases ###
|
||||||
|
|
||||||
Set-PSReadLineKeyHandler -Chord "Ctrl+f" -Function ForwardWord
|
|
||||||
|
|
||||||
### 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 }
|
|
||||||
|
|
||||||
### Aliases ###
|
|
||||||
|
|
||||||
# PowerShell Equivalents #
|
# PowerShell Equivalents #
|
||||||
|
|
||||||
Set-Alias "touch" "New-Item"
|
|
||||||
Set-Alias "ll" "Get-ChildItem"
|
|
||||||
Set-Alias "curl" "Invoke-WebRequest"
|
Set-Alias "curl" "Invoke-WebRequest"
|
||||||
Set-Alias "man" "Get-Help"
|
Set-Alias "man" "Get-Help"
|
||||||
Set-Alias "kill" "Stop-Process"
|
Set-Alias "kill" "Stop-Process"
|
||||||
|
Set-Alias "open" "Invoke-Item" # Use ii instead of open
|
||||||
|
|
||||||
# Dev #
|
# Dev #
|
||||||
|
|
||||||
${function:shcfg} = { code $PROFILE }
|
|
||||||
${function:zshcfg} = { nvim ~/.zshrc }
|
${function:zshcfg} = { nvim ~/.zshrc }
|
||||||
${function:bashcfg} = { nvim ~/.bashrc }
|
${function:bashcfg} = { nvim ~/.bashrc }
|
||||||
${function:reload} = { Invoke-Expression $PROFILE }
|
|
||||||
${function:csi} = { dotnet script }
|
|
||||||
${function:pulldots} = { Set-Location -Path $DOTFILES && git pull }
|
|
||||||
Set-Alias "pwshcfg" "shcfg"
|
|
||||||
Set-Alias "cl" "clang"
|
|
||||||
Set-Alias "cl++" "clang++"
|
|
||||||
Set-Alias "clang" "clang -std=c99"
|
|
||||||
Set-Alias "clang++" "clang++ -std=c++2b"
|
|
||||||
|
|
||||||
# Python & Conda #
|
|
||||||
|
|
||||||
Set-Alias "python3" "python"
|
|
||||||
Set-Alias "pip3" "pip"
|
|
||||||
Set-Alias "py" "python"
|
|
||||||
Set-Alias "pyact" "conda activate"
|
|
||||||
Set-Alias "pylsenv" "conda env list"
|
|
||||||
Set-Alias "pydeact" "conda deactivate"
|
|
||||||
Set-Alias "pymkenv" "conda create --name"
|
|
||||||
|
|
||||||
# Editors #
|
|
||||||
|
|
||||||
Set-Alias "v" "nvim"
|
|
||||||
Set-Alias "c" "code"
|
|
||||||
Set-Alias "gvi" "neovide"
|
|
||||||
|
|
||||||
# Miscs #
|
|
||||||
|
|
||||||
Set-Alias mcd CreateAndSet-Directory
|
|
||||||
|
|
||||||
### Functions ###
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Modules ###
|
|
||||||
|
|
||||||
Import-Module CompletionPredictor
|
|
||||||
# Import-Module syntax-highlighting
|
|
||||||
|
|
||||||
### Misc ###
|
|
||||||
|
|
||||||
|
|
|
||||||
0
mac/readme.md
Normal file
0
mac/readme.md
Normal file
|
|
@ -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
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
- [Windows](./win/readme.md)
|
- [Windows](./win/readme.md)
|
||||||
- [Linux](./linux/readme.md)
|
- [Linux](./linux/readme.md)
|
||||||
|
- [Mac](./mac/readme.md)
|
||||||
|
|
||||||
- [Neovim](./nvim/readme.md)
|
- [Neovim](./nvim/readme.md)
|
||||||
- [VSCode](./vscode/readme.md)
|
- [VSCode](./vscode/readme.md)
|
||||||
|
|
@ -14,10 +15,5 @@
|
||||||
|
|
||||||
- [pip](./pip.conf)
|
- [pip](./pip.conf)
|
||||||
- [npm](./.npmrc)
|
- [npm](./.npmrc)
|
||||||
|
- [conda](./.condarc)
|
||||||
|
|
||||||
|
|
||||||
### Scripts
|
|
||||||
|
|
||||||
- [Install Neovim *nix](./install_nvim.sh)
|
|
||||||
- [Set Mirror *nix](./set_mirror.sh)
|
|
||||||
- [Set Mirror PowerShell](./set_mirror.ps1)
|
|
||||||
|
|
@ -5,56 +5,13 @@ $DOTFILES = "$HOME\Documents\.dotfiles"
|
||||||
### Load Configs ###
|
### Load Configs ###
|
||||||
|
|
||||||
Get-ChildItem -Path $DOTFILES\powershell -Filter *.ps1 | ForEach-Object {. $_}
|
Get-ChildItem -Path $DOTFILES\powershell -Filter *.ps1 | ForEach-Object {. $_}
|
||||||
|
Get-ChildItem -Path $DOTFILES\powershell_private -Filter *.ps1 | ForEach-Object {. $_}
|
||||||
### PSReadLine ###
|
|
||||||
|
|
||||||
Set-PSReadLineOption -EditMode vi # Vi Keybindings
|
|
||||||
Set-PSReadLineOption -PredictionViewStyle ListView # Prediction View Style
|
|
||||||
Set-PSReadLineOption -PredictionSource HistoryAndPlugin # Prediction Source
|
|
||||||
Set-PSReadLineOption -ContinuationPrompt "`e[36m CR > " # Continuation Prompt
|
|
||||||
|
|
||||||
### 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 ~\Temporary }
|
|
||||||
${function:one} = { Set-Location -Path ~\OneDrive }
|
|
||||||
${function:doku} = { Set-Location -Path ~\MyDocuments && Get-ChildItem }
|
|
||||||
|
|
||||||
### Aliases ###
|
### Aliases ###
|
||||||
|
|
||||||
# Shell Equivalents #
|
# Shell Equivalents #
|
||||||
|
|
||||||
Set-Alias "touch" "New-Item"
|
Set-Alias "open" "Invoke-Item" # Use ii instead of explorer.exe
|
||||||
function open {
|
|
||||||
if ($args.Count -eq 0) {
|
|
||||||
explorer.exe .
|
|
||||||
} else {
|
|
||||||
explorer.exe $args[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Shell Configurations #
|
# Shell Configurations #
|
||||||
|
|
||||||
|
|
@ -62,11 +19,6 @@ ${function:shcfg} = { code $PROFILE }
|
||||||
${function:reload} = { . $PROFILE }
|
${function:reload} = { . $PROFILE }
|
||||||
${function:pulldots} = { Set-Location -Path $DOTFILES && git pull }
|
${function:pulldots} = { Set-Location -Path $DOTFILES && git pull }
|
||||||
Set-Alias "pwshcfg" "shcfg"
|
Set-Alias "pwshcfg" "shcfg"
|
||||||
|
|
||||||
# Dotnet #
|
|
||||||
|
|
||||||
${function:csi} = { dotnet script }
|
|
||||||
|
|
||||||
# C & C++ #
|
# C & C++ #
|
||||||
|
|
||||||
# Set-Alias "cl" "clang"
|
# Set-Alias "cl" "clang"
|
||||||
|
|
@ -78,13 +30,8 @@ ${function:csi} = { dotnet script }
|
||||||
|
|
||||||
Set-Alias "python3" "python"
|
Set-Alias "python3" "python"
|
||||||
Set-Alias "pip3" "pip"
|
Set-Alias "pip3" "pip"
|
||||||
Set-Alias "py" "python"
|
|
||||||
${function:pyact} = { conda activate $args[0] }
|
|
||||||
${function:pylsenvs} = { conda env list }
|
|
||||||
${function:pydact} = { conda deactivate }
|
|
||||||
${function:pymkenv} = { conda create --name $args[0] }
|
|
||||||
|
|
||||||
# # Git #
|
# Git #
|
||||||
|
|
||||||
# Set-Alias "g" "git"
|
# Set-Alias "g" "git"
|
||||||
# Set-Alias "ginit" "git init"
|
# Set-Alias "ginit" "git init"
|
||||||
|
|
@ -104,26 +51,14 @@ ${function:pymkenv} = { conda create --name $args[0] }
|
||||||
${function:wsl1} = {wsl.exe --distribution Debian}
|
${function:wsl1} = {wsl.exe --distribution Debian}
|
||||||
${function:wsl2} = {wsl.exe --distribution Ubuntu-22.04}
|
${function:wsl2} = {wsl.exe --distribution Ubuntu-22.04}
|
||||||
|
|
||||||
# Editors #
|
|
||||||
|
|
||||||
Set-Alias "v" "nvim"
|
|
||||||
Set-Alias "c" "code"
|
|
||||||
Set-Alias "gvi" "neovide"
|
|
||||||
|
|
||||||
# Miscs #
|
# Miscs #
|
||||||
|
|
||||||
|
|
||||||
### Functions ###
|
|
||||||
|
|
||||||
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 }
|
|
||||||
|
|
||||||
### Modules ###
|
### Modules ###
|
||||||
|
|
||||||
Import-Module -Name Microsoft.WinGet.CommandNotFound #f45873b3-b655-43a6-b217-97c00aa0db58
|
Import-Module -Name Microsoft.WinGet.CommandNotFound #f45873b3-b655-43a6-b217-97c00aa0db58
|
||||||
Import-Module CompletionPredictor
|
Import-Module CompletionPredictor
|
||||||
|
# Import-Module syntax-highlighting # Buggy
|
||||||
|
|
||||||
### Misc ###
|
### Misc ###
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue