Skip to content

Instantly share code, notes, and snippets.

@akilb
Created April 3, 2018 11:37
Show Gist options
  • Save akilb/0c116c9b85d85b8cf807399e63b1d612 to your computer and use it in GitHub Desktop.
Save akilb/0c116c9b85d85b8cf807399e63b1d612 to your computer and use it in GitHub Desktop.
PowerShell personalisation
# Bail if this is running in the NuGet Package Manager Console
# https://github.com/NuGet/Home/issues/917
if ($profile.Contains("NuGet_profile")) {
# Just define this func that helps with updating packages
Function Update-AllProjects {
[CmdletBinding()]
Param($arg)
foreach ($project in Get-Project -all) { Update-Package -Id $arg -ProjectName $project.ProjectName }
};
return;
}
# Use posh-git
Import-Module posh-git
# Hack to make git think powershell can handle colours.
$env:TERM = 'cygwin'
$env:LESS = 'FRSX'
# Grab Program Files x64 folder
$env:ProgramFilesx64 = (Join-Path ${env:ProgramFiles(x86)} "..\Program Files")
#Set environment variables for Visual Studio Command Prompt
pushd 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\'
cmd /c "VsDevCmd.bat&set" |
foreach {
if ($_ -match "=") {
$v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
popd
function global:psprof {
& start "$env:userprofile\Documents\WindowsPowerShell\profile.ps1"
}
function global:hosts {
& np "$env:SystemRoot\System32\drivers\etc\hosts"
}
function global:src {
& pushd "C:\src"
}
function global:np {
& "${env:ProgramFilesx64}\notepad2\Notepad2.exe" ($args[0])
}
function global:npp {
& "${env:programfiles(x86)}\Notepad++\notepad++.exe" ($args)
}
function global:nps {
& "${env:ProgramFilesx64}\Sublime Text 3\sublime_text.exe" ($args)
}
function global:.. {
pushd ".."
}
function global:mydocs {
& pushd "$env:userprofile\Documents"
}
function global:desktop {
& pushd "$env:userprofile\Desktop"
}
function Set-FileTime{
param(
[string[]]$paths,
[bool]$only_modification = $false,
[bool]$only_access = $false
);
begin {
function updateFileSystemInfo([System.IO.FileSystemInfo]$fsInfo) {
$datetime = get-date
if ( $only_access )
{
$fsInfo.LastAccessTime = $datetime
}
elseif ( $only_modification )
{
$fsInfo.LastWriteTime = $datetime
}
else
{
$fsInfo.CreationTime = $datetime
$fsInfo.LastWriteTime = $datetime
$fsInfo.LastAccessTime = $datetime
}
}
function touchExistingFile($arg) {
if ($arg -is [System.IO.FileSystemInfo]) {
updateFileSystemInfo($arg)
}
else {
$resolvedPaths = resolve-path $arg
foreach ($rpath in $resolvedPaths) {
if (test-path -type Container $rpath) {
$fsInfo = new-object System.IO.DirectoryInfo($rpath)
}
else {
$fsInfo = new-object System.IO.FileInfo($rpath)
}
updateFileSystemInfo($fsInfo)
}
}
}
function touchNewFile([string]$path) {
#$null > $path
Set-Content -Path $path -value $null;
}
}
process {
if ($_) {
if (test-path $_) {
touchExistingFile($_)
}
else {
touchNewFile($_)
}
}
}
end {
if ($paths) {
foreach ($path in $paths) {
if (test-path $path) {
touchExistingFile($path)
}
else {
touchNewFile($path)
}
}
}
}
}
New-Alias touch Set-FileTime
Set-Location C:\src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment