Skip to content

PowerShell modify_ script #1493

Answered by bradenhilton
jeandeaual asked this question in Q&A
Discussion options

You must be logged in to vote

See https://stackoverflow.com/a/66550241/11000543 regarding Read-Host.

I can't remember off the top of my head if $input/$($input)/@($input) works in the context of a chezmoi modify_ script. Feel free to try it.

At the moment I'm using this:

function Read-FileFromStdin {
    $stdin = [System.Console]::In

    $allLines = @()
    while ($line = $stdin.ReadLine()) {
        $allLines += $line
    } 

    if (-not $allLines) {
        return $null
    }

    return $allLines -join [System.Environment]::NewLine
}

$CurrentFileContents = Read-FileFromStdin

You can also just directly read the file contents if you want:

function Read-FileFromPath {
    $filePath = "your/path/here"

    if (-not (T…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jeandeaual
Comment options

Answer selected by jeandeaual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants