Skip to content

Instantly share code, notes, and snippets.

@ngdelcastillo
Created January 10, 2016 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngdelcastillo/b6b1553c69e199584b5b to your computer and use it in GitHub Desktop.
Save ngdelcastillo/b6b1553c69e199584b5b to your computer and use it in GitHub Desktop.
Powershell Script
$env:path += ";" + (Get-Item "Env:ProgramFiles").Value + "\Git\bin"
(Get-Host).UI.RawUI.ForegroundColor = "gray"
function prompt
{
Write-host("[" + $(get-location) + "]") -foregroundcolor Green
return "$ "
}
function Get-Batchfile ($file) {
$cmd = "`"$file`" & set"
cmd /c $cmd | Foreach-Object {
$p, $v = $_.split('=')
Set-Item -path env:$p -value $v
}
}
function VsVars32()
{
$vs140comntools = (Get-ChildItem env:VS140COMNTOOLS).Value
$batchFile = [System.IO.Path]::Combine($vs140comntools, "vsvars32.bat")
Get-Batchfile $BatchFile
[System.Console]::Title = "Visual Studio 2015 Windows PowerShell"
}
function Do-Touch {
param(
[string]$filespec = $null,
[datetime]$datetime = ([DateTime]::Now),
[int]$forward = 0,
[string]$reference = $null,
[bool]$only_modification = $false,
[bool]$only_access = $false
);
$touch = $null;
if ( $filespec )
{
$files = @(Get-ChildItem -Path $filespec -ErrorAction SilentlyContinue)
if ( !$files )
{
# If file doesn't exist, attempt to create one.
# A wildcard patter will fail silently.
Set-Content -Path $filespec -value $null;
$files = @(Get-ChildItem -Path $filespec -ErrorAction SilentlyContinue);
}
if ( $files )
{
if ( $reference )
{
$reffile = Get-ChildItem -Path $reference -ErrorAction SilentlyContinue;
if ( $reffile )
{
[datetime]$touch = $reffile.LastAccessTime.AddSeconds($forward);
}
}
elseif ( $datetime )
{
[datetime]$touch = $datetime.AddSeconds($forward);
}
if ( $touch )
{
[DateTime]$UTCTime = $touch.ToUniversalTime();
foreach ($file in $files)
{
if ( $only_access )
{
$file.LastAccessTime=$touch
$file.LastAccessTimeUtc=$UTCTime
}
elseif ( $only_modification )
{
$file.LastWriteTime=$touch
$file.LastWriteTimeUtc=$UTCTime
}
else
{
$file.CreationTime = $touch;
$file.CreationTimeUtc = $UTCTime;
$file.LastAccessTime=$touch
$file.LastAccessTimeUtc=$UTCTime
$file.LastWriteTime=$touch
$file.LastWriteTimeUtc=$UTCTime
}
$file | select Name, *time*
}
}
}
}
}
VsVars32
set-alias touch Do-Touch
Set-Alias sublime "C:\Program Files\Sublime Text 2\sublime_text.exe"
set shell=powershell
set shellcmdflag=-command
cd D:\Code
# Load posh-git
if(Test-Path Function:\Prompt) {Rename-Item Function:\Prompt PrePoshGitPrompt -Force}
# Load posh-git example profile
. 'C:\tools\poshgit\dahlbyk-posh-git-bc61566\profile.example.ps1'
#Rename-Item Function:\Prompt PoshGitPrompt -Force
#function Prompt() {if(Test-Path Function:\PrePoshGitPrompt){++$global:poshScope; New-Item function:\script:Write-host -value "param([object] `$object, `$backgroundColor, `$foregroundColor, [switch] `$nonewline) " -Force | Out-Null;$private:p = PrePoshGitPrompt; if(--$global:poshScope -eq 0) {Remove-Item function:\Write-Host -Force}}PoshGitPrompt}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment