Skip to content

Profile scripting best practices #38

Description

@rkeithhill

I'm not sure where this belongs or if it even belongs in this repo but... Most of us probably have pretty complex profile scripts. My PSReadline custom configuration alone is over 200 lines. So I've taken to moving those "module-specific" configurations out into a separate file that sits by my profile.ps1 file. It is called "PSReadline_config.ps1" - I've seen this approach with Bash (.bash_aliases). I was thinking something like <ModuleOrDescription>_config.ps1. Then in your profile script you just dot source it in like so:

. $PSScriptRoot\PSReadline_config.ps1

This has made it easier for me to share my PSReadline config with others.

BTW there is probably some best practices around "which" profile scripts to use. I'm old school and use the current user all hosts script and for PSReadline I check against the host name. I should probably use the console's profile Microsoft.PowerShell_profile.ps and ditch the if ($host.Name -eq 'ConsoleHost') check.

Activity

  1. gerane commented on Jun 3, 2016

    @gerane

    I tend to dot source my profiles anyway. I usually keep them in onedrive and then my normal profile just dot sources the onedrive ones. I should probably just investigate using junctions or something instead.

    I do like the idea and naming you have used.

  2. Jaykul commented on Jul 14, 2016

    @Jaykul
    Member

    I can't think where to put this, but it's worth discussing ... and documenting.

  3. rkeithhill commented on Jul 14, 2016

    @rkeithhill
    Author

    I also have one for Posh-git - Posh-Git_config.ps1.

  4. michaeltlombardi commented on Jul 15, 2016

    @michaeltlombardi

    Posh-Git definitely needs one.

    This would make for a lot of utility, especially if people are writing generally-useful things to put in their profile and are releasing them as scripts on the gallery.

  5. locked and limited conversation to collaborators on Jul 22, 2023
  6. converted this issue into a discussion #168 on Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions