Last active
June 21, 2024 01:15
-
-
Save JeffJacobson/1d787776f34fe0d282b17188d86ced36 to your computer and use it in GitHub Desktop.
Profile that imports modules and sets up programs ONLY IF THEY ARE AVAILABLE
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
# Tests if a command exists. | |
function commandExists($commandName) { | |
return $null -ne (Get-Command $commandName -ErrorAction SilentlyContinue) | |
} | |
# Tests to see if a module is installed on the computer. | |
function moduleExists($moduleName) { | |
return $null -ne (Get-Module $moduleName -ListAvailable) | |
} | |
# Import posh-git only if this is a git repo | |
if ((moduleExists posh-git) -and (commandExists git) -and (git rev-parse --is-inside-work-tree)) { | |
Import-Module posh-git | |
} | |
if (commandExists oh-my-posh) { | |
oh-my-posh init pwsh | Invoke-Expression | |
oh-my-posh completion powershell | Out-String | Invoke-Expression | |
} | |
if (moduleExists Terminal-Icons) { | |
Import-Module -Name Terminal-Icons | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment