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

@ -12,7 +12,7 @@
"gitconfig": "git",
"nvim/init.lua": "vim",
"markdownlint.json": "markdownlint",
".wslconfig": "settings",
"wslconfig": "settings",
"skhdrc": "console"
},
"material-icon-theme.folders.associations": {

View file

@ -1,4 +1,8 @@
#! /bin/bash
# $DOTFILES/bootstrap/set_symblink_unix.bash
# Date: 2024-12-01
# Author: contact@js0ny.net
# Set symbolic links for Unix-like systems
mkdir -p $XDG_CONFIG_HOME/conda $XDG_CONFIG_HOME/git $XDG_CONFIG_HOME/ideavim $XDG_CONFIG_HOME/markdownlint $XDG_CONFIG_HOME/pip $XDG_CONFIG_HOME/neovide $XDG_CONFIG_HOME/powershell $XDG_CONFIG_HOME/vscode $XDG_CONFIG_HOME/NuGet $XDG_CONFIG_HOME/vim $XDG_CONFIG_HOME/tmux $XDG_CONFIG_HOME/npm $XDG_CONFIG_HOME/readline $XDG_CONFIG_HOME/ipython
# Not support XDG_CONFIG_HOME but same directory
mkdir -p ~/.config/zellij ~/.config/yazi ~/.config/glow

View file

@ -0,0 +1,36 @@
# $DOTFILES\bootstrap\set_symlink_win.ps1
# Date: 2024-12-01
# Author: contact@js0ny.net
# Set symlinks for dotfiles on Windows
# 在 Windows 上设置 dotfiles 的符号链接
$DOTFILES = Join-Path $env:UserProfile ".dotfiles"
$BASE_COMMON = Join-Path $DOTFILES "common"
$BASE_TOOLS = Join-Path $DOTFILES "tools"
$BASE_WIN = Join-Path $DOTFILES "platforms" "win"
$linkDots = @{
"$BASE_WIN\wslconfig" = "$env:UserProfile\.wslconfig"
"$BASE_WIN\neovide.toml" = "$Env:AppData\neovide\config.toml"
"$BASE_COMMON\condarc.yaml" = "$env:XDG_CONFIG_HOME\conda\.condarc"
"$BASE_COMMON\gitconfig" = "$env:UserProfile\.gitconfig"
"$BASE_COMMON\glow.yaml" = "$env:AppData\glow\glow.yml"
"$BASE_COMMON\haskeline" = "$env:UserProfile\.haskeline"
"$BASE_COMMON\ideavimrc" = "$env:XDG_CONFIG_HOME\ideavim\ideavimrc"
"$BASE_COMMON\lesskey" = "$env:LessKeyIn"
"$BASE_COMMON\npmrc" = "$env:NPM_CONFIG_USERCONFIG"
"$BASE_COMMON\NuGet.Config" = "$env:AppData\NuGet\NuGet.Config"
"$BASE_COMMON\obsidian.vimrc" = "$env:UserProfile\Obsidian\.obsidian.vimrc"
"$BASE_COMMON\pip.conf" = "$env:AppData\pip\pip.ini"
"$BASE_COMMON\vimrc" = "$env:Vim\_vimrc"
"$BASE_TOOLS\ipython" = "$env:IPYTHONDIR"
"$BASE_TOOLS\nvim" = "$env:XDG_CONFIG_HOME\nvim"
}
# TODO: Auto create directories
foreach ($target in $linkDots.Keys) {
$path = $linkDots[$target]
New-Item -ItemType SymbolicLink -Target $target -Path $path -Force
}
New-Item -ItemType SymbolicLink -Target "$BASE_WIN\Microsoft.PowerShell_profile.ps1" -Path "$env:UserProfile\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" -Force

View file

@ -1,12 +0,0 @@
# ~/.wslconfig
# New-Item -ItemType SymbolicLink -Path ~\.wslconfig -Target ~\.dotfiles\win\.wslconfig
[wsl2]
# networkingMode=mirrored
# dnsTunneling=true
# firewall=true
# autoProxy=true
[experimental]
# requires dnsTunneling but are also OPTIONAL
bestEffortDnsParsing=true
hostAddressLoopback=true

View file

@ -1,69 +1,30 @@
# $DOTFILES/platforms\win\Microsoft.PowerShell_profile.ps1
# Date: 2024-12-01
# Author: contact@js0ny.net
# PowerShell profile for Windows
### Load Configs ###
$DOTFILES = "$HOME\.dotfiles"
Get-ChildItem -Path $DOTFILES\powershell -Filter *.ps1 | ForEach-Object {. $_}
Get-ChildItem -Path $DOTFILES\powershell_private -Filter *.ps1 | ForEach-Object {. $_}
$DOTFILES = Join-Path $HOME ".dotfiles"
Get-ChildItem -Path $(Join-Path $DOTFILES "tools" "powershell") -Filter *.ps1 | ForEach-Object {. $_}
### Aliases ###
# Shell Equivalents #
Set-Alias "grep" "Select-String"
${function:which} = { (Get-Command $args[0]).Path }
# Shell Configurations #
${function:shcfg} = { code $PROFILE }
${function:reload} = { & $PROFILE }
${function:pulldots} = { Set-Location -Path $DOTFILES && git pull }
Set-Alias "pwshcfg" "shcfg"
# C & C++ #
# Set-Alias "cl" "clang"
# Set-Alias "clpp" "clang++"
# ${function:clang} = { clang -std=c99 $args[0] }
# ${function:clang++} = { clang -std=c++2b $args[0] }
# WSL #
${function:wsl1} = {wsl.exe --distribution Arch}
${function:wsl2} = {wsl.exe --distribution Ubuntu-22.04}
# Search Software #
function Find-AppPackageListRemote {
param(
[string]$Name
)
if (-not $Name) {
Write-Host "Please provide a package name."
return
}
Write-Host "Searching for $Name..."
Write-Host "=== winget ==="
winget search $Name
Write-Host "=== choco ==="
choco search $Name
# Too slow!
# Write-Host "=== scoop ==="
# scoop search $Name
}
Set-Alias "pkgsearch" "Find-AppPackageListRemote"
function Get-AppPackageListLocal {
winget list
choco list
scoop list
}
# Toggle Theme #
function Set-SystemTheme {
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"
$currentMode = Get-ItemProperty -Path $regPath -Name "AppsUseLightTheme"
if ($currentMode.AppsUseLightTheme -eq 1) {
Set-ItemProperty -Path $regPath -Name "AppsUseLightTheme" -Value 0
Write-Host "已切换到深色模式"
}
else {
Set-ItemProperty -Path $regPath -Name "AppsUseLightTheme" -Value 1
Write-Host "已切换到浅色模式"
}
}
Set-Alias "dark-mode" "Set-SystemTheme" # Consistent with macOS (`dark-mode`)
# TODO: Change to `bat` script implementation
# function Set-SystemTheme {
# $regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"
# $currentMode = Get-ItemProperty -Path $regPath -Name "AppsUseLightTheme"
# if ($currentMode.AppsUseLightTheme -eq 1) {
# Set-ItemProperty -Path $regPath -Name "AppsUseLightTheme" -Value 0
# Write-Host "已切换到深色模式"
# }
# else {
# Set-ItemProperty -Path $regPath -Name "AppsUseLightTheme" -Value 1
# Write-Host "已切换到浅色模式"
# }
# }
# Set-Alias "dark-mode" "Set-SystemTheme" # Consistent with macOS (`dark-mode`)
# Miscs #
@ -98,13 +59,16 @@ If (Test-Path "$HOME\miniconda3\Scripts\conda.exe") {
#Remove-Variable __lastStartup
#Remove-Variable _currentDate
# Use some unix commands
${function:tree} = { wsl tree $args}
${function:ln} = { coreutils.exe ln $args}
${function:la} = { lsd.exe -la $args}
# Set default applications
$Env:PAGER = "less"
$Env:EDITOR = "code --wait"
$Env:VISUAL = "code --wait"
$Env:FILE_MANAGER = "dopus.exe"
${function:wsl2} = {wsl.exe --distribution Ubuntu}
${function:wini} = { winget install $args }
${function:winr} = { winget uninstall $args }
${function:wins} = { winget search $args }
${function:winu} = { winget upgrade $args }

19
platforms/win/wslconfig Normal file
View file

@ -0,0 +1,19 @@
# $DOTFILES\platforms\win\wslconfig
# Date: 2024-12-01
# Author: contact@js0ny.net
# Config Files (mainly for networking) for WSL2 (Windows Subsystem for Linux 2)
# 适用于 Windows 的 Linux 子系统 2 的配置文件(主要用于网络)
# Location: ~/.wslconfig
# Linking: (PowerShell)
# New-Item -ItemType SymbolicLink -Path ~\.wslconfig -Target ~\.dotfiles\platforms\win\wslconfig
[wsl2]
# networkingMode=mirrored
# dnsTunneling=true
# firewall=true
# autoProxy=true
[experimental]
# requires dnsTunneling but are also OPTIONAL
bestEffortDnsParsing=true
hostAddressLoopback=true

View file

@ -1,12 +1,13 @@
# $DOTFILES/platforms//zshrc
# $DOTFILES/platforms/wsl/zshrc
# Date: 2024-12-01
# Author: contact@js0ny.net
# Sourced by user's zshrc if is WSL 在用户的 zshrc 中被引用WSL 特定配置
# Entry point in $DOTFILES/tools/zsh/common.zshrc (入口点)
# TODO: Test on WSL
### Variables ###
export IS_WSL=true
export ARCHFLAGS="-arch x86_64"
source $DOTFILES/wsl/winterop.zsh
source $DOTFILES/platforms/wsl/winterop.zsh
### Misc ###

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,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

@ -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,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"