Last active
September 8, 2015 07:43
-
-
Save dnasca/1404484f446986d1e10c to your computer and use it in GitHub Desktop.
just some quality of life objects to increase workflow in powershell.
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
| #goes in C:\Users\user.name\Documents\WindowsPowerShell (Microsoft.PowerShell_profile.ps1) | |
| #prompt is automatically invoked | |
| function prompt { | |
| # display the full, current path in the window title | |
| $host.ui.RawUI.WindowTitle = ( get-item -path ".\" -verbose ).FullName + " :: ${env:username}" | |
| # prompt: 14:22 :: c:\ > | |
| write-host (($(get-date).ToString("HH:mm")) + " :: " + (get-location | get-item).Name) -nonewline -foregroundcolor yellow | |
| return " > " | |
| } | |
| #pseudo-class for creating objects that represent information about applications | |
| $ShortcutFactory = new-object psobject -property @{ | |
| name = $null | |
| path = $null | |
| # add-member: adds methods to the $ShortcutFactory object #usage: chrome.cd() | |
| } | add-member -name "cd" -passthru -membertype scriptmethod -value { $this.path = split-path $this.path; cd $this.path | |
| } | add-member -name "dir" -passthru -membertype scriptmethod -value { $this.path = split-path $this.path; dir | |
| } | add-member -name 'fe' -passthru -membertype scriptmethod -value { $this.path = split-path $this.path; ii $this.path | |
| } | add-member -name 'ii' -passthru -membertype scriptmethod -value { ii $this.path } | |
| #pseudo-class constructor? | |
| function ShortcutFactory ($name, $path){ | |
| # i'm kind of like a constructor... | |
| $app = $ShortcutFactory.psobject.copy() | |
| $app.name = $name | |
| $app.path = $path | |
| $app | |
| } | |
| # instantiate some objects with our ShortcutFactory function. -name, -path are the arguments | |
| $chrome = ShortcutFactory -name "chrome" -path "${env:ProgramFiles(x86)}\google\chrome\application\chrome.exe" | |
| $iexplore = ShortcutFactory -name "iexplore" -path "${env:ProgramFiles(x86)}\internet explorer\iexplore.exe" | |
| $firefox = ShortcutFactory -name "firefox" -path "${env:ProgramFiles(x86)}\mozilla firefox\firefox.exe" | |
| $safari = ShortcutFactory -name "safari" -path "${env:ProgramFiles(x86)}\safari\safari.exe" | |
| $iis = ShortcutFactory -name "iis" -path "${env:systemroot}\system32\inetsrv\inetmgr.exe" | |
| $sqlms = ShortcutFactory -name "sqlms" -path "${env:ProgramFiles(x86)}\microsoft sql server\90\tools\binn\vsshell\common7\ide\sqlwb.exe" | |
| $vs2010 = ShortcutFactory -name "vs2010" -path "${env:ProgramFiles(x86)}\microsoft visual studio 10.0\common7\ide\devenv.exe" | |
| $vs2013 = ShortcutFactory -name "vs2013" -path "${env:ProgramFiles(x86)}\microsoft visual studio 12.0\common7\ide\devenv.exe" | |
| $vscode = ShortcutFactory -name "vscode" -path "${env:ProgramFiles(x86)}\code\bin\code.cmd" | |
| $fdlr = ShortcutFactory -name "fdlr" -path "${env:ProgramFiles(x86)}\fiddler2\fdlr.exe" | |
| $winmrg = ShortcutFactory -name "winmerge" -path "${env:ProgramFiles(x86)}\winmerge\winmergeu.exe" | |
| $sublime = ShortcutFactory -name "sublime" -path "${env:ProgramFiles}\sublime text 3\sublime_text.exe" | |
| $7zip = ShortcutFactory -name "7-zip" -path "${env:ProgramFiles}\7-zip\7zfm.exe" | |
| $derrik = ShortcutFactory -name "derrik" -path "${env:userprofile}" | |
| $temp = ShortcutFactory -name "temp" -path "${env:userprofile}\temp" | |
| $dropbox = ShortcutFactory -name "dropbox" -path "${env:userprofile}\Dropbox" | |
| # the switches invoke methods that exist on the objects (created with the add-members that are piped into the $ShortcutFactory object) | |
| #usage: iis (opens inetmgr.exe) // iis fe (opens iis dir in file explorer) /// iis cd (directs path to iis path) | |
| ###################################################################### | |
| function iis ($cmd) { switch ($cmd) { 'fe' { $iis.fe() } | |
| 'cd' { $iis.cd() } | |
| 'dir' { $iis.dir() } | |
| default { $iis.ii() }}} | |
| ###################################################################### | |
| function sqlms ($cmd) { switch ($cmd) { 'fe' { $sqlms.fe() } | |
| 'cd' { $sqlms.cd() } | |
| 'dir' { $sqlms.dir() } | |
| default { $sqlms.ii() }}} | |
| ###################################################################### | |
| function vs2010 ($cmd) { switch ($cmd) { 'fe' { $vs2010.fe() } | |
| 'cd' { $vs2010.cd() } | |
| 'dir' { $vs2010.dir() } | |
| default { $vs2010.ii() }}} | |
| ###################################################################### | |
| function vs2013 ($cmd) { switch ($cmd) { 'fe' { $vs2013.fe() } | |
| 'cd' { $vs2013.cd() } | |
| 'dir' { $vs2013.dir() } | |
| default { $vs2013.ii() }}} | |
| ###################################################################### | |
| function vscode ($cmd) { switch ($cmd) { 'fe' { $vscode.fe() } | |
| 'cd' { $vscode.cd() } | |
| 'dir' { $vscode.dir() } | |
| default { $vscode.ii() }}} | |
| ###################################################################### | |
| function subl ($cmd) { switch ($cmd) { 'fe' { $sublime.fe() } | |
| 'cd' { $sublime.cd() } | |
| 'dir' { $sublime.dir() } | |
| default { $sublime.ii() }}} | |
| ###################################################################### | |
| function 7zip ($cmd) { switch ($cmd) { 'fe' { $7zip.fe() } | |
| 'cd' { $7zip.cd() } | |
| 'dir' { $7zip.dir() } | |
| default { $7zip.ii() }}} | |
| ###################################################################### | |
| function fdlr ($cmd) { switch ($cmd) { 'fe' { $fdlr.fe() } | |
| 'cd' { $fdlr.cd() } | |
| 'dir' { $fdlr.dir() } | |
| default { $fdlr.ii() }}} | |
| ###################################################################### | |
| function winmrg ($cmd) { switch ($cmd) { 'fe' { $winmrg.fe() } | |
| 'cd' { $winmrg.cd() } | |
| 'dir' { $winmrg.dir() } | |
| default { $winmrg.ii() }}} | |
| ###################################################################### | |
| function derrik ($cmd) { switch ($cmd) { 'fe' { $derrik.fe() } | |
| 'dir' { $derrik.dir() } | |
| default { $derrik.cd() }}} | |
| ###################################################################### | |
| function temp ($cmd) { switch ($cmd) { 'fe' { $temp.fe() } | |
| 'dir' { $temp.dir() } | |
| default { $temp.cd() }}} | |
| ###################################################################### | |
| function dropbox ($cmd) { switch ($cmd) { 'fe' { $dropbox.fe() } | |
| 'cd' { $dropbox.cd() } | |
| 'dir' { $dropbox.dir() } | |
| default { $dropbox.ii() }}} | |
| ###################################################################### | |
| # browser functions - usage: chrome reddit.com (no argument = 'google.com') | |
| function chrome ( $url = 'google.com' ) { start $chrome.name $url } | |
| function firefox ( $url = 'google.com' ) { start $firefox.name $url } # url not working with firefox :( | |
| function ie ( $url = 'google.com' ) { start $iexplore.name $url } | |
| function safari ( $url = 'google.com' ) { start $safari.name $url } | |
| # opens chrome and goes to url | |
| function gmail { chrome 'gmail.com' } | |
| function stack { chrome 'stackoverflow.com' } | |
| function yt { chrome 'youtube.com' } | |
| function difm { chrome 'di.fm' } | |
| function soundcloud { chrome 'soundcloud.com' } | |
| function github { chrome 'github.com' } | |
| # usage: reddit pcgaming -> opens chrome, goes to www.reddit.com/r/pcgaming | |
| function reddit ($sub) { if ($sub -ne $null) { $sub = 'reddit.com' + '/r/' + $sub; start chrome $sub } else { start chrome 'reddit.com' }} | |
| # usage: google 'food near me' <- optional, opens chrome with optional search param | |
| function google ($str) { if ($str -eq $null) { chrome google.com } else { chrome google.com $str }} | |
| # ssh aliases | |
| set-alias ssh-agent "${env:ProgramFiles(x86)}\git\bin\ssh-agent.exe" | |
| set-alias ssh-add "${env:ProgramFiles(x86)}\git\bin\ssh-add.exe" | |
| # open file explorer to current path | |
| function fe { ii $global:pwd } | |
| # reload profile and clear console | |
| function clr { | |
| . $profile | |
| clear-host | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment