Last active
November 30, 2018 20:42
-
-
Save craibuc/5ffec8491c825a75aee7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Write-Host "Executing $($MyInvocation.MyCommand.Name)..." | |
## | |
# variables | |
# | |
Write-Host "`nSetting environment variables..." | |
$ProfileFolder = Split-Path -path $Profile | |
# PS> cd $modules | |
$MODULES = "$(split-path $profile)\Modules" | |
# PS> cd $scripts | |
$SCRIPTS = "$(split-path $profile)\Scripts" | |
# $DOCS = $(resolve-path "$Env:userprofile\Documents") | |
# $DESKTOP = $(resolve-path "$Env:userprofile\Desktop") | |
# $PROJECTS = $(resolve-path "$Env:userprofile\Projects") | |
# $HOMEDRIVE = "C:\" | |
# $HOMEPATH = "Users\" + $env:username | |
# Set-Location $env:USERPROFILE\Documents\WindowsPowerShell | |
# Set-Location $projects | |
# Set and force overwrite of the $HOME variable | |
# Set-Variable HOME "$HOMEDRIVE$HOMEPATH" -Force | |
## | |
# drives | |
# | |
Write-Host "`nCreating drives..." | |
# New-PSDrive wps filesystem $env:USERPROFILE\Documents\WindowsPowerShell | |
# New-PSDrive Q filesystem $env:USERPROFILE\Projects\Requests | |
# New-PSDrive M filesystem "$(split-path $profile)\Modules" | |
# New-PSDrive -Name J -PSProvider FileSystem -Root "$HOMEDRIVE$HOMEPATH\Projects" | |
# Set the "~" shortcut value for the FileSystem provider | |
# (get-psprovider 'FileSystem').Home = $HOMEDRIVE + $HOMEPATH | |
## | |
# shell suport for applications | |
# | |
Write-Host "`nModifying PATH..." | |
# sublime text | |
$env:Path="$env:USERPROFILE\Applications\Sublime Text;$($env:Path)" | |
# Visual Studio Code | |
# $env:Path="$env:USERPROFILE\Applications\Visual Studio Code;$($env:Path)" | |
# Git | |
# $env:Path="$env:USERPROFILE\Applications\PortableGit\cmd;$($env:Path)" | |
# Ruby | |
# $env:Path="$env:USERPROFILE\Applications\ruby\current\bin;$($env:Path)" | |
## | |
# application aliases | |
# | |
Write-Host "`nAssigning aliases..." | |
# opens the current folder in Explorer | |
# PS> open . | |
Set-Alias open Explorer | |
# add the clipboard as a pipeline target | |
# copy a file's content to the clipboard | |
# PS> Get-Content ~\Desktop\data.csv -Raw | Out-Clipboard | |
Set-Alias Out-Clipboard $env:SystemRoot\system32\clip.exe | |
## | |
# imported modules | |
# | |
Write-Host "`nImporting modules..." | |
# package manager | |
Import-Module PsGet | |
# testing framework | |
Import-Module Pester | |
Set-Alias pester Invoke-Pester | |
# build-automation ala 'rake' for powershell-git | |
Import-Module Psake | |
Set-Alias -Name psake -Value Invoke-Psake | |
# SQL Server-PowerShell intergration | |
# Import-Module sqlps -DisableNameChecking | |
# New-Alias sql Invoke-Sqlcmd | |
# powershell-git intergration | |
Import-Module posh-git | |
# posh-git prompt | |
. $ProfileFolder\Modules\posh-git\profile.example.ps1 | |
## | |
# imported scripts | |
# | |
Write-Host "`nImporting scripts..." | |
# load all scripts in 'Dot-Sourced' folder | |
Get-ChildItem ( "$(Split-Path $profile)\Scripts\Dot-Sourced" ) -Recurse | ` | |
Where { $_.Name -like '*.ps1' -and $_.Name -notlike '__*' -and $_.Name -notlike '*.Tests*' } | ` | |
ForEach { . $_.FullName } | |
## | |
# functions | |
# | |
Write-Host "`nGenerating functions..." | |
# create a directory then change to it | |
# PS> mcd newFolder | |
function mcd { mkdir @args; cd @args } | |
# remove a directory | |
# PS> rdf this_folder_and_its_spawn | |
function rdf { Remove-Item -recurse -force @args } | |
# wrap MKLINK command | |
# PS> mklink /h alias path\to\file | |
# PS> mklink /j alias path\to\folder | |
function mklink { cmd /c mklink $args } | |
# parse the PATH environment variable; make it readable | |
# PS> path | |
function path { ($env:Path).Replace(';',"`n") } | |
# calculate the size of the directory and its contents | |
function Get-DirectorySize() { | |
param ([string]$root = $(resolve-path .)) | |
gci -re $root | | |
?{ -not $_.PSIsContainer } | | |
measure-object -sum -property Length | |
} | |
# enable Write-Debug messages | |
# toggle state by repeated issuing command | |
# PS> debug | |
function Set-DebugMode() | |
{ | |
switch ($DebugPreference) { | |
'Continue' { | |
write-host 'Setting debug off' | |
$global:DebugPreference = 'SilentlyContinue' | |
} | |
'SilentlyContinue' { | |
write-host 'Setting debug on' | |
$global:DebugPreference = 'Continue' | |
} | |
} | |
} | |
Set-Alias debug Set-DebugMode | |
# allow ZIP modules downloaded from Github to function | |
function unblock { ls -r | Unblock-File } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment