Migrate SQLPrompt Snippets to VSCode

 I love snippets; love em. And I have a whole bunch in RedGate SQL Prompt. Now I want to be able to use those in VSCode as well, but boy do I dread having to retype all of them. Solution? Python! First arg is the path where your SQLPrompt snippets are Second arg is the directory where you want it to spit out a "sql.json" file with all your snippets. """ A script to translate sqlprompt snippet files to vscode formatted snippets """ import os import json import glob import io import argparse class SQLPromptPlaceholder :     """Represents the values of a SQLPrompt placeholder"""     def __init__ ( self , name , default_value ):         self . name = name         self . default_value = default_value class SQLPromptSnippet :     """Represents the content of a SQLPrompt snippet"""     @ staticmethod     def from_file ( filename ):         """Generates an instance fr

Powershell Script: to Create Git Repo with .gitignore

 I'm a scripting junkie, so I got tired of having to download or copy/paste a gitignore file into my git repos all the time. To that end, I created the script below.

The involved function is

gitig
which downloads a boilerplate .gitignore file from github (i have it defaulting to downloading the VisualStudio .gitignore, but you can change that, or provide your own at call time).

The other function is
gitinit
which calls
gitig
followed by
git init
. That way you can initialize a new git repo with a boiler plate .gitignore script with a single powershell command.

To install these, 

  1. Open Powershell
  2. Type "notepad $profile"
    1. This will open notepad with your powershell profile
  3. Paste the code below at the bottom of that file
  4. Save and close the profile file
  5. Restart powershell
Now you can type
gitinit
from powershell to create a repository with a boilerplate .gitignore anywhere you want.

function gitig(
    [String]$Name = "VisualStudio", 
    [switch]$Overwrite = $false, 
    [switch]$Silent = $false) 
{
	$url = "https://raw.githubusercontent.com/github/gitignore/master/${name}.gitignore"
    $headerMessage = "** FAILURE **"
    $message = ""
    try {
        $response = Invoke-WebRequest -Uri $url
        $message = "    Retrieved content from URL: $url`n"
        $targetFilePath = Join-Path (Get-Location) ".gitignore"
        $fileExists = Test-Path $targetFilePath
        if ((-not $fileExists) -or $Overwrite) {
            $headerMessage = "** SUCCESS **"
            
            if ($Overwrite) {
                $message = "$message    OVERWROTE ""$targetFilePath"""
            } else {
                $message = "$message    Wrote content to ""$targetFilePath"""
            }
            $response.Content > $targetFilePath
        } else {
            $headerMessage = "** FAILURE **"
            $message = "$message    File already exists! To Overwrite, pass '-Overwrite'"
        }
    }
    catch {
		$headerMessage = "** FAILURE **"
        $message = "    Requesting ""$url""`n    $($_.Exception.Message)"
	}
    finally {
        if (-not $Silent) {
            Write-Output $headerMessage
            Write-Output $message
        }
    }
}

function gitinit([string]$GitIgnoreName = "VisualStudio") {
	if (-Not (Test-Path .git)) {
		gitig -Name $GitIgnoreName
		git init
	} else {
		Write-Output "Git repository already exists here."
	}
}

Comments

Popular posts from this blog

Migrate SQLPrompt Snippets to VSCode

Fixing Git "Unexpected Disconnect while reading sideband packet"

Left-Padding Zeroes