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", "gitconfig": "git",
"nvim/init.lua": "vim", "nvim/init.lua": "vim",
"markdownlint.json": "markdownlint", "markdownlint.json": "markdownlint",
".wslconfig": "settings", "wslconfig": "settings",
"skhdrc": "console" "skhdrc": "console"
}, },
"material-icon-theme.folders.associations": { "material-icon-theme.folders.associations": {

View file

@ -1,4 +1,8 @@
#! /bin/bash #! /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 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 # Not support XDG_CONFIG_HOME but same directory
mkdir -p ~/.config/zellij ~/.config/yazi ~/.config/glow 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 ### ### Load Configs ###
$DOTFILES = "$HOME\.dotfiles" $DOTFILES = Join-Path $HOME ".dotfiles"
Get-ChildItem -Path $DOTFILES\powershell -Filter *.ps1 | ForEach-Object {. $_} Get-ChildItem -Path $(Join-Path $DOTFILES "tools" "powershell") -Filter *.ps1 | ForEach-Object {. $_}
Get-ChildItem -Path $DOTFILES\powershell_private -Filter *.ps1 | ForEach-Object {. $_}
### Aliases ### ### 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 # # Toggle Theme #
function Set-SystemTheme { # TODO: Change to `bat` script implementation
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" # function Set-SystemTheme {
$currentMode = Get-ItemProperty -Path $regPath -Name "AppsUseLightTheme" # $regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"
if ($currentMode.AppsUseLightTheme -eq 1) { # $currentMode = Get-ItemProperty -Path $regPath -Name "AppsUseLightTheme"
Set-ItemProperty -Path $regPath -Name "AppsUseLightTheme" -Value 0 # if ($currentMode.AppsUseLightTheme -eq 1) {
Write-Host "已切换到深色模式" # Set-ItemProperty -Path $regPath -Name "AppsUseLightTheme" -Value 0
} # Write-Host "已切换到深色模式"
else { # }
Set-ItemProperty -Path $regPath -Name "AppsUseLightTheme" -Value 1 # else {
Write-Host "已切换到浅色模式" # Set-ItemProperty -Path $regPath -Name "AppsUseLightTheme" -Value 1
} # Write-Host "已切换到浅色模式"
} # }
Set-Alias "dark-mode" "Set-SystemTheme" # Consistent with macOS (`dark-mode`) # }
# Set-Alias "dark-mode" "Set-SystemTheme" # Consistent with macOS (`dark-mode`)
# Miscs # # Miscs #
@ -98,13 +59,16 @@ If (Test-Path "$HOME\miniconda3\Scripts\conda.exe") {
#Remove-Variable __lastStartup #Remove-Variable __lastStartup
#Remove-Variable _currentDate #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 # Set default applications
$Env:PAGER = "less" $Env:PAGER = "less"
$Env:EDITOR = "code --wait" $Env:EDITOR = "code --wait"
$Env:VISUAL = "code --wait" $Env:VISUAL = "code --wait"
$Env:FILE_MANAGER = "dopus.exe" $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 特定配置 # Sourced by user's zshrc if is WSL 在用户的 zshrc 中被引用WSL 特定配置
# Entry point in $DOTFILES/tools/zsh/common.zshrc (入口点) # Entry point in $DOTFILES/tools/zsh/common.zshrc (入口点)
# TODO: Test on WSL
### Variables ### ### Variables ###
export IS_WSL=true export IS_WSL=true
export ARCHFLAGS="-arch x86_64" export ARCHFLAGS="-arch x86_64"
source $DOTFILES/wsl/winterop.zsh source $DOTFILES/platforms/wsl/winterop.zsh
### Misc ### ### Misc ###

View file

@ -1,13 +1,16 @@
# $DOTFILES/tools\powershell\Aliases.ps1
# Date: 2024-12-01
# Author: contact@js0ny.net
# Aliases for PowerShell
### VARIABLES ### ### VARIABLES ###
$EDITOR = "code" $EDITOR = "code"
# Shell Equivalents # # Shell Equivalents #
Set-Alias "touch" "New-Item" 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 # # Shell Configurations #
${function:shcfg} = { code $PROFILE }
Set-Alias "pwshcfg" "shcfg"
${function:reload} = { . $PROFILE }
${function:pulldots} = { Set-Location -Path $DOTFILES && git pull } ${function:pulldots} = { Set-Location -Path $DOTFILES && git pull }
# Editors # # Editors #
@ -16,31 +19,13 @@ Set-Alias "c" "code"
Set-Alias "gvi" "neovide" Set-Alias "gvi" "neovide"
# File Creation # # 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 tc { param ( [string] $filename) New-Item $filename && code $filename }
function tv { param ( [string] $filename) New-Item $filename && nvim $filename } function tv { param ( [string] $filename) New-Item $filename && nvim $filename }
function cdls { param( [string] $dirname) Set-Location $dirname && Get-ChildItem } function cdls { param( [string] $dirname) Set-Location $dirname && Get-ChildItem }
### Dev ### ### Dev ###
# .NET #
${function:csi} = { dotnet repl --default-kernel csharp}
${function:fsi} = { dotnet repl --default-kernel fsharp}
# Python & Conda # # Python & Conda #
Set-Alias "py" "python" Set-Alias "py" "python"
Set-Alias "ipy" "ipython" 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 ~ } cd is better
${function:...} = { Set-Location -Path ..\.. } ${function:...} = { Set-Location -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) }
${function:....} = { Set-Location -Path ..\..\.. } ${function:....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) }
${function:.....} = { Set-Location -Path ..\..\..\.. } ${function:.....} = { Set-Location -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path (Join-Path -Path .. -ChildPath ..) -ChildPath ..) -ChildPath ..) -ChildPath ..) }
${function:......} = { Set-Location -Path ..\..\..\..\.. } ${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 # Absolute navigation
${function:docs} = { Set-Location -Path ~/Documents } ${function:docs} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Documents") }
${function:down} = { Set-Location -Path ~/Downloads } ${function:down} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Downloads") }
${function:dt} = { Set-Location -Path ~/Desktop } ${function:dt} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "Desktop") }
${function:mytmp} = { Set-Location -Path ~/Temp } ${function:one} = { Set-Location -Path (Join-Path -Path $HOME -ChildPath "OneDrive") }
${function:one} = { Set-Location -Path ~/OneDrive }
${function:doku} = { Set-Location -Path ~/doku && Get-ChildItem }
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 # 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 # Below is the backup of original prompt function
# $promptTime = $true # $promptTime = $true

View file

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