This commit is contained in:
js0ny 2024-08-04 13:26:09 +08:00
parent b6aeb26915
commit f04850314f
5 changed files with 135 additions and 37 deletions

View file

@ -122,6 +122,8 @@ gvi() {
### Misc ### ### Misc ###
# Conda #
# >>> conda initialize >>> # >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !! # !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('$HOME/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)" __conda_setup="$('$HOME/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
@ -136,3 +138,14 @@ else
fi fi
unset __conda_setup unset __conda_setup
# <<< conda initialize <<< # <<< 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

28
powershell/forex.ps1 Normal file
View file

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

View file

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

View file

@ -1,8 +1,11 @@
### Variables ### ### Variables ###
$EDITOR = "code"
$DOTFILES = "$HOME\Documents\.dotfiles" $DOTFILES = "$HOME\Documents\.dotfiles"
### Load Configs ###
Get-ChildItem -Path $DOTFILES\powershell -Filter *.ps1 | ForEach-Object {. $_}
### PSReadLine ### ### PSReadLine ###
Set-PSReadLineOption -EditMode vi # Vi Keybindings Set-PSReadLineOption -EditMode vi # Vi Keybindings
@ -12,7 +15,14 @@ Set-PSReadLineOption -ContinuationPrompt "`e[36m CR > " # Continuation Prompt
### Keybindings ### ### 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 ### ### Navigator ###
@ -42,8 +52,8 @@ Set-Alias "open" "explorer.exe"
# Shell Configurations # # Shell Configurations #
${function:shcfg} = { $EDITOR $PROFILE } ${function:shcfg} = { code $PROFILE }
${function:reload} = { Invoke-Expression $PROFILE } ${function:reload} = { . $PROFILE }
${function:pulldots} = { Set-Location -Path $DOTFILES && git pull } ${function:pulldots} = { Set-Location -Path $DOTFILES && git pull }
Set-Alias "pwshcfg" "shcfg" Set-Alias "pwshcfg" "shcfg"
@ -54,7 +64,7 @@ ${function:csi} = { dotnet script }
# C & C++ # # C & C++ #
Set-Alias "cl" "clang" Set-Alias "cl" "clang"
Set-Alias "clp" "clang++" Set-Alias "clpp" "clang++"
Set-Alias "clang" "clang -std=c99" Set-Alias "clang" "clang -std=c99"
Set-Alias "clang++" "clang++ -std=c++2b" Set-Alias "clang++" "clang++ -std=c++2b"
@ -83,6 +93,11 @@ Set-Alias "pymkenv" "conda create --name"
# Set-Alias "gps" "git push" # Set-Alias "gps" "git push"
# WSL #
${function:wsl1} = {wsl.exe --distribution Debian}
${function:wsl2} = {wsl.exe --distribution Ubuntu-22.04}
# Editors # # Editors #
Set-Alias "v" "nvim" Set-Alias "v" "nvim"
@ -124,3 +139,24 @@ If (Test-Path "$HOME\miniconda3\Scripts\conda.exe") {
(& "$HOME\miniconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Where-Object{$_} | Invoke-Expression (& "$HOME\miniconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Where-Object{$_} | Invoke-Expression
} }
#endregion #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
}

View file

@ -55,6 +55,10 @@
}, },
"keys": "ctrl+k" "keys": "ctrl+k"
}, },
{
"command": "paste",
"keys": "ctrl+v"
},
{ {
"command": "command":
{ {
@ -64,8 +68,16 @@
"keys": "ctrl+shift+k" "keys": "ctrl+shift+k"
}, },
{ {
"command": "paste", "command": "find",
"keys": "ctrl+v" "keys": "ctrl+shift+f"
},
{
"command":
{
"action": "resizePane",
"direction": "left"
},
"keys": "ctrl+shift+h"
}, },
{ {
"command": "command":
@ -79,14 +91,10 @@
{ {
"command": "command":
{ {
"action": "resizePane", "action": "splitPane",
"direction": "left" "split": "right"
}, },
"keys": "ctrl+shift+h" "keys": "alt+shift+/"
},
{
"command": "find",
"keys": "ctrl+shift+f"
}, },
{ {
"command": "command":
@ -96,14 +104,6 @@
}, },
"keys": "ctrl+j" "keys": "ctrl+j"
}, },
{
"command":
{
"action": "splitPane",
"split": "right"
},
"keys": "alt+shift+/"
},
{ {
"command": "command":
{ {
@ -173,13 +173,6 @@
"scrollbarState": "hidden", "scrollbarState": "hidden",
"source": "Windows.Terminal.PowershellCore" "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}", "guid": "{3c5d580b-1c52-55ce-89c9-57119457e5a7}",
"hidden": false, "hidden": false,
@ -225,6 +218,18 @@
"hidden": false, "hidden": false,
"name": "Debian", "name": "Debian",
"source": "Windows.Terminal.Wsl" "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", "white": "#D3D7CF",
"yellow": "#C4A000" "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", "background": "#300A24",
"black": "#171421", "black": "#171421",