From 29c17de18faf3fd130b4f09a0e24f321dcf98df0 Mon Sep 17 00:00:00 2001 From: js0ny Date: Fri, 9 Aug 2024 16:16:17 +0800 Subject: [PATCH 1/2] Sync from Windows --- .npmrc | 3 +- win/Microsoft.PowerShell_profile.ps1 | 57 ++++++++++++-------------- win/WindowsTerminal.json | 61 +++++++++++++++------------- 3 files changed, 60 insertions(+), 61 deletions(-) diff --git a/.npmrc b/.npmrc index 1cf6c9c..7549542 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1 @@ -proxy=http://127.0.0.1:7890 -https-proxy=http://127.0.0.1:7890 +registry=https://registry.npmmirror.com diff --git a/win/Microsoft.PowerShell_profile.ps1 b/win/Microsoft.PowerShell_profile.ps1 index 7dbf680..8cd0628 100644 --- a/win/Microsoft.PowerShell_profile.ps1 +++ b/win/Microsoft.PowerShell_profile.ps1 @@ -48,7 +48,13 @@ ${function:doku} = { Set-Location -Path ~\MyDocuments && Get-ChildItem } # Shell Equivalents # Set-Alias "touch" "New-Item" -Set-Alias "open" "explorer.exe" +function open { + if ($args.Count -eq 0) { + explorer.exe . + } else { + explorer.exe $args[0] + } +} # Shell Configurations # @@ -63,20 +69,20 @@ ${function:csi} = { dotnet script } # C & C++ # -Set-Alias "cl" "clang" -Set-Alias "clpp" "clang++" -Set-Alias "clang" "clang -std=c99" -Set-Alias "clang++" "clang++ -std=c++2b" +# Set-Alias "cl" "clang" +# Set-Alias "clpp" "clang++" +# ${function:clang} = { clang -std=c99 $args[0] } +# ${function:clang++} = { clang -std=c++2b $args[0] } # Python & Conda # Set-Alias "python3" "python" Set-Alias "pip3" "pip" Set-Alias "py" "python" -Set-Alias "pyact" "conda activate" -Set-Alias "pylsenv" "conda env list" -Set-Alias "pydeact" "conda deactivate" -Set-Alias "pymkenv" "conda create --name" +${function:pyact} = { conda activate $args[0] } +${function:pylsenvs} = { conda env list } +${function:pydact} = { conda deactivate } +${function:pymkenv} = { conda create --name $args[0] } # # Git # @@ -106,33 +112,23 @@ Set-Alias "gvi" "neovide" # Miscs # -Set-Alias mcd CreateAndSet-Directory ### Functions ### -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 -} +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 } ### Modules ### -$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" -if (Test-Path($ChocolateyProfile)) { Import-Module "$ChocolateyProfile" } - Import-Module -Name Microsoft.WinGet.CommandNotFound #f45873b3-b655-43a6-b217-97c00aa0db58 - Import-Module CompletionPredictor ### Misc ### +## Conda ## + #region conda initialize # !! Contents within this block are managed by 'conda init' !! If (Test-Path "$HOME\miniconda3\Scripts\conda.exe") { @@ -140,19 +136,15 @@ If (Test-Path "$HOME\miniconda3\Scripts\conda.exe") { } #endregion -### Check Start Up ### - +## Check Start Up ## $SystemlogFilePath = "$env:USERPROFILE\.PowerShellStartup.log" - # 检查日志文件是否存在 if (-not (Test-Path $SystemlogFilePath)) { New-Item -Path $SystemlogFilePath -ItemType File -Force | Out-Null } - # 读取日志文件的最后一行(即上次启动日期) $__lastStartup = Get-Content -Path $SystemlogFilePath -Tail 1 -ErrorAction SilentlyContinue $_currentDate = (Get-Date).ToString("yyyy-MM-dd") - if (-not ($__lastStartup -eq $_currentDate)) { Get-Date Update-ForexData & @@ -160,3 +152,8 @@ if (-not ($__lastStartup -eq $_currentDate)) { # 记录当前日期到日志文件 $_currentDate | Out-File -FilePath $SystemlogFilePath -Append } + +## Chocolatey ## + +$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" +if (Test-Path($ChocolateyProfile)) { Import-Module "$ChocolateyProfile" } diff --git a/win/WindowsTerminal.json b/win/WindowsTerminal.json index 564595b..6842854 100644 --- a/win/WindowsTerminal.json +++ b/win/WindowsTerminal.json @@ -3,6 +3,14 @@ "$schema": "https://aka.ms/terminal-profiles-schema", "actions": [ + { + "command": + { + "action": "copy", + "singleLine": false + }, + "keys": "ctrl+c" + }, { "command": "unbound", "keys": "alt+shift+plus" @@ -39,22 +47,6 @@ "command": "unbound", "keys": "alt+shift+left" }, - { - "command": - { - "action": "copy", - "singleLine": false - }, - "keys": "ctrl+c" - }, - { - "command": - { - "action": "moveFocus", - "direction": "up" - }, - "keys": "ctrl+k" - }, { "command": "paste", "keys": "ctrl+v" @@ -68,8 +60,12 @@ "keys": "ctrl+shift+k" }, { - "command": "find", - "keys": "ctrl+shift+f" + "command": + { + "action": "moveFocus", + "direction": "up" + }, + "keys": "ctrl+k" }, { "command": @@ -79,6 +75,10 @@ }, "keys": "ctrl+shift+h" }, + { + "command": "find", + "keys": "ctrl+shift+f" + }, { "command": { @@ -88,14 +88,6 @@ }, "keys": "alt+shift+d" }, - { - "command": - { - "action": "splitPane", - "split": "right" - }, - "keys": "alt+shift+/" - }, { "command": { @@ -104,6 +96,14 @@ }, "keys": "ctrl+j" }, + { + "command": + { + "action": "splitPane", + "split": "right" + }, + "keys": "alt+shift+/" + }, { "command": { @@ -158,7 +158,9 @@ "font": { "face": "CaskaydiaCove Nerd Font" - } + }, + "opacity": 95, + "useAcrylic": true }, "list": [ @@ -169,9 +171,10 @@ "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", "hidden": false, "name": "PowerShell", - "opacity": 100, + "opacity": 30, "scrollbarState": "hidden", - "source": "Windows.Terminal.PowershellCore" + "source": "Windows.Terminal.PowershellCore", + "useAcrylic": true }, { "guid": "{3c5d580b-1c52-55ce-89c9-57119457e5a7}", From 1a0f4a01a4f840a46c77edcb08d5045eb6ac0ce1 Mon Sep 17 00:00:00 2001 From: js0ny Date: Mon, 12 Aug 2024 16:34:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=AA=9F:=20Add=20pathlib,=20PowerShell?= =?UTF-8?q?=20Password=20Script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pathlib.json | 19 +++++++++++++ powershell/bw.ps1 | 33 +++++++++++++++++++++++ win/WindowsTerminal.json | 58 ++++++++++++++++++++-------------------- 3 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 pathlib.json create mode 100644 powershell/bw.ps1 diff --git a/pathlib.json b/pathlib.json new file mode 100644 index 0000000..d58927a --- /dev/null +++ b/pathlib.json @@ -0,0 +1,19 @@ +{ + ".bashrc": "~/.bashrc", + ".zshrc": "~/.zshrc", + "nvim/": "~/.config/nvim/", + ".condarc": "~/.condarc", + ".gitconfig": "~/.gitconfig", + ".ideavimrc": "~/.ideavimrc", + "pip.conf": "~/.config/pip/pip.conf", + ".npmrc": "~/.npmrc", + "Microsoft.PowerShell_profile.ps1": { + "Mac": "~/.config/powershell/Microsoft.PowerShell_profile.ps1", + "Windows": "~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1" + }, + ".wslconfig": "~/.wslconfig", + "neovide.toml": { + "Mac": "~/.config/neovide/neovide.toml", + "Windows": "~/AppData/Local/neovide/neovide.toml" + } +} \ No newline at end of file diff --git a/powershell/bw.ps1 b/powershell/bw.ps1 new file mode 100644 index 0000000..cde2fc4 --- /dev/null +++ b/powershell/bw.ps1 @@ -0,0 +1,33 @@ +function Get-Password { + param ( + [Parameter(Mandatory = $true)] + [string]$Name, + [Boolean]$Hidden = $true + ) + $result = (bw list items --search $Name | ConvertFrom-Json).login | Select-Object -Property username, password + if ($result.Length -eq 0) { + Write-Host -ForegroundColor Red "No password found" + return + } + elseif ($result.Length -gt 1) { + Write-Host -ForegroundColor Red "More than one password found, please specify" + $counter = 0 + foreach ($username in $result.username) { + Write-Host "["$counter "]" $username + $counter++ + } + $selector = Read-Host -MaskInput "Select the username" + if ($result[$selector] -eq "") { + Write-Host -ForegroundColor Red "Invalid selection" + return + } + $result = $result[$selector] + } + if ($Hidden) { + Write-Host -ForegroundColor Green "Password copied to clipboard" + Set-Clipboard -Value $result.password + } else { + Write-Host $result + } + return $result +} \ No newline at end of file diff --git a/win/WindowsTerminal.json b/win/WindowsTerminal.json index 6842854..05345f4 100644 --- a/win/WindowsTerminal.json +++ b/win/WindowsTerminal.json @@ -3,14 +3,6 @@ "$schema": "https://aka.ms/terminal-profiles-schema", "actions": [ - { - "command": - { - "action": "copy", - "singleLine": false - }, - "keys": "ctrl+c" - }, { "command": "unbound", "keys": "alt+shift+plus" @@ -47,6 +39,22 @@ "command": "unbound", "keys": "alt+shift+left" }, + { + "command": + { + "action": "copy", + "singleLine": false + }, + "keys": "ctrl+c" + }, + { + "command": + { + "action": "moveFocus", + "direction": "up" + }, + "keys": "ctrl+k" + }, { "command": "paste", "keys": "ctrl+v" @@ -60,12 +68,8 @@ "keys": "ctrl+shift+k" }, { - "command": - { - "action": "moveFocus", - "direction": "up" - }, - "keys": "ctrl+k" + "command": "find", + "keys": "ctrl+shift+f" }, { "command": @@ -75,10 +79,6 @@ }, "keys": "ctrl+shift+h" }, - { - "command": "find", - "keys": "ctrl+shift+f" - }, { "command": { @@ -88,14 +88,6 @@ }, "keys": "alt+shift+d" }, - { - "command": - { - "action": "moveFocus", - "direction": "down" - }, - "keys": "ctrl+j" - }, { "command": { @@ -104,6 +96,14 @@ }, "keys": "alt+shift+/" }, + { + "command": + { + "action": "moveFocus", + "direction": "down" + }, + "keys": "ctrl+j" + }, { "command": { @@ -159,8 +159,8 @@ { "face": "CaskaydiaCove Nerd Font" }, - "opacity": 95, - "useAcrylic": true + "opacity": 100, + "useAcrylic": false }, "list": [ @@ -171,7 +171,7 @@ "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", "hidden": false, "name": "PowerShell", - "opacity": 30, + "opacity": 100, "scrollbarState": "hidden", "source": "Windows.Terminal.PowershellCore", "useAcrylic": true