From 6eae769e394971e4abf478a89c36329856058763 Mon Sep 17 00:00:00 2001 From: qwjyh Date: Fri, 23 Sep 2022 03:30:00 +0900 Subject: [PATCH 1/3] pwsh: home util shortcut --- dotfiles/pwsh/powershell_profile.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dotfiles/pwsh/powershell_profile.ps1 b/dotfiles/pwsh/powershell_profile.ps1 index 46fdc5d..d918b8b 100644 --- a/dotfiles/pwsh/powershell_profile.ps1 +++ b/dotfiles/pwsh/powershell_profile.ps1 @@ -21,6 +21,12 @@ function Invoke-Starship-PreCommand { Invoke-Expression (&starship init powershell) $ENV:STARSHIP_CONFIG = "$HOME\.config\starship.toml" +# home_util shortcut +$home_util_path = "~\Documents\macro\ahk" +function home_util { + & (Join-Path -Path $home_util_path -ChildPath "home_util.exe") +} + # for chezmoi $Editor = "C:\Users\Owner\AppData\Local\Programs\Microsoft VS Code\Code.exe" @@ -52,3 +58,13 @@ Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } + +# Import the Chocolatey Profile that contains the necessary code to enable +# tab-completions to function for `choco`. +# Be aware that if you are missing these lines from your profile, tab completion +# for `choco` will not function. +# See https://ch0.co/tab-completion for details. +$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" +if (Test-Path($ChocolateyProfile)) { + Import-Module "$ChocolateyProfile" +} From b5d9207d7bbc76cf54398ca1dcd8d74f22a20c35 Mon Sep 17 00:00:00 2001 From: qwjyh Date: Sat, 24 Sep 2022 03:57:22 +0900 Subject: [PATCH 2/3] pwsh: add encoding functions and descriptions --- dotfiles/pwsh/powershell_profile.ps1 | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/dotfiles/pwsh/powershell_profile.ps1 b/dotfiles/pwsh/powershell_profile.ps1 index d918b8b..c8d734a 100644 --- a/dotfiles/pwsh/powershell_profile.ps1 +++ b/dotfiles/pwsh/powershell_profile.ps1 @@ -27,6 +27,70 @@ function home_util { & (Join-Path -Path $home_util_path -ChildPath "home_util.exe") } +# change encoding +# ref: https://qiita.com/e4rfx/items/3772ecb58b6918ed5348 +# 文字エンコードをUTF8に設定する +function Set-UTF8 { + <# + .SYNOPSIS + Sets powershell encoding to UTF-8. + + .DESCRIPTION + Sets powershell encodings to UTF-8. + To remove this settings, use Remove-EncodingSettings. + To set to default, use Reset-EncodingSettings. + For more details, see https://qiita.com/e4rfx/items/3772ecb58b6918ed5348. + #> + $PSDefaultParameterValues['*:Encoding'] = 'utf8' + $global:OutputEncoding = [System.Text.Encoding]::UTF8 + [console]::OutputEncoding = [System.Text.Encoding]::UTF8 +} +# UTF 16 LE +# pwsh default encoding +# best for redirecting to more.exe, Out-File +function Set-UTF16LE { + <# + .SYNOPSIS + Sets powershell encoding to UTF-16 LE. + + .DESCRIPTION + Sets powershell encodings to UTF-16 LE(Little Endian), which is the default of pwsh. + This function is especially useful when redirecting to more.exe and less and Out-File and etc. + To remove this settings, use Remove-EncodingSettings. + To set to default, use Reset-EncodingSettings. + For more details, see https://qiita.com/e4rfx/items/3772ecb58b6918ed5348. + #> + $PSDefaultParameterValues['*:Encoding'] = 'unicode' + $global:OutputEncoding = [System.Text.Encoding]::Unicode + [console]::OutputEncoding = [System.Text.Encoding]::Unicode +} +# デフォルトパラメータの文字エンコード指定を解除する +function Remove-EncodingSettings { + <# + .SYNOPSIS + Remove custom encoding settings. + + .DESCRIPTION + Remove custom encoding settings. + For more details, see https://qiita.com/e4rfx/items/3772ecb58b6918ed5348. + #> + $PSDefaultParameterValues.Remove('*:Encoding') +} +# 文字エンコード設定を初期状態に戻す +function Reset-EncodingSettings { + <# + .SYNOPSIS + Sets powershell encoding to default. + + .DESCRIPTION + Sets powershell encodings to default(Shift-JIS). + For more details, see https://qiita.com/e4rfx/items/3772ecb58b6918ed5348. + #> + $PSDefaultParameterValues.Remove('*:Encoding') + $global:OutputEncoding = [System.Text.Encoding]::ASCII + [console]::OutputEncoding = [System.Text.Encoding]::Default +} + # for chezmoi $Editor = "C:\Users\Owner\AppData\Local\Programs\Microsoft VS Code\Code.exe" @@ -35,6 +99,22 @@ $Editor = "C:\Users\Owner\AppData\Local\Programs\Microsoft VS Code\Code.exe" # shortcut to enable ssh-agent function Enable-SshAgent { + <# + .SYNOPSIS + starts ssh-agent + execute ssh-add to add ssh keys + + .DESCRIPTION + Starts ssh-agent. + Execute ssh-add to add ssh keys. + You just need to execute this once after start up. + + .INPUTS + no inputs + + .OUTPUTS + no outputs + #> sudo Set-Service -Name ssh-agent -StartupType Manual && Start-Service ssh-agent } # execute "ssh-add" to add keys From 835b6e1737a45464459d8fbf3c0e0c440d8d1635 Mon Sep 17 00:00:00 2001 From: qwjyh Date: Sat, 24 Sep 2022 04:14:15 +0900 Subject: [PATCH 3/3] pwsh add $env:LESS --- dotfiles/pwsh/powershell_profile.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dotfiles/pwsh/powershell_profile.ps1 b/dotfiles/pwsh/powershell_profile.ps1 index c8d734a..ff955e0 100644 --- a/dotfiles/pwsh/powershell_profile.ps1 +++ b/dotfiles/pwsh/powershell_profile.ps1 @@ -91,12 +91,6 @@ function Reset-EncodingSettings { [console]::OutputEncoding = [System.Text.Encoding]::Default } -# 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 - # shortcut to enable ssh-agent function Enable-SshAgent { <# @@ -119,6 +113,12 @@ function Enable-SshAgent { } # execute "ssh-add" to add keys + +# less options +$env:LESS = "-M -R -S -W -z-4 -x4" + + + # chezmoi completion $script = "$HOME\.config\powershell\chezmoi_completion.ps1" if (Test-Path $script) {