Commit 7b95b1c2 authored by Dustin L. Howett's avatar Dustin L. Howett

Move a bunch more stuff into profile.d

parent 29cd10a5
Function Enter-DevelopmentEnvironment {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True)]
[String]
$Name
)
$item = (Get-Item (Split-Path $Profile | Join-Path -ChildPath "Dev\${Name}") -EA SilentlyContinue)
If($null -eq $item) {
$item = (Get-Item (Split-Path $Profile | Join-Path -ChildPath "Dev\${Name}.ps1") -EA SilentlyContinue)
}
If($item -is [System.IO.DirectoryInfo]) {
$Script:path = $item.ToString()
$item = (Get-Item (Join-Path $item -ChildPath dev.ps1) -EA SilentlyContinue)
}
If($null -eq $item) {
Write-Error -Message "Unable to find development environment ${Name}." -Category InvalidArgument
Return
}
$Global:DevEnv = @{
Name = $Name;
Path = $Script:path;
}
$local:newDE = (& $item.ToString())
ForEach($h in $local:newDE.GetEnumerator()) {
$Global:DevEnv[$h.Name] = $h.Value
}
If($Global:DevEnv.Path) {
Set-Location $Global:DevEnv.Path
}
}
New-Alias -Name dev -Value Enter-DevelopmentEnvironment
Import-Module Pscx -arg (Join-Path (Split-Path $Profile) Pscx.UserPreferences.ps1) -EA Ignore
New-Alias -name vs -Value Import-VisualStudioVars
New-Alias -Name Eject -Value Eject-Disk
New-Alias -Name fmt -Value Format-Clang
New-Alias -Name cc -Value Get-ColoredContent
Function Enter-Subshell {
Push-Location -StackName:"SubshellStack" > $Null
$Host.EnterNestedPrompt()
Pop-Location -StackName:"SubshellStack" > $Null
}
New-Alias -Name ss -Value Enter-Subshell
Function Take-TemporaryDirectory {
$TAKE = [System.IO.Path]::Combine($Env:TEMP, "take$(Get-Random)")
New-Item -ItemType:Directory -Path:"$TAKE" -ErrorAction:Stop > $Null
Push-Location -Path:$TAKE -StackName:"TakeStack" > $Null
$Host.EnterNestedPrompt()
Pop-Location -StackName:"TakeStack" > $Null
If($null -Eq (Get-Item (Join-Path -Path:$TAKE -ChildPath:".keep") -ErrorAction:Ignore)) {
Remove-Item -Recurse $TAKE
Write-Warning "Removed temporary directory $TAKE"
} Else {
Get-Item $TAKE
}
}
New-Alias -Name take -Value Take-TemporaryDirectory
......@@ -2,125 +2,9 @@
. ($i.FullName)
}
New-Alias -Name Eject -Value Eject-Disk
New-Alias -Name make -Value mingw32-make
Function Enter-DevelopmentEnvironment {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True)]
[String]
$Name
)
$item = (Get-Item (Split-Path $Profile | Join-Path -ChildPath "Dev\${Name}") -EA SilentlyContinue)
If($null -eq $item) {
$item = (Get-Item (Split-Path $Profile | Join-Path -ChildPath "Dev\${Name}.ps1") -EA SilentlyContinue)
}
If($item -is [System.IO.DirectoryInfo]) {
$Script:path = $item.ToString()
$item = (Get-Item (Join-Path $item -ChildPath dev.ps1) -EA SilentlyContinue)
}
If($null -eq $item) {
Write-Error -Message "Unable to find development environment ${Name}." -Category InvalidArgument
Return
}
$Global:DevEnv = @{
Name = $Name;
Path = $Script:path;
}
$local:newDE = (& $item.ToString())
ForEach($h in $local:newDE.GetEnumerator()) {
$Global:DevEnv[$h.Name] = $h.Value
}
If($Global:DevEnv.Path) {
Set-Location $Global:DevEnv.Path
}
}
New-Alias -Name dev -Value Enter-DevelopmentEnvironment
Function Open-FuzzyMatchedItem {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$Filters
)
Process {
ForEach($filter in $Filters) {
$Items=@((Get-Item $filter -EA Ignore | Select-Object -First 1 -EA Ignore))
If($Items.Length -eq 0) {
$Items=@((Get-ChildItem . -r -EA Ignore | ? { $_.FullName -Like "*$($filter)" }))
}
If($Items.Length -eq 0) {
Write-Error "Failed to find a file matching filter `"$filter`""
Continue
}
$idx = 1
if($Items.Length -gt 1) {
$i = 1;
Write-Host "Multiple matches`n----------------"
ForEach($Item in $Items) {
Write-Host " $(@(" ","*")[$i -eq 1]) [" -nonewline -foregroundcolor White
Write-Host "$($i)" -nonewline -foregroundcolor Yellow
Write-Host "] $($Item.FullName)" -foregroundcolor White
$i++
}
Write-Host " [" -nonewline -foregroundcolor White
Write-Host "q" -nonewline -foregroundcolor Yellow
Write-Host "] Abort" -foregroundcolor White
Write-Host ""
$resp = Read-Host -Prompt "Select one, or press ENTER for default"
if($resp) {
if($resp.ToLower() -eq "q") {
Return
}
Try {
$idx = [int]$resp
} Catch {
$idx = 1
}
}
}
$Items[$idx-1] | Invoke-Item
}
}
}
Function Get-FuzzyChildItem {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$Filters
)
Begin {
$items=@()
}
Process {
ForEach($filter in $Filters) {
$items += (
Get-ChildItem -Recurse -Filter $filter | % {
Add-Member -InputObject $_ -Name Path -Value (Resolve-Path $_.FullName -Relative) -MemberType NoteProperty;
$_
}
)
}
}
End {
$items | Format-Table -Property Mode,LastWriteTime,Length,Path
}
}
New-Alias -Name o -Value Open-FuzzyMatchedItem
New-Alias -Name f -Value Get-FuzzyChildItem
New-Alias -Name fmt -Value Format-Clang
. "$(Split-Path $PROFILE)\Get-InstalledSoftware.ps1"
. "$(Split-Path $PROFILE)\powercat.ps1"
. "$(Split-Path $PROFILE)\ghostbin.ps1"
Import-Module Pscx -arg "$(Split-Path $PROFILE)\Pscx.UserPreferences.ps1"
Function Add-MSHeader {
Param (
......@@ -150,30 +34,5 @@ Function Add-MSHeader {
New-Alias -Name ms -Value Add-MSHeader
New-Alias -name vs -Value Import-VisualStudioVars
Function Take-TemporaryDirectory {
$TAKE = [System.IO.Path]::Combine($Env:TEMP, "take$(Get-Random)")
New-Item -ItemType:Directory -Path:"$TAKE" -ErrorAction:Stop > $Null
Push-Location -Path:$TAKE -StackName:"TakeStack" > $Null
$Host.EnterNestedPrompt()
Pop-Location -StackName:"TakeStack" > $Null
If($null -Eq (Get-Item (Join-Path -Path:$TAKE -ChildPath:".keep") -ErrorAction:Ignore)) {
Remove-Item -Recurse $TAKE
Write-Warning "Removed temporary directory $TAKE"
} Else {
Get-Item $TAKE
}
}
New-Alias -Name take -Value Take-TemporaryDirectory
New-Alias -Name vim -Value gvim
Function Enter-Subshell {
Push-Location -StackName:"SubshellStack" > $Null
$Host.EnterNestedPrompt()
Pop-Location -StackName:"SubshellStack" > $Null
}
New-Alias -Name ss -Value Enter-Subshell
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment