From 8ad1c2b032c6a89941ee8a21491d4f3776742cf5 Mon Sep 17 00:00:00 2001 From: qwjyh Date: Tue, 20 Sep 2022 02:04:25 +0900 Subject: [PATCH] add pwsh --- bin/install.ps1 | 5 +-- dotfiles/pwsh/powershell_profile.ps1 | 51 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 dotfiles/pwsh/powershell_profile.ps1 diff --git a/bin/install.ps1 b/bin/install.ps1 index bbd0bfb..8b52697 100644 --- a/bin/install.ps1 +++ b/bin/install.ps1 @@ -30,5 +30,6 @@ if (!( # make symbolic links # neovim -$neovim_directory -New-Item -ItemType SymbolicLink -Path ~\AppData\Local\nvim\init.vim -Target (Resolve-Path .\dotfiles\neovim\init.vim) -Force \ No newline at end of file +New-Item -ItemType SymbolicLink -Path ~\AppData\Local\nvim\init.vim -Target (Resolve-Path .\dotfiles\neovim\init.vim) -Force +# pwsh +New-Item -ItemType SymbolicLink -Path $PROFILE -Target (Resolve-Path .\dotfiles\pwsh\powershell_profile.ps1) -Force diff --git a/dotfiles/pwsh/powershell_profile.ps1 b/dotfiles/pwsh/powershell_profile.ps1 new file mode 100644 index 0000000..fb8f136 --- /dev/null +++ b/dotfiles/pwsh/powershell_profile.ps1 @@ -0,0 +1,51 @@ +# auto completion +Import-Module PSReadLine +Set-PSReadLineOption -PredictionSource History +Set-PSReadlineOption -HistoryNoDuplicates +Set-PSReadLineKeyHandler -Chord "Ctrl+f" -Function ForwardWord # like fish +Set-PSReadLineKeyHandler -Chord "Tab" MenuComplete +Set-PSReadLineKeyHandler -Chord "Ctrl+d" DeleteCharOrExit + +function ~ { cd ~ } +function .. { cd .. } +function epl {explorer.exe .} +Set-Alias touch New-Item + + +# starship +# change window name +function Invoke-Starship-PreCommand { + $ParentFolder = Split-Path $PWD -Leaf + $host.ui.Write("`e]0; $ParentFolder `a") +} +Invoke-Expression (&starship init powershell) +$ENV:STARSHIP_CONFIG = "$HOME\.config\starship.toml" + +# for chezmoi +$Editor = "C:\Users\Owner\AppData\Local\Programs\Microsoft VS Code\Code.exe" + +# oh my posh +# oh-my-posh --init --shell pwsh --config ~/AppData/Local/Programs/oh-my-posh/themes/capr4n.omp.json | Invoke-Expression + +# enable ssh-agent +#sudo Set-Service -Name ssh-agent -StartupType Manual | Start-Service ssh-agent + +# chezmoi completion +$script = "$HOME\.config\powershell\chezmoi_completion.ps1" +if (Test-Path $script) { + . $script +} + +# git completion +Import-Module posh-git + +# winget completion(source:https://docs.microsoft.com/en-us/windows/package-manager/winget/tab-completion) +Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + [Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new() + $Local:word = $wordToComplete.Replace('"', '""') + $Local:ast = $commandAst.ToString().Replace('"', '""') + winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } +} \ No newline at end of file