LoginSignup
68
61

More than 5 years have passed since last update.

PowerShellのprofile.ps1自分用設定

Last updated at Posted at 2015-10-01

はじめに

下記の設定がかわいかったので、プロファイルの設定を作成したお話(*'-')
かわいい PowerShell プロンプト

参考

PowerShellのプロンプト文字列をカスタマイズする
Windows PowerShell プロファイル
Windows PowerShell コンソールをカスタマイズする

プロファイルを見つける&作成する

  • プロファイル確認
    Test-Path $profile

  • 無い場合
    New-Item -path $profile -type file -force

  • ある場合
    notepad $profile

    PowerShellでは「みつかりません」PowerShell ISEだと「新しく作成しますか?」でした(私の環境では(windows7))。
    プロファイルについての詳細(ユーザ毎等)は下記サイトで詳しく説明されています。
    PowerShell で Profile を利用して スクリプトの自動読み込みをしてみよう

かわいくしていく+α

profile.ps1を編集していきます!

タイトルを変更する

profile.ps1
$a = (Get-Host).UI.RawUI 
$a.WindowTitle = "三( `・ω・)\\|| Powershell////(・ω・´ )三"

開始ディレクトリの指定

profile.ps1
Set-Location 開始したい場所の絶対パス

実行ポリシー表示

profile.ps1
Write-Host "実行ポリシーは" (Get-ExecutionPolicy) "だよ!" -ForegroundColor "Yellow"

かわいい設定

現在のディレクトリがわからないと不便だったので追加しています。

profile.ps1
function Prompt {
    if ($?) {
        Write-Host "["(Split-Path (Get-Location) -Leaf)"](*'-')"  -NoNewLine -ForegroundColor "Green"
        return "> "
    } else {
        Write-Host "["(Split-Path (Get-Location) -Leaf)"](*;-;)"  -NoNewLine -ForegroundColor "Red"
        return "> "
    }
}

まとめ

profile.ps1を起動時に読みこめるよう、実行ポリシーをRemoteSigned以上に変更しておきましょう。
Powershellを楽に実行してもらうには

profile.ps1
#タイトルを変更する
$a = (Get-Host).UI.RawUI 
$a.WindowTitle = "三( `・ω・)\\|| Powershell////(・ω・´ )三"

#開始ディレクトリの指定
Set-Location 開始したい場所の絶対パス

#実行ポリシー確認
Write-Host "実行ポリシーは" (Get-ExecutionPolicy) "だよ!" -ForegroundColor "Yellow"

#かわいい設定
function Prompt {
    if ($?) {
        Write-Host "["(Split-Path (Get-Location) -Leaf)"](*'-')"  -NoNewLine -ForegroundColor "Green"
        return "> "
    } else {
        Write-Host "["(Split-Path (Get-Location) -Leaf)"](*;-;)"  -NoNewLine -ForegroundColor "Red"
        return "> "
    }
}

その他

$aの要素((Get-Host).UI.RawUI )の設定をいろいろいじれば、背景色・画面サイズなどなど設定できます。

68
61
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
68
61