Created
June 9, 2021 13:55
-
-
Save jamesthomasonjr/43a887abf6db68f67559502889324990 to your computer and use it in GitHub Desktop.
Powershell profile
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 touch { | |
param([string] $file) | |
if(test-path $file) { | |
Set-ItemProperty -Path $file -Name LastWriteTime -Value (get-date) | |
} else { | |
Set-Content -Path ($file) -Value ($null); | |
} | |
<# | |
.SYNOPSIS | |
Duplicates the "touch" functionality of unix. | |
.DESCRIPTION | |
Duplicates the "touch" functionality of unix. | |
Creates an empty file, or updates the timestamp if the file already exists. | |
.PARAMETER file | |
Specifies the file to create/update. | |
#> | |
} | |
function mod { | |
param( | |
[string] $module, | |
[scriptblock] $before = $null, | |
[scriptblock] $after = $null, | |
[bool] $if = $true | |
) | |
if ($if -ne $true) { | |
return | |
} | |
if ($before -ne $null) { | |
. $before | |
} | |
if (-not(Get-Module -ListAvailable -Name $module)) { | |
"Installing ${module}..." | |
Install-Module $module -Scope CurrentUser | |
} | |
Import-Module $module | |
if ($after -ne $null) { | |
. $after | |
} | |
<# | |
.SYNOPSIS | |
Installs and/or loads a given module. | |
.DESCRIPTION | |
Installs and/or loads a given module. | |
Takes a module to install/load, and code to run before/after, and a conditional of when to load. | |
.PARAMETER module | |
Specifies the module to install/load. | |
.PARAMETER before | |
Specifies code to run before installing/loading. | |
.PARAMETER after | |
Specifies code to run after installing/loading. | |
.PARAMETER if | |
Specifies if the module should be installed/loaded. | |
#> | |
} | |
function script { | |
param( | |
[string] $name, | |
[scriptblock] $before = $null, | |
[scriptblock] $after = $null | |
) | |
if ($before -ne $null) { | |
. $before | |
} | |
if (-not(Get-Command -ListAvailable -CommandType ExternalScript -Name $name)) { | |
"Installing ${name}..." | |
Install-Script -Name $name | |
} | |
if ($after -ne $null) { | |
. $after | |
} | |
<# | |
.SYNOPSIS | |
Installs a given script. | |
.DESCRIPTION | |
Installs a given script. | |
Takes a script to install and code to run before/after. | |
.PARAMETER name | |
Specifies the script to. | |
.PARAMETER before | |
Specifies code to run before installing/loading. | |
.PARAMETER after | |
Specifies code to run after installing/loading. | |
#> | |
} | |
Set-Alias which Get-Command | |
script ` | |
-name pwshfetch-test-1 | |
mod ` | |
-module PSReadLine ` | |
-if ($host.Name -eq 'ConsoleHost') | |
mod ` | |
-module posh-git | |
mod ` | |
-module oh-my-posh ` | |
-before { $env:POSH_GIT_ENABLED = $true} ` | |
-after { Set-PoshPrompt -Theme powerlevel10k_rainbow } | |
pwshfetch-test-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment