-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #52
- Loading branch information
Showing
3 changed files
with
176 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
$pwsh_config_path = "Microsoft.PowerShell_profile.ps1" | ||
$pwsh_config_path = "Microsoft.PowerShell_profile.ps1.tmpl" | ||
$pwsh_config_file = Get-Content -Path $pwsh_config_path | ||
Set-Content -Path $pwsh_config_path -Value $pwsh_config_file -Encoding "utf8BOM" |
This file was deleted.
Oops, something went wrong.
175 changes: 175 additions & 0 deletions
175
dot_config/powershell/Microsoft.PowerShell_profile.ps1.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
# Use cache and speedup | ||
# thx: https://zenn.dev/ryoppippi/articles/de6c931cc1028f | ||
$env:CACHE_PROFILE_DIR = "$env:HOME/.cache/powershell" | ||
$env:CACHE_PROFILE = Join-Path -Path $env:CACHE_PROFILE_DIR -ChildPath "cache-profile.ps1" | ||
$CACHE_PROFILE = $env:CACHE_PROFILE | ||
|
||
if ((Test-Path $PROFILE) -and (Test-Path $CACHE_PROFILE)) { | ||
if ((Get-Item $PROFILE).LastWriteTime -gt (Get-Item $CACHE_PROFILE).LastWriteTime) { | ||
$cond = $true | ||
} else { | ||
$cond = $false | ||
} | ||
} elseif ((Test-Path $PROFILE) -and !(Test-Path $CACHE_PROFILE)) { | ||
$cond = $true | ||
} else { | ||
$cond = $false | ||
} | ||
|
||
if ($cond) { | ||
New-Item $env:CACHE_PROFILE_DIR -ItemType Directory -Force 2>&1 > $null | ||
New-Item $env:CACHE_PROFILE -ItemType File -Value "" -Force 2>&1 > $null | ||
|
||
# using namespace first | ||
$namespace1 = "using namespace System.Management.Automation.Language" | ||
$namespace2 = "using namespace System.Management.Automation" | ||
Write-Output $namespace1 >> $env:CACHE_PROFILE | ||
Write-Output $namespace2 >> $env:CACHE_PROFILE | ||
|
||
# starship setup | ||
Write-Output "# cache starship setup" >> $env:CACHE_PROFILE | ||
starship init powershell --print-full-init >> $env:CACHE_PROFILE | ||
|
||
# starship completion | ||
Write-Output "# cache starship completion" >> $env:CACHE_PROFILE | ||
$starship_completion = starship completions powershell | | ||
ForEach-Object { $_ -replace $namespace1, "" } | | ||
ForEach-Object { $_ -replace $namespace2, "" } | ||
Write-Output $starship_completion >> $env:CACHE_PROFILE | ||
|
||
# wezterm completion | ||
Write-Output "# cache wezterm completion" >> $env:CACHE_PROFILE | ||
$wezterm_completion = wezterm shell-completion --shell power-shell | | ||
ForEach-Object { $_ -replace $namespace1, "" } | | ||
ForEach-Object { $_ -replace $namespace2, "" } | ||
Write-Output $wezterm_completion >> $env:CACHE_PROFILE | ||
|
||
# rustup completion | ||
Write-Output "# cache rustup completion" >> $env:CACHE_PROFILE | ||
$rustup_completion = rustup completions powershell | | ||
ForEach-Object { $_ -replace $namespace1, "" } | | ||
ForEach-Object { $_ -replace $namespace2, "" } | ||
Write-Output $rustup_completion >> $env:CACHE_PROFILE | ||
|
||
# chezmoi completion | ||
Write-Output "# cache chezmoi completion" >> $env:CACHE_PROFILE | ||
chezmoi completion powershell >> $env:CACHE_PROFILE | ||
|
||
# github-cli completion | ||
Write-Output "# cache github-cli completion" >> $env:CACHE_PROFILE | ||
gh completion -s powershell >> $env:CACHE_PROFILE | ||
|
||
# just completion | ||
# Powershell v7以上のときのみ読み込む | ||
$ver = $PSVersionTable.PSVersion.Major | ||
if ($ver -eq 7) { | ||
Write-Output "# cache just completion" >> $env:CACHE_PROFILE | ||
$just_completion = just --completions powershell | | ||
ForEach-Object { $_ -replace $namespace1, "" } | | ||
ForEach-Object { $_ -replace $namespace2, "" } | ||
Write-Output $just_completion >> $env:CACHE_PROFILE | ||
} | ||
|
||
# zoxide setup | ||
Write-Output "# cache zoxide setup" >> $env:CACHE_PROFILE | ||
zoxide init powershell >> $env:CACHE_PROFILE | ||
|
||
# zoxide completion | ||
Write-Output "# cache zoxide completion" >> $env:CACHE_PROFILE | ||
$zoxideCompleteFilePath = Join-Path -Path $env:GHQ_ROOT -ChildPath "github.com\ajeetdsouza\zoxide\contrib\completions\_zoxide.ps1" | ||
if (Test-Path($zoxideCompleteFilePath)) { | ||
$zoxide_completion = Get-Content $zoxideCompleteFilePath | | ||
ForEach-Object { $_ -replace $namespace1, "" } | | ||
ForEach-Object { $_ -replace $namespace2, "" } | ||
} | ||
Write-Output $zoxide_completion >> $env:CACHE_PROFILE | ||
} | ||
|
||
# Loading from cache profile | ||
. $env:CACHE_PROFILE | ||
|
||
#posh-git git | ||
Import-Module posh-git | ||
# PSReadLine | ||
Import-Module PSReadLine | ||
|
||
$env:EDITOR = "nvim" | ||
|
||
# Obsidian vault | ||
{{ if eq .chezmoi.hostname "TanakaPC" }} | ||
$win_obsidian_vault_path_value = {{ (bitwardenFields "item" "0f17c992-d0fe-4f36-bde8-95d9e2de3a6d").win_obsidian_vault_path.value }} | ||
{{ else }} | ||
$win_obsidian_vault_path_value = {{ (bitwardenFields "item" "ec557677-82d9-4a61-a4f6-aed300cfb34f").win_obsidian_vault_path.value }} | ||
{{ end }} | ||
$windocuments = Join-Path $env:WIN_HOME -ChildPath "Documents" | ||
$env:obsidian_vault_path = Join-Path $windocuments -ChildPath $win_obsidian_vault_path_value | ||
$env:obsidian = Join-Path $env:obsidian_vault_path -ChildPath "001_DailyNotes" | ||
|
||
# alias bd | ||
function Set-ParentLocation() { | ||
Set-Location .. | ||
} | ||
Set-Alias -Name bd -Value Set-ParentLocation | ||
|
||
# alias touch | ||
Set-Alias -Name touch -Value New-Item | ||
|
||
# alias ls (lsd or eza) | ||
Get-Command eza -ErrorAction Ignore | Out-Null | ||
$res = $? | ||
if ($res) { | ||
# alias ls eza | ||
Set-Alias -Name ls -Value eza | ||
# eza aliases | ||
function Invoke-EzaTree() { | ||
eza -T | ||
} | ||
Set-Alias -Name lt -Value Invoke-EzaTree | ||
function Invoke-EzaLa() { | ||
eza -la | ||
} | ||
Set-Alias -Name la -Value Invoke-EzaLa | ||
} | ||
|
||
# alias vim | ||
Get-Command neovim -ErrorAction Ignore | Out-Null | ||
$res = $? | ||
if ($res) { | ||
# alias vim neovim | ||
Set-Alias -Name vim -Value neovim | ||
} | ||
|
||
# alias gcd | ||
$env:PSGhqPath = "$env:GHQ_ROOT\github.com\mimikun\PSGhq\Set-GhqLocation.ps1" | ||
if (Test-Path($env:PSGhqPath)) { | ||
. $env:PSGhqPath | ||
Set-Alias -Name gcd -Value Set-GhqLocation | ||
} | ||
|
||
# alias editorconfig Invoke-GenerateEditorConfig | ||
function Invoke-GenerateEditorConfig() { | ||
Get-Item -Path .\.editorconfig -ErrorAction Ignore | ||
$res = $? | ||
if (!$res) { | ||
Write-Output ".editorconfig not exist." | ||
Write-Output "Creating .editorconfig." | ||
Copy-Item -Path $env:USERPROFILE\.editorconfig-template -Destination .\.editorconfig | ||
} | ||
} | ||
Set-Alias -Name editorconfig Invoke-GenerateEditorConfig | ||
|
||
# PSReadLine settings | ||
Set-PSReadLineKeyHandler ` | ||
-Key Ctrl+g ` | ||
-BriefDescription "Run ghq cd" ` | ||
-LongDescription "Run ghq cd" ` | ||
-ScriptBlock { | ||
Set-GhqLocation | ||
} | ||
|
||
# alias chezmoi_cd | ||
function Set-ChezmoiDirLocation() { | ||
Set-Location $env:CHEZMOI_DIR | ||
} | ||
Set-Alias -Name chezmoi_cd -Value Set-ChezmoiDirLocation | ||
|