Sync from Windows

This commit is contained in:
js0ny 2024-11-20 14:27:00 +00:00
parent 8a7397c426
commit d5f8d807b9
80 changed files with 6079 additions and 5097 deletions

View file

@ -1,37 +1,37 @@
### VARIABLES ###
$EDITOR = "code"
# 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"
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] }
### VARIABLES ###
$EDITOR = "code"
# 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"
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 }

View file

@ -0,0 +1,9 @@
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 }
}
}

View file

@ -1,7 +1,7 @@
# Use XDG Base Directory Specification and its similar structure for Windows
# wget
${function:wget} = {wget --hsts-file $XDG_CACHE_HOME/wget-hsts $args}
# yarn v1
# Use XDG Base Directory Specification and its similar structure for Windows
# wget
${function:wget} = {wget --hsts-file $XDG_CACHE_HOME/wget-hsts $args}
# yarn v1
${function:yarn} = {yarn --use-yarnrc $XDG_CONFIG_HOME/yarn/config.yaml $args}

View file

@ -1,25 +1,25 @@
# aka PSReadLine
# PSReadLineOptions
Set-PSReadLineOption -EditMode Vi # Vi Keybindings
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
# Set-PSReadLineOption -ContinuationPrompt "`e[36m CR > " # Use Starship instead
# PSReadLineKeyHandlers
## Colemak hnei
Set-PSReadLineKeyHandler -Chord "n" -Function NextHistory -ViMode Command
Set-PSReadLineKeyHandler -Chord "e" -Function PreviousHistory -ViMode Command
Set-PSReadLineKeyHandler -Chord "i" -Function ViForwardChar -ViMode Command
## Similar position to [i] in QWERTY
Set-PSReadLineKeyHandler -Chord "l" -Function ViInsertMode -ViMode Command
Set-PSReadlineKeyHandler -Chord "L" -Function ViInsertAtBegining -ViMode Command
## Ne{[k]s}t
Set-PSReadLineKeyHandler -Chord "k" -Function RepeatSearch -ViMode Command
Set-PSReadLineKeyHandler -Chord "K" -Function RepeatSearchBackward -ViMode Command
## [j]ump
Set-PSReadLineKeyHandler -Chord "j" -Function NextWordEnd -ViMode Command
Set-PSReadLineKeyHandler -Chord "J" -Function ViEndOfGlob -ViMode Command
## Use N to Join
Set-PSReadLineKeyHandler -Chord "N" -Function ViJoinLines -ViMode Command
Set-PSReadLineKeyHandler -Chord "Control+Oem4" -Function ViCommandMode -ViMode Insert # ^[ to Escape
Set-PSReadLineKeyHandler -Chord "Ctrl+a" -Function BeginningOfLine
# aka PSReadLine
# PSReadLineOptions
Set-PSReadLineOption -EditMode Vi # Vi Keybindings
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
# Set-PSReadLineOption -ContinuationPrompt "`e[36m CR > " # Use Starship instead
# PSReadLineKeyHandlers
## Colemak hnei
Set-PSReadLineKeyHandler -Chord "n" -Function NextHistory -ViMode Command
Set-PSReadLineKeyHandler -Chord "e" -Function PreviousHistory -ViMode Command
Set-PSReadLineKeyHandler -Chord "i" -Function ViForwardChar -ViMode Command
## Similar position to [i] in QWERTY
Set-PSReadLineKeyHandler -Chord "l" -Function ViInsertMode -ViMode Command
Set-PSReadlineKeyHandler -Chord "L" -Function ViInsertAtBegining -ViMode Command
## Ne{[k]s}t
Set-PSReadLineKeyHandler -Chord "k" -Function RepeatSearch -ViMode Command
Set-PSReadLineKeyHandler -Chord "K" -Function RepeatSearchBackward -ViMode Command
## [j]ump
Set-PSReadLineKeyHandler -Chord "j" -Function NextWordEnd -ViMode Command
Set-PSReadLineKeyHandler -Chord "J" -Function ViEndOfGlob -ViMode Command
## Use N to Join
Set-PSReadLineKeyHandler -Chord "N" -Function ViJoinLines -ViMode Command
Set-PSReadLineKeyHandler -Chord "Control+Oem4" -Function ViCommandMode -ViMode Insert # ^[ to Escape
Set-PSReadLineKeyHandler -Chord "Ctrl+a" -Function BeginningOfLine
Set-PSReadLineKeyHandler -Chord "Ctrl+e" -Function EndOfLine

View file

@ -1,9 +1,9 @@
Import-Module -Name Terminal-Icons
Import-Module -Name CompletionPredictor
if ($IsWindows) {
# Chocolatey
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) { Import-Module "$ChocolateyProfile" }
# WinGet
Import-Module -Name Microsoft.WinGet.CommandNotFound #f45873b3-b655-43a6-b217-97c00aa0db58
Import-Module -Name Terminal-Icons
Import-Module -Name CompletionPredictor
if ($IsWindows) {
# Chocolatey
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) { Import-Module "$ChocolateyProfile" }
# WinGet
Import-Module -Name Microsoft.WinGet.CommandNotFound #f45873b3-b655-43a6-b217-97c00aa0db58
}

View file

@ -1,15 +1,15 @@
# ${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 }
# ${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 }
Invoke-Expression (& { (zoxide init powershell | Out-String) })

View file

@ -1,92 +1,92 @@
# Use starship to set prompt
$ENV:STARSHIP_CONFIG = "$DOTFILES/.config/starship/starship_pwsh.toml"
Invoke-Expression (&starship init powershell)
# Below is the backup of original prompt function
# $promptTime = $true
# # $promptWeather = $false
# function prompt {
# $prompt = "`e[35m"
# # Time
# if ($promptTime) {
# $promptTime = Get-Date -Format HH:mm
# $prompt += "`[$promptTime]"
# }
# # UserInfo
# $prompt += " $Env:Username @ $Env:Userdomain"
# # Directory
# $promptCurrentDirectory = $(PWD).Path
# $promptCurrentDirectory = $promptCurrentDirectory.Replace("$HOME", "~")
# $prompt += "`e[0m in `e[33m$promptCurrentDirectory "
# # Git
# if ($(git rev-parse --is-inside-work-tree 2> $null) -eq "true") {
# $prompt += "`e[32m`u{e702} $(git branch --show-current)"
# }
# # Conda
# if ( $Env:CONDA_PROMPT_MODIFIER ) {
# $promptConda = $Env:CONDA_PROMPT_MODIFIER.Replace("`(","").Replace(")","")
# $pythonVersion = $(python --version).Split(" ")[1]
# $prompt += " `e[33m`u{e73c} $promptConda $pythonVersion"
# }
# # Programming Language (by Get-ChildItem)
# ## Python
# if (Test-Path -Path "$PWD\pyproject.toml") {
# $pythonVersion = $(python --version).Split(" ")[1]
# $prompt += " `e[33m`u{e73c} $pythonVersion"
# }
# ## Node.js
# if (Test-Path -Path "$PWD\package.json") {
# $nodeVersion = $(node --version)
# $prompt += " `e[32m`u{e3a0} $nodeVersion"
# # Locked
# if (Test-Path -Path "$PWD\yarn.lock" || Test-Path -Path "$PWD\package-lock.json") {
# $prompt += "`u{f023}"
# }
# }
# ## .NET
# ### C Sharp
# if (Test-Path -Path "$PWD\*.csproj") {
# $dotnetVersion = $(dotnet --version)
# $prompt += " `e[34m`u{e648} $dotnetVersion"
# }
# ### F Sharp
# if (Test-Path -Path "$PWD\*.fsproj") {
# $dotnetVersion = $(dotnet --version)
# $prompt += " `e[35m`u{e65a} $dotnetVersion"
# }
# ## Rust
# if (Test-Path -Path "$PWD\Cargo.toml") {
# $rustVersion = $(cargo --version).Split(" ")[1]
# $prompt += " `e[31m`u{e7a8} $rustVersion"
# }
# ## Java
# if (Test-Path -Path "$PWD\pom.xml" || Test-Path -Path "$PWD\build.gradle") {
# $javaVersion = $(java --version).Split(" ")[1]
# $prompt += " `e[31m`u{e738} $javaVersion"
# }
# ## Makefile
# if (Test-Path -Path "$PWD\Makefile") {
# $prompt += " `e[32m`u{e673}"
# }
# if (Test-Path -Path "$PWD\CMakeLists.txt") {
# $prompt += " `e[32m `u{e61d}"
# }
# # Docker
# if (Test-Path -Path "$PWD\Dockerfile" || Test-Path -Path "$PWD\docker-compose.yml") {
# $prompt += " `e[33m`u{f21f}"
# }
# # Weather
# # if ( $global:promptWeather ) {
# # $prompt += $(Write-WeatherCurrent -City "Edinburgh" -Country "UK" -Unit "metric" -Inline -Apikey $Env:WEATHER_API_KEY)
# # }
# # Error on last command
# ## TODO: Seems does not work
# if ($?) {
# $prompt += "`n`e[32m PS > `e[0m"
# } else {
# $prompt += "`n`e[31m PS > `e[0m"
# }
# return $prompt
# Use starship to set prompt
$ENV:STARSHIP_CONFIG = "$DOTFILES/.config/starship/starship_pwsh.toml"
Invoke-Expression (&starship init powershell)
# Below is the backup of original prompt function
# $promptTime = $true
# # $promptWeather = $false
# function prompt {
# $prompt = "`e[35m"
# # Time
# if ($promptTime) {
# $promptTime = Get-Date -Format HH:mm
# $prompt += "`[$promptTime]"
# }
# # UserInfo
# $prompt += " $Env:Username @ $Env:Userdomain"
# # Directory
# $promptCurrentDirectory = $(PWD).Path
# $promptCurrentDirectory = $promptCurrentDirectory.Replace("$HOME", "~")
# $prompt += "`e[0m in `e[33m$promptCurrentDirectory "
# # Git
# if ($(git rev-parse --is-inside-work-tree 2> $null) -eq "true") {
# $prompt += "`e[32m`u{e702} $(git branch --show-current)"
# }
# # Conda
# if ( $Env:CONDA_PROMPT_MODIFIER ) {
# $promptConda = $Env:CONDA_PROMPT_MODIFIER.Replace("`(","").Replace(")","")
# $pythonVersion = $(python --version).Split(" ")[1]
# $prompt += " `e[33m`u{e73c} $promptConda $pythonVersion"
# }
# # Programming Language (by Get-ChildItem)
# ## Python
# if (Test-Path -Path "$PWD\pyproject.toml") {
# $pythonVersion = $(python --version).Split(" ")[1]
# $prompt += " `e[33m`u{e73c} $pythonVersion"
# }
# ## Node.js
# if (Test-Path -Path "$PWD\package.json") {
# $nodeVersion = $(node --version)
# $prompt += " `e[32m`u{e3a0} $nodeVersion"
# # Locked
# if (Test-Path -Path "$PWD\yarn.lock" || Test-Path -Path "$PWD\package-lock.json") {
# $prompt += "`u{f023}"
# }
# }
# ## .NET
# ### C Sharp
# if (Test-Path -Path "$PWD\*.csproj") {
# $dotnetVersion = $(dotnet --version)
# $prompt += " `e[34m`u{e648} $dotnetVersion"
# }
# ### F Sharp
# if (Test-Path -Path "$PWD\*.fsproj") {
# $dotnetVersion = $(dotnet --version)
# $prompt += " `e[35m`u{e65a} $dotnetVersion"
# }
# ## Rust
# if (Test-Path -Path "$PWD\Cargo.toml") {
# $rustVersion = $(cargo --version).Split(" ")[1]
# $prompt += " `e[31m`u{e7a8} $rustVersion"
# }
# ## Java
# if (Test-Path -Path "$PWD\pom.xml" || Test-Path -Path "$PWD\build.gradle") {
# $javaVersion = $(java --version).Split(" ")[1]
# $prompt += " `e[31m`u{e738} $javaVersion"
# }
# ## Makefile
# if (Test-Path -Path "$PWD\Makefile") {
# $prompt += " `e[32m`u{e673}"
# }
# if (Test-Path -Path "$PWD\CMakeLists.txt") {
# $prompt += " `e[32m `u{e61d}"
# }
# # Docker
# if (Test-Path -Path "$PWD\Dockerfile" || Test-Path -Path "$PWD\docker-compose.yml") {
# $prompt += " `e[33m`u{f21f}"
# }
# # Weather
# # if ( $global:promptWeather ) {
# # $prompt += $(Write-WeatherCurrent -City "Edinburgh" -Country "UK" -Unit "metric" -Inline -Apikey $Env:WEATHER_API_KEY)
# # }
# # Error on last command
# ## TODO: Seems does not work
# if ($?) {
# $prompt += "`n`e[32m PS > `e[0m"
# } else {
# $prompt += "`n`e[31m PS > `e[0m"
# }
# return $prompt
# }

View file

@ -1,17 +1,17 @@
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 "| $_ |"
}
}
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 "| $_ |"
}
}
}

View file

@ -1,23 +1,23 @@
# PowerShell Profile
This is the cross-platform PowerShell profile for PowerShell Core
```text
.
├── Aliases.ps1
├── Keymap.ps1 # keymaps, optimize for Vi-Mode and Colemak
├── Modules.ps1
├── Navigation.ps1
├── Prompt.ps1
├── readme.md
└── Scripts.ps1
1 directory, 7 files
```
| Keymap | Action | Mode |
| --- | --- | --- |
| `^a` | To Beginning of Line | All |
| `^e` | To End of Line | All |
| `^[` | To Normal Mode | Insert |
# PowerShell Profile
This is the cross-platform PowerShell profile for PowerShell Core
```text
.
├── Aliases.ps1
├── Keymap.ps1 # keymaps, optimize for Vi-Mode and Colemak
├── Modules.ps1
├── Navigation.ps1
├── Prompt.ps1
├── readme.md
└── Scripts.ps1
1 directory, 7 files
```
| Keymap | Action | Mode |
| --- | --- | --- |
| `^a` | To Beginning of Line | All |
| `^e` | To End of Line | All |
| `^[` | To Normal Mode | Insert |