Skip to content

Instantly share code, notes, and snippets.

@JeffJacobson
Last active June 21, 2024 01:15
Show Gist options
  • Save JeffJacobson/1d787776f34fe0d282b17188d86ced36 to your computer and use it in GitHub Desktop.
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
# 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