Handle conflicts from macOS and Windows

This commit is contained in:
js0ny 2024-12-01 07:08:50 +00:00
commit fab8acc614
14 changed files with 151 additions and 142 deletions

View file

@ -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 }
}

View file

@ -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 }
}
}

View 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"

View file

@ -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) })

View file

@ -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
# }
# }

View file

@ -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 "| $_ |"
}
}
}

View file

@ -1,5 +1,5 @@
# $DOTFILES/tools/zsh/mod/navi.zsh
# Date: 2024-11-30
# Date: 2024-12-01
# Author: contact@js0ny.net
# Sourced by user's zshrc 在用户的 zshrc 中被引用
@ -19,13 +19,13 @@ eval "$(zoxide init zsh)"
# Absolute navigation #
alias dotfiles="cd $DOTFILES && ls"
# TODO: Test on WSL
if [ "$IS_WSL" = true ]; then # IS_WSL is defined in $DOTFILES/platforms/wsl/zshrc
alias dt="cd /mnt/c/Users/$(whoami)/Desktop && ls"
alias doku="cd /mnt/c/Users/$(whoami)/Documents && ls"
alias down="cd /mnt/c/Users/$(whoami)/Downloads && ls"
winuser=$(whoami.exe | cut -d'\' -f2 | tr -d '\r')
alias dt="cd /mnt/c/Users/$winuser/Desktop && ls"
alias doku="cd /mnt/c/Users/$winuser/Documents && ls"
alias down="cd /mnt/c/Users/$winuser/Downloads && ls"
alias src="cd /mnt/d/Source"
alias one="cd /mnt/c/Users/$(whoami)/OneDrive"
alias one="cd /mnt/c/Users/$winuser/OneDrive"
alias gdrive="cd /mnt/g"
else
alias dt="cd $HOME/Desktop && ls"