Last active
June 24, 2020 22:15
-
-
Save WardBrian/68c8296f9a84d1ecb50057f68b7b8dcb to your computer and use it in GitHub Desktop.
Brian's Powershell Customization
This file contains 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
<# | |
.Synopsis | |
Opens explorer in the current working directory | |
#> | |
Function Start-FileExplorer { | |
Start-Process explorer.exe . | |
} | |
<# | |
.Synopsis | |
Opens Emacs in wsl for the specified file | |
.Parameter File | |
The file to open (optional) | |
#> | |
Function Start-Emacs{ | |
param($file) | |
if ($file -ne $null) { | |
$url = Split-Path $file -Leaf | |
if ($url -ne $null) { | |
wsl.exe -e emacs $url | |
} else { | |
wsl.exe -e emacs $file | |
} | |
} else { | |
wsl.exe -e emacs | |
} | |
} | |
<# | |
.Synopsis | |
Opens Github of the current repo if inside one | |
.Description | |
Opens the Github page of the current repo. Requires git to be a valid command. Will do nothing if not a github remote or not in a git repo. | |
#> | |
Function Open-Github{ | |
$remote = git config remote.origin.url | |
if ($remote -ne $null -and $remote -match '.+\.com:(?<user>.*)/(?<repo>.*)\.git') { | |
$url = "https://github.com/" | |
$url += $Matches.user | |
$url += "/" | |
$url += $Matches.repo | |
Start-Process explorer.exe $url | |
} | |
} | |
Export-ModuleMember -Function Start-FileExplorer | |
Export-ModuleMember -Function Start-Emacs | |
Export-ModuleMember -Function Open-Github | |
#aliases | |
New-Alias -Name "view" -Value "Start-Process" -Description "View a file" | |
New-Alias -Name "ex." -Value "Start-FileExplorer" -Description "Open explorer here" | |
New-Alias -Name "open" -Value "Start-FileExplorer" -Description "Open explorer here" | |
New-Alias -Name "edit" -Value "Start-Emacs" -Description "Starts WSL-Emacs" | |
New-Alias -Name "gh" -Value "Open-Github" -Description "Open git of current repo" | |
Export-ModuleMember -Alias * -Function * |
This file contains 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
# powershell core | |
# prompt customization | |
$color = "DarkYellow" | |
$arrow = "White" | |
. $HOME\Documents\PowerShell\Prompt.ps1 | |
# load custom functions | |
Import-Module -Name $HOME\Documents\PowerShell\CustomFunctions |
This file contains 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
function Prompt { | |
Write-Host -NoNewline "PS [" -ForegroundColor $color | |
Write-Host -NoNewline "lego@Battletop " -ForegroundColor $color | |
Write-Host -NoNewline (Split-Path -Path (Get-Location).Path -Leaf) -ForegroundColor Blue | |
Write-Host -NoNewline "] " -ForegroundColor $color | |
Write-Host -NoNewline ">" -ForegroundColor $arrow | |
return " " | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment