pwshの設定

2024/05/06

まずやること

実行ポリシーを変更する

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

設定プロファイルのスクリプトを作成

New-Item $Profile

fish風のオートサジェスト機能を有効にする方法

Invoke-Item $Profileでテキストエディタを開く

中身に

Set-PSReadLineOption -PredictionSource History
Set-PSReadlineOption -HistoryNoDuplicates
Set-PSReadLineKeyHandler -Key "Ctrl+f" -Function ForwardWord

を追加するとできる

oh-my-poshの設定

Invoke-Item $Profileでテキストエディタを開く

中身に

if ($env:WT_PROFILE_ID) {
    Import-Module oh-my-posh
    Set-PoshPrompt -Theme {{theme}}
}

を追加するとできる

themeフォルダは./Users/{{username}}/AppData/Local/oh-my-posh/themesにある

僕のoh-my-poshのテーマは↓

nya10.omp.json  
{
 "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
 "blocks": [
  {
   "alignment": "left",
   "segments": [
    {
     "foreground": "#B0CBE7",
     "style": "plain",
     "template": "{{.Icon}} ",
     "type": "os"
    },
    {
     "foreground": "#96CCE7",
     "style": "plain",
     "template": "{{ .UserName }}@{{ .HostName }}",
     "type": "session"
    },
    {
     "foreground": "#B0CBE7",
     "properties": {
     "folder_separator_icon": "/",
     "style": "full"
     },
     "style": "plain",
     "type": "path"
    },
    {
     "foreground": "#CECEFF",
     "properties": {
      "branch_icon": "\ue725 ",
      "cherry_pick_icon": "\ue29b ",
      "commit_icon": "\uf417 ",
      "fetch_status": false,
      "fetch_upstream_icon": false,
      "merge_icon": "\ue727 ",
      "no_commits_icon": "\uf0c3 ",
      "rebase_icon": "\ue728 ",
      "revert_icon": "\uf0e2 ",
      "tag_icon": "\uf412 "
     },
     "template": "{{ .HEAD }} ",
     "style": "plain",
     "type": "git"
    },
    {
     "foreground": "#E7E7B0",
     "style": "powerline",
     "template": "\ue235{{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }} ",
     "type": "python"
    },
    {
     "foreground": "#96CCE7",
     "style": "powerline",
     "template": "\ue626{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
     "type": "go"
    },
    {
     "foreground": "#B0E7CB",
     "style": "powerline",
     "template": "\ue718{{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} ",
     "type": "node"
    },
    {
     "foreground": "#FF9D9D",
     "style": "powerline",
     "template": "\ue791{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
     "type": "ruby"
    },
    {
     "foreground": "#FF9D9D",
     "style": "powerline",
     "template": "\ue738{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
     "type": "java"
    },
    {
     "foreground": "#96CCE7",
     "style": "powerline",
     "template": " \ue624{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
     "type": "julia"
    },
    {
     "foreground": "darkGray",
     "style": "plain",
     "template": "{{ .CurrentDate | date .Format }}",
     "type": "time"
    }
   ],
   "type": "prompt"
  },
  {
   "alignment": "left",
   "newline": true,
   "segments": [
    {
     "style": "plain",
     "template": "\uf105",
     "type": "text"
    }
   ],
   "type": "prompt"
  }
 ],
 "final_space": true,
 "version": 2
}