From f04850314f957d963aafdbf422b5ec064127e5f8 Mon Sep 17 00:00:00 2001 From: js0ny Date: Sun, 4 Aug 2024 13:26:09 +0800 Subject: [PATCH] Forex --- linux/.zshrc | 13 +++++ powershell/forex.ps1 | 28 ++++++++++ set_mirror.ps1 | 7 --- win/Microsoft.PowerShell_profile.ps1 | 48 +++++++++++++++--- win/WindowsTerminal.json | 76 +++++++++++++++++++--------- 5 files changed, 135 insertions(+), 37 deletions(-) create mode 100644 powershell/forex.ps1 delete mode 100644 set_mirror.ps1 diff --git a/linux/.zshrc b/linux/.zshrc index 32c6bcf..4babe0c 100644 --- a/linux/.zshrc +++ b/linux/.zshrc @@ -122,6 +122,8 @@ gvi() { ### Misc ### +# Conda # + # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('$HOME/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)" @@ -136,3 +138,14 @@ else fi unset __conda_setup # <<< conda initialize <<< + +# Ubuntu Command Not Found # + +if [[ -x /usr/lib/command-not-found ]] ; then + if (( ! ${+functions[command_not_found_handler]} )) ; then + function command_not_found_handler { + [[ -x /usr/lib/command-not-found ]] || return 1 + /usr/lib/command-not-found -- ${1+"$1"} && : + } + fi +fi \ No newline at end of file diff --git a/powershell/forex.ps1 b/powershell/forex.ps1 new file mode 100644 index 0000000..52664d4 --- /dev/null +++ b/powershell/forex.ps1 @@ -0,0 +1,28 @@ +$_userForexToday = (Get-Content ~/.forex | ConvertFrom-Json).conversion_rates + +function Update-ForexData { + ((Invoke-WebRequest "$_userForexUrl").Content | ConvertFrom-Json).conversion_rates > ~/.forex +} +function Get-ExchangeRate { + param ( + [string] $From, + [string] $To = "CNY", + [double] $Value = 1 + ) + if (-not $from) { + Get-ForexOverview + return + } + Write-Host $From : $To " " -NoNewline -ForegroundColor DarkGreen + ($Value * ($_userForexToday.$To / $_userForexToday.$From)) | Write-Host -ForegroundColor DarkBlue +} + +function Get-ForexOverview { + Get-ExchangeRate -From GBP -To CNY -Value 1 + Get-ExchangeRate -From USD -To CNY -Value 1 + Get-ExchangeRate -From HKD -To CNY -Value 1 + Get-ExchangeRate -From EUR -To CNY -Value 1 + Get-ExchangeRate -From CNY -To JPY -Value 1 +} + +Set-Alias "forex" "Get-ExchangeRate" \ No newline at end of file diff --git a/set_mirror.ps1 b/set_mirror.ps1 deleted file mode 100644 index c7d6573..0000000 --- a/set_mirror.ps1 +++ /dev/null @@ -1,7 +0,0 @@ -# pip -Set-Alias pip pip3 -Set-Alias python python3 -python -m pip install --upgrade pip -pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple -# npm -npm config set registry https://registry.npmmirror.com \ No newline at end of file diff --git a/win/Microsoft.PowerShell_profile.ps1 b/win/Microsoft.PowerShell_profile.ps1 index 6796eee..7dbf680 100644 --- a/win/Microsoft.PowerShell_profile.ps1 +++ b/win/Microsoft.PowerShell_profile.ps1 @@ -1,8 +1,11 @@ ### Variables ### -$EDITOR = "code" $DOTFILES = "$HOME\Documents\.dotfiles" +### Load Configs ### + +Get-ChildItem -Path $DOTFILES\powershell -Filter *.ps1 | ForEach-Object {. $_} + ### PSReadLine ### Set-PSReadLineOption -EditMode vi # Vi Keybindings @@ -12,7 +15,14 @@ Set-PSReadLineOption -ContinuationPrompt "`e[36m CR > " # Continuation Prompt ### Keybindings ### -Set-PSReadLineKeyHandler -Chord "Ctrl+f" -Function ForwardWord +Set-PSReadLineKeyHandler -Chord "Ctrl+Shift+f" -Function ForwardWord +Set-PSReadLineKeyHandler -Chord "Ctrl+Shift+b" -Function BackwardWord +Set-PSReadLineKeyHandler -Chord "Alt+f" -Function ForwardChar +Set-PSReadLineKeyHandler -Chord "Ctrl+b" -Function BackwardChar +Set-PSReadLineKeyHandler -Chord "Ctrl+p" -Function HistorySearchBackward +Set-PSReadLineKeyHandler -Chord "Ctrl+n" -Function HistorySearchForward +Set-PSReadLineKeyHandler -Chord "Ctrl+a" -Function BeginningOfLine +Set-PSReadLineKeyHandler -Chord "Ctrl+e" -Function EndOfLine ### Navigator ### @@ -42,8 +52,8 @@ Set-Alias "open" "explorer.exe" # Shell Configurations # -${function:shcfg} = { $EDITOR $PROFILE } -${function:reload} = { Invoke-Expression $PROFILE } +${function:shcfg} = { code $PROFILE } +${function:reload} = { . $PROFILE } ${function:pulldots} = { Set-Location -Path $DOTFILES && git pull } Set-Alias "pwshcfg" "shcfg" @@ -54,7 +64,7 @@ ${function:csi} = { dotnet script } # C & C++ # Set-Alias "cl" "clang" -Set-Alias "clp" "clang++" +Set-Alias "clpp" "clang++" Set-Alias "clang" "clang -std=c99" Set-Alias "clang++" "clang++ -std=c++2b" @@ -83,6 +93,11 @@ Set-Alias "pymkenv" "conda create --name" # Set-Alias "gps" "git push" +# WSL # + +${function:wsl1} = {wsl.exe --distribution Debian} +${function:wsl2} = {wsl.exe --distribution Ubuntu-22.04} + # Editors # Set-Alias "v" "nvim" @@ -123,4 +138,25 @@ Import-Module CompletionPredictor If (Test-Path "$HOME\miniconda3\Scripts\conda.exe") { (& "$HOME\miniconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Where-Object{$_} | Invoke-Expression } -#endregion \ No newline at end of file +#endregion + +### 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 & + Write-Host "今天是第一次启动 PowerShell。" + # 记录当前日期到日志文件 + $_currentDate | Out-File -FilePath $SystemlogFilePath -Append +} diff --git a/win/WindowsTerminal.json b/win/WindowsTerminal.json index bd1d755..564595b 100644 --- a/win/WindowsTerminal.json +++ b/win/WindowsTerminal.json @@ -55,6 +55,10 @@ }, "keys": "ctrl+k" }, + { + "command": "paste", + "keys": "ctrl+v" + }, { "command": { @@ -64,8 +68,16 @@ "keys": "ctrl+shift+k" }, { - "command": "paste", - "keys": "ctrl+v" + "command": "find", + "keys": "ctrl+shift+f" + }, + { + "command": + { + "action": "resizePane", + "direction": "left" + }, + "keys": "ctrl+shift+h" }, { "command": @@ -79,14 +91,10 @@ { "command": { - "action": "resizePane", - "direction": "left" + "action": "splitPane", + "split": "right" }, - "keys": "ctrl+shift+h" - }, - { - "command": "find", - "keys": "ctrl+shift+f" + "keys": "alt+shift+/" }, { "command": @@ -96,14 +104,6 @@ }, "keys": "ctrl+j" }, - { - "command": - { - "action": "splitPane", - "split": "right" - }, - "keys": "alt+shift+/" - }, { "command": { @@ -173,13 +173,6 @@ "scrollbarState": "hidden", "source": "Windows.Terminal.PowershellCore" }, - { - "colorScheme": "One Half Dark", - "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}", - "hidden": false, - "name": "Ubuntu", - "source": "Windows.Terminal.Wsl" - }, { "guid": "{3c5d580b-1c52-55ce-89c9-57119457e5a7}", "hidden": false, @@ -225,6 +218,18 @@ "hidden": false, "name": "Debian", "source": "Windows.Terminal.Wsl" + }, + { + "guid": "{17bf3de4-5353-5709-bcf9-835bd952a95e}", + "hidden": true, + "name": "Ubuntu-22.04", + "source": "Windows.Terminal.Wsl" + }, + { + "guid": "{e5a83caa-4c73-52b3-ae6b-bc438d721ef9}", + "hidden": false, + "name": "Ubuntu 22.04.3 LTS", + "source": "CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc" } ] }, @@ -414,6 +419,29 @@ "white": "#D3D7CF", "yellow": "#C4A000" }, + { + "background": "#300A24", + "black": "#171421", + "blue": "#0037DA", + "brightBlack": "#767676", + "brightBlue": "#08458F", + "brightCyan": "#2C9FB3", + "brightGreen": "#26A269", + "brightPurple": "#A347BA", + "brightRed": "#C01C28", + "brightWhite": "#F2F2F2", + "brightYellow": "#A2734C", + "cursorColor": "#FFFFFF", + "cyan": "#3A96DD", + "foreground": "#FFFFFF", + "green": "#26A269", + "name": "Ubuntu-22.04-ColorScheme", + "purple": "#881798", + "red": "#C21A23", + "selectionBackground": "#FFFFFF", + "white": "#CCCCCC", + "yellow": "#A2734C" + }, { "background": "#300A24", "black": "#171421",