mirror of
https://github.com/js0ny/dotfiles.git
synced 2025-12-21 08:43:00 +00:00
feat(pwsh): Windows Migration and optimize powershell scripts
This commit is contained in:
parent
567c8d1b3b
commit
8306264bdb
12 changed files with 141 additions and 133 deletions
|
|
@ -1,13 +1,16 @@
|
|||
# $DOTFILES/tools\powershell\Aliases.ps1
|
||||
# Date: 2024-12-01
|
||||
# Author: contact@js0ny.net
|
||||
# Aliases for PowerShell
|
||||
### VARIABLES ###
|
||||
$EDITOR = "code"
|
||||
# Shell Equivalents #
|
||||
Set-Alias "touch" "New-Item"
|
||||
${function:ll} = { Get-ChildItem -Force }
|
||||
${function:l} = { Get-ChildItem -Force }
|
||||
${function:tree} = { lsd.exe --tree $args }
|
||||
Set-Alias "which" "Get-Command"
|
||||
|
||||
# Shell Configurations #
|
||||
${function:shcfg} = { code $PROFILE }
|
||||
Set-Alias "pwshcfg" "shcfg"
|
||||
${function:reload} = { . $PROFILE }
|
||||
${function:pulldots} = { Set-Location -Path $DOTFILES && git pull }
|
||||
|
||||
# Editors #
|
||||
|
|
@ -16,31 +19,13 @@ Set-Alias "c" "code"
|
|||
Set-Alias "gvi" "neovide"
|
||||
|
||||
# File Creation #
|
||||
function mkcd { param ( [string] $dirname) mkdir $dirname && Set-Location $dirname }
|
||||
function mkcd { param ( [string] $dirname) New-Item -ItemType Directory -Name $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"
|
||||
Set-Alias "ipy" "ipython"
|
||||
${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 }
|
||||
|
||||
# Winget #
|
||||
|
||||
if ($isWindows) {
|
||||
${function:wini} = { winget install $args }
|
||||
${function:winr} = { winget uninstall $args }
|
||||
${function:wins} = { winget search $args }
|
||||
${function:winu} = { winget upgrade $args }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
function Invoke-Completion {
|
||||
param ([string]$command)
|
||||
switch ($command) {
|
||||
'docker' { docker completion powershell | Out-String | Invoke-Expression }
|
||||
'git' { Import-Module Posh-Git }
|
||||
'hugo' { hugo completion powershell | Out-String | Invoke-Expression }
|
||||
'pip' { pip completion --powershell | Out-String | Invoke-Expression }
|
||||
}
|
||||
}
|
||||
10
tools/powershell/Environment.ps1
Normal file
10
tools/powershell/Environment.ps1
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# $DOTFILES/tools\powershell\Environment.ps1
|
||||
# Date: 2024-12-01
|
||||
# Author: contact@js0ny.net
|
||||
# Sourced by Microsoft.PowerShell_profile.ps1
|
||||
|
||||
|
||||
# This file stores only environment variables that only called by
|
||||
# interactive session.
|
||||
|
||||
$env:IPYTHONDIR = "$env:AppData\ipython"
|
||||
|
|
@ -1,15 +1,14 @@
|
|||
# ${function:~} = { Set-Location -Path ~ } cd is better
|
||||
${function:...} = { Set-Location -Path ..\.. }
|
||||
${function:....} = { Set-Location -Path ..\..\.. }
|
||||
${function:.....} = { Set-Location -Path ..\..\..\.. }
|
||||
${function:......} = { Set-Location -Path ..\..\..\..\.. }
|
||||
${function:...} = { Set-Location -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) }
|
||||
${function:....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:.....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
${function:......} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) }
|
||||
|
||||
# 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 }
|
||||
${function:docs} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Documents") }
|
||||
${function:down} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Downloads") }
|
||||
${function:dt} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Desktop") }
|
||||
${function:one} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "OneDrive") }
|
||||
|
||||
Invoke-Expression (& { (zoxide init powershell | Out-String) })
|
||||
|
||||
Invoke-Expression (& { (zoxide init powershell | Out-String) })
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
# $DOTFILES/tools\powershell\Prompt.ps1
|
||||
# Date: 2024-12-01
|
||||
# Author: contact@js0ny.net
|
||||
# Use starship to set prompt
|
||||
$ENV:STARSHIP_CONFIG = "$DOTFILES/.config/starship/starship_pwsh.toml"
|
||||
$ENV:STARSHIP_CONFIG = Join-Path $DOTFILES "tools" "starship" "starship_pwsh.toml"
|
||||
|
||||
Invoke-Expression (&starship init powershell)
|
||||
# Invoke-Expression (&starship init powershell)
|
||||
|
||||
# Below is the backup of original prompt function
|
||||
# $promptTime = $true
|
||||
|
|
@ -16,7 +19,7 @@ Invoke-Expression (&starship init powershell)
|
|||
# }
|
||||
# # UserInfo
|
||||
# $prompt += " $Env:Username @ $Env:Userdomain"
|
||||
# # Directory
|
||||
# # Directory
|
||||
# $promptCurrentDirectory = $(PWD).Path
|
||||
# $promptCurrentDirectory = $promptCurrentDirectory.Replace("$HOME", "~")
|
||||
# $prompt += "`e[0m in `e[33m$promptCurrentDirectory "
|
||||
|
|
@ -81,7 +84,7 @@ Invoke-Expression (&starship init powershell)
|
|||
# # if ( $global:promptWeather ) {
|
||||
# # $prompt += $(Write-WeatherCurrent -City "Edinburgh" -Country "UK" -Unit "metric" -Inline -Apikey $Env:WEATHER_API_KEY)
|
||||
# # }
|
||||
# # Error on last command
|
||||
# # Error on last command
|
||||
# ## TODO: Seems does not work
|
||||
# if ($?) {
|
||||
# $prompt += "`n`e[32m PS > `e[0m"
|
||||
|
|
@ -89,4 +92,4 @@ Invoke-Expression (&starship init powershell)
|
|||
# $prompt += "`n`e[31m PS > `e[0m"
|
||||
# }
|
||||
# return $prompt
|
||||
# }
|
||||
# }
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
function CsvToMarkdown {
|
||||
param( [string]$csv)
|
||||
$counter = 0
|
||||
$column = $csv.Split("`n")[0].Split(",").Length
|
||||
$aHeader = " --- |"
|
||||
$header = "|" + $aHeader * $column
|
||||
$csv.replace(",", " | ").Split("`n") | ForEach-Object {
|
||||
if ($counter -eq 0) {
|
||||
Write-Output "| $_ |"
|
||||
$counter++
|
||||
Write-Output $header
|
||||
}
|
||||
else {
|
||||
Write-Output "| $_ |"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue