♻️

UbuntuにPowerShell入れるメモ

2020/09/26に公開

環境

  • Ubuntu 18.04

手順

PowerShell 入れる

https://docs.microsoft.com/ja-jp/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-6#ubuntu-1804

sh
# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt update

# Enable the "universe" repositories
sudo add-apt-repository universe

# Install PowerShell
sudo apt install powershell

# Start PowerShell
pwsh

ログインシェルをPowerShellにする

sh
chsh -s /usr/bin/pwsh

posh-git 入れる

https://git-scm.com/book/ja/v2/Appendix-A%3A-その他の環境でのGit-PowershellでGitを使う

powershell
Install-Module posh-git

$PROFILE 編集

powershell
vim $PROFILE
~/.config/powershell/Microsoft.PowerShell_profile.ps1
# プロンプト設定 (お好みで変えて下さい)
function prompt {
    $tmp = $LASTEXITCODE
    $GitPromptSettings.EnableWindowTitle = "$(git rev-parse --git-common-dir | Split-Path -Parent | Split-Path -Leaf) "
    $path = git rev-parse --show-prefix
    if ($null -eq $path) {
        $path = $ExecutionContext.SessionState.Path.CurrentLocation.Path
    } else {
        $path = ':' + $path -replace '/$', ''
    }
    Write-Host $path -NoNewline
    Write-VcsStatus
    "$('>' * ($NestedPromptLevel + 1)) "
    $LASTEXITCODE = $tmp
}

# posh-git
Import-Module posh-git
$GitPromptSettings.EnableStashStatus = $true

# ~/bin をPATHに追加
$env:PATH += ":/home/$env:USER/bin"

# エイリアス (適当にいろいろ入れてね)
function exec() {
    Start-Process -Wait @args
}

New-Alias eval Invoke-Expression
New-Alias g git

# ssh-agent
Start-SshAgent

Discussion