Skip to content

Commit 1498bb2

Browse files
committed
[pwsh profile] Split profile scripts per function.
1 parent 6533c38 commit 1498bb2

File tree

9 files changed

+97
-100
lines changed

9 files changed

+97
-100
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2023 Matthias Wolf, Mawosoft.
2+
3+
<#
4+
.SYNOPSIS
5+
Lists all Powershell profile paths and if they exist.
6+
.OUTPUTS
7+
Objects with profile infos
8+
#>
9+
function Get-Profile {
10+
[CmdletBinding()]
11+
[Alias('gpr')]
12+
[OutputType([psobject])]
13+
param()
14+
15+
foreach ($scope in ('AllUsersAllHosts', 'AllUsersCurrentHost', 'CurrentUserAllHosts', 'CurrentUserCurrentHost')) {
16+
[pscustomobject]@{
17+
Scope = $scope
18+
Path = $PROFILE.$($scope)
19+
Exists = Test-Path -Path $PROFILE.$($scope) -PathType Leaf
20+
}
21+
}
22+
}

PowerShellProfile/profileCommon.ps1 renamed to PowerShell/Profile/Common/Import-BatchEnvironment.ps1

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
# Copyright (c) 2023 Matthias Wolf, Mawosoft.
22

3-
<#
4-
.SYNOPSIS
5-
Lists all Powershell profiles and tests if they exist.
6-
.OUTPUTS
7-
[PSObject[]] with profile infos
8-
#>
9-
function global:Get-Profile {
10-
[CmdletBinding()]
11-
[OutputType([psobject[]])]
12-
param()
13-
14-
foreach ($scope in ('AllUsersAllHosts', 'AllUsersCurrentHost', 'CurrentUserAllHosts', 'CurrentUserCurrentHost')) {
15-
[pscustomobject]@{
16-
Scope = $scope
17-
Path = $PROFILE.$($scope)
18-
Exists = Test-Path -Path $PROFILE.$($scope) -PathType Leaf
19-
}
20-
}
21-
}
22-
233
<#
244
.SYNOPSIS
255
# Invokes a batch file (.bat, .cmd) and imports the environment variables it has set.
@@ -29,7 +9,8 @@ function global:Get-Profile {
299
- preserve working dir, psmodulepath
3010
- Batch parameters and other goodies
3111
#>
32-
function global:Import-BatchEnvironment {
12+
function Import-BatchEnvironment {
13+
[CmdletBinding()]
3314
param (
3415
# The batch file to run
3516
[Parameter(Mandatory)]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2023 Matthias Wolf, Mawosoft.
2+
3+
<#
4+
.SYNOPSIS
5+
Clears the MSBuild environment variables for binlog auto-generation
6+
#>
7+
function Clear-BinlogEnvironment {
8+
param()
9+
10+
$env:MSBuildDebugEngine = $null
11+
$env:MSBUILDLOGTASKINPUTS = $null
12+
$env:MSBUILDTARGETOUTPUTLOGGING = $null
13+
$env:MSBUILDLOGIMPORTS = $null
14+
$env:MSBUILDLOGALLENVIRONMENTVARIABLES = $null
15+
$env:MSBUILDDEBUGPATH = $null
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2023 Matthias Wolf, Mawosoft.
2+
3+
<#
4+
.SYNOPSIS
5+
Imports the VsDevCmd environment variables
6+
#>
7+
function Import-VsDevCmd {
8+
[CmdletBinding()]
9+
[Alias('ipvsd')]
10+
param()
11+
Import-BatchEnvironment (Get-Alias 'vsdevcmd').Definition
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2023 Matthias Wolf, Mawosoft.
2+
3+
<#
4+
.SYNOPSIS
5+
Sets MSBuild environment variables to auto-generate binlogs
6+
#>
7+
function Set-BinlogEnvironment {
8+
param(
9+
# Binlog will include all environment variables, not just used ones.
10+
[switch]$LogAllEnvVars,
11+
12+
# Directory path to store the binlogs, defaults to .\MSBuild_Logs
13+
[ValidateNotNullOrEmpty()]
14+
[string]$Path
15+
)
16+
17+
$env:MSBuildDebugEngine = 1
18+
# Fix incomplete binlogs in MSBuild <=17.3.x. See https://github.com/mawosoft/Mawosoft.Extensions.BenchmarkDotNet/issues/146
19+
$env:MSBUILDLOGTASKINPUTS = 1
20+
$env:MSBUILDTARGETOUTPUTLOGGING = 'true'
21+
$env:MSBUILDLOGIMPORTS = 1
22+
# PowerShell 5.1 compat: $bool ? 'yes' : 'no' --> if ($bool) { 'yes' } else { 'no' }
23+
$env:MSBUILDLOGALLENVIRONMENTVARIABLES = if ($LogAllEnvVars) { 'true' } else { $null }
24+
$env:MSBUILDDEBUGPATH = if ($Path) { $Path } else { $null }
25+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2023 Matthias Wolf, Mawosoft.
2+
3+
# dotnet Tab completion
4+
# See https://learn.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete
5+
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
6+
param($commandName, $wordToComplete, $cursorPosition)
7+
dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object {
8+
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
9+
}
10+
}
11+
12+
# Visual Studio aliases
13+
New-Alias -Name 'vstudio' -Value (Join-Path $env:ProgramFiles 'Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe')
14+
New-Alias -Name 'vsdevcmd' -Value (Join-Path $env:ProgramFiles 'Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat')
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2023 Matthias Wolf, Mawosoft.
2+
3+
# VirtualBox aliases
4+
5+
New-Alias -Name 'vbi' -Value (Join-Path $env:VBOX_MSI_INSTALL_PATH 'vbox-img.exe')
6+
New-Alias -Name 'vbm' -Value (Join-Path $env:VBOX_MSI_INSTALL_PATH 'VBoxManage.exe')

PowerShellProfile/profileDeveloper.ps1

Lines changed: 0 additions & 71 deletions
This file was deleted.

PowerShellProfile/profileVBoxHost.ps1

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)