1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PowerShellをKaliっぽくしてみた

Last updated at Posted at 2025-11-26

以下を$PROFILEに記述すると、Kaliっぽくなる。
PowerShell 7向け。

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$PSDefaultParameterValues['*:Encoding'] = 'utf8'

Import-Module PSReadLine
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineKeyHandler -Key Ctrl+e -Function AcceptSuggestion
Set-PSReadLineKeyHandler -Key RightArrow -Function ForwardChar

# Tab を Linux みたいに「完了」動作にする
# Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Chord Tab -Function MenuComplete
# Set-PSReadLineOption -PredictionViewStyle ListView
# Set-PSReadLineOption -PredictionViewStyle InlineView

# 候補数を増やす(古い版でも有効)
Set-PSReadLineOption -CompletionQueryItems 500

Set-PSReadLineOption -Colors @{
	Command = 'Cyan'
        Error   = 'DarkGray'
}

# vi
Set-Alias vi vim

function prompt {

    # path shortener
    $full = $PWD.ProviderPath
    $userHome = [Environment]::GetFolderPath("UserProfile")
    if ($full -like "$userHome*") {
        $shortPath = "~" + $full.Substring($userHome.Length)
    }
    else {
        $shortPath = $full
    }

    # ===== Git ブランチ(リポジトリルート探索版) =====
    function Find-GitRoot($startDir) {
        $dir = Get-Item $startDir
        while ($dir -ne $null) {
            if (Test-Path (Join-Path $dir.FullName ".git")) {
                return $dir.FullName
            }
            $dir = $dir.Parent
        }
        return $null
    }

    $branch = ""
    try {
        $gitRoot = Find-GitRoot $PWD

        if ($gitRoot) {
            $gitHead = Join-Path $gitRoot ".git\HEAD"
            if (Test-Path $gitHead) {
                $content = Get-Content $gitHead -ErrorAction SilentlyContinue
                if ($content -match "ref: refs/heads/(.+)") {
                    $branch = $matches[1]
                }
            }
        }
    }
    catch {}

    # User / Host
    $user = [Environment]::UserName
    $hostName = $env:COMPUTERNAME

    # 1行目
    Write-Host "┌──(" -ForegroundColor Green -NoNewline
    Write-Host $user -ForegroundColor Blue -NoNewline
    Write-Host "㉿" -ForegroundColor Blue -NoNewline
    Write-Host $hostName -ForegroundColor Blue -NoNewline
    Write-Host ")-[" -ForegroundColor Green -NoNewline
    Write-Host $shortPath -ForegroundColor White -NoNewline
    Write-Host "]" -ForegroundColor Green -NoNewline
    if ($branch) {
        Write-Host "($branch)" -ForegroundColor Blue -NoNewline
    }
    Write-Host ""

    # 2行目
    Write-Host "└─$ " -ForegroundColor Green -NoNewline

    return " "
}
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?