Giter VIP home page Giter VIP logo

shaynas-powershell-extensions's Introduction

Shayna's PowerShell Extensions (SPSE)

This is my personal PowerShell profile, containing my own extensions and extension loader. The extension loader can be found in spse-init.ps1, which is intended to be imported from your PowerShell profile script (Microsoft.PowerShell_profile.ps1). Inside of spse-init.ps1, an object called SPSEEnv is defined - this object stores the configuration for the extension loader.

The SPSEEnv object is defined like this, and should have its values modified according to where the repository is stored on your computer:

New-Variable -Name SPSEEnv -Value @{
    repositoryDirectory            = [String]"$HOME\Dropbox\Repositories\shaynas-powershell-extensions"
    repositoryExtensionsDirectory  = [String]"$HOME\Dropbox\Repositories\shaynas-powershell-extensions\extensions"
    enabledUserExtensionsDirectory = [String]"$HOME\shaynas-powershell-extensions\enabled-user-extensions\"
    loadedExtensions               = [Array]@()
}

The extension loader recognizes all .ps1 PowerShell scripts within repositoryExtensionsDirectory to be "extensions", and it will consider the extension enabled if a symlink exists within enabledUserExtensionsDirectory that points to that extension. Upon startup, all symlinks within enabledUserExtensionsDirectory that point to .ps1 files inside of repositoryExtensionsDirectory will be imported.

Extensions can be "enabled" or "disabled" using the SPSE_SetExtensionEnabled command, which will create or delete a symlink within enabledUserExtensionsDirectory for the given extension, like this:

SPSE_SetExtensionEnabled Get-Weather.ps1 -Disable

Extensions and their state can be viewed using the SPSE_GetExtensions command, where the -Pretty switch can also be specified to prettify the output.

โžœ SPSE_GetExtensions -Pretty
--------------------------------------------------
[ E ] Encryption-Utilities.ps1
[ E ] Get-PublicIP.ps1
[ E ] Get-Weather.ps1
[ E ] OhMyPosh-Setup.ps1
[ D ] RegistryConsoleFontManager.ps1
[ E ] Set-TitlebarColor.ps1

When the -Pretty switch isn't used, an array of PSCustomObject's is returned, which can have the following methods called on them: .IsEnabled(), .Enable(), .Disable() to be able to query and manage the state of the extensions programmatically.

Additionally, the state of a specific extension can be queried using the SPSE_IsExtensionEnabled command.

If for whatever reason, an extension is deleted from repositoryExtensionsDirectory without being disabled first, any lingering symlinks can be cleaned up using the SPSE_RemoveZombieSymlinks command.

shaynas-powershell-extensions's People

Contributors

psychedelicshayna avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.