Last active
March 7, 2020 02:40
-
-
Save SirJson/7f7c184ebdbf4ebfc21d55a9e743cbba to your computer and use it in GitHub Desktop.
ignoreman but ported to powershell 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$gitroot = $args[0] | |
function gitignoreio() { | |
# Parameter help description | |
Param( | |
[Parameter(Mandatory = $true)] | |
[String] | |
$command | |
) | |
$output = curl -L -s "https://www.gitignore.io/api/$command" | |
return $output | |
} | |
if (-Not $gitroot) { | |
Write-Warning "No project root provided. Searching for a git project in my working directory..." | |
$gitroot = $(Get-ChildItem -Path $userguess *.git -Directory -Hidden) | |
if (-Not $gitroot) { | |
Write-Warning "No git project found" | |
$userguess = Read-Host -Prompt 'Where is the root of your git project? Relative paths are allowed.' | |
try { | |
$gitroot = $(Get-ChildItem -Path $userguess *.git -Recurse -Directory -Hidden) | |
$gitroot = Split-Path -Path $gitroot -Parent | |
Write-Output "Using: $gitroot" | |
} | |
catch { | |
Write-Output "Sorry but I didn't find the .git folder at your path. Try again!" | |
exit | |
} | |
} | |
} | |
$ignorefile = "$gitroot/.gitignore"; | |
$templates = gitignoreio list | |
$selection = $templates -split "," | Out-GridView -Title "Ignore templates" -PassThru | |
foreach ($select in $selection) { | |
Write-Host "Adding the gitignore config for $select" | |
gitignoreio $select >> $ignorefile | |
} | |
Write-Host "Done! Your new or modified gitignore file is at $ignorefile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment