Skip to content

Instantly share code, notes, and snippets.

@charudatta10
Last active March 26, 2024 15:59
Show Gist options
  • Save charudatta10/9e6c426b99140e3cbecd4f7b9b90b686 to your computer and use it in GitHub Desktop.
Save charudatta10/9e6c426b99140e3cbecd4f7b9b90b686 to your computer and use it in GitHub Desktop.
PowerShell, profile files are scripts that run automatically when you start a PowerShell session. They allow you to customize your environment, load modules, define aliases, and set preferences.
"""
Certainly! Let's delve into the details of **PowerShell profile files**, their relevance in the context of **Git**, and how they can be used effectively for **Gist READMEs**.
## **PowerShell Profile Files**
In PowerShell, profile files are scripts that run automatically when you start a PowerShell session. They allow you to customize your environment, load modules, define aliases, and set preferences. There are different types of profile files, each serving a specific purpose:
1. **`$PROFILE`**: This is the most common profile file. It is specific to the current user and host (console or ISE). You can find it by running `$PROFILE` in your PowerShell session. Common locations include:
- **Current User, Current Host**: `$Home\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1`
- **All Users, Current Host**: `$PsHome\Profile.ps1`
2. **`$PROFILE.AllUsersCurrentHost`**: This profile file applies to all users on the current host.
3. **`$PROFILE.AllUsersAllHosts`**: This profile file applies to all users on all hosts.
## **Customizing Your PowerShell Profile for Git Gist READMEs**
When working with Git Gists (GitHub's lightweight repositories), you can use your PowerShell profile to streamline your workflow. Here's how:
1. **Download a Gist as a ZIP**:
- Visit the Gist you want to work with.
- Click the "Download" button to get a ZIP file containing the Gist's contents.
2. **Customize Your Profile**:
- Copy the `01_PowerShell_common.ps1` file from the downloaded ZIP to your `$PROFILE` location.
- If the Gist contains XML files (e.g., configuration files), copy them to `$PSScriptRoot`.
3. **Local Customizations**:
- Create one or more local customizations in your `$PSScriptRoot`. Name them as desired (e.g., `my_customization.local.ps1`).
4. **Use the Customizations**:
- In your customizations, you can define Git aliases, functions, or any other settings relevant to your Gists.
- For example, you might create a function that uploads a selected text snippet to a Gist directly from your PowerShell session.
## **Benefits of Customizing Your Profile for Gist READMEs**
- **Efficiency**: With customized functions and aliases, you can interact with Gists seamlessly.
- **Consistency**: Your customizations ensure a consistent approach across different Gists.
- **Automation**: Automate tasks like creating new Gists, updating existing ones, or managing snippets.
Remember that your PowerShell profile is a powerful tool. Use it wisely, and tailor it to your specific needs—whether you're working with Git Gists, managing modules, or optimizing your PowerShell environment.
Source:
(1) PowerShell Profile Scripts · GitHub. https://gist.github.com/aggieben/6c5d5c6c7985b506f35030797cd10392.
(2) . https://bing.com/search?q=powershell+profile+file+for+git+gist+readme.
(3) Github: How to embed a gist into README.md? - Stack Overflow. https://stackoverflow.com/questions/11622509/github-how-to-embed-a-gist-into-readme-md.
(4) powershell profile · GitHub. https://gist.github.com/fimusial/111f73bdeffdfa95e497fc2354b23a8b.
(5) My personal PowerShell profile file · GitHub. https://gist.github.com/chadbaldwin/2ae7373ce6eb51c1b05b291c7dee40d8.
(6) undefined. https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/customizing-your-profile/managing-your-profile-readme.
(7) undefined. https://github.com/dfinke/Posh-Gist.
(8) undefined. https://gist.github.com/nisrulz/11c0d63428b108f10c83.js.
(9) undefined. https://gist.github.com/benbalter/5555251.
(10) undefined. https://gist.github.com/fimusial/111f73bdeffdfa95e497fc2354b23a8b.js&quot.
"""
#Variables
$oh_my_posh_theme_path = 'C:\Users\user\AppData\Local\Programs\oh-my-posh\themes\bubblesline.omp.json'
$env:VIRTUAL_ENV_DISABLE_PROMPT = 1
#Aliases
Set-Alias -Name d -Value recycle-bin
Set-Alias -Name v -Value nvim
Set-Alias -Name p -Value python
Set-Alias -Name m -Value more
Set-Alias -Name n -Value nano
Set-Alias -Name j -Value just
Set-Alias -Name l -Value lsd
Set-Alias -Name b -Value bat
Set-Alias -Name s -Value syncthing
#Functions
Function FPY ($python_venv_name)
{
. C:\Users\chaitrali\$python_venv_name\Scripts\Activate.ps1
}
Function FLGD0 ()
{
$var1 = Read-Host "Please Enter Day of the Year";
(Get-Date -Month 1 -Day 1).AddDays($var1-1)
}
Function FLGD1 ()
{
$var1 = Read-Host "Please Enter Day of the Year";
(Get-Date $var1).dayofyear
}
Function FM0()
{
$hash = @{ "Get day of the year for today" = "(Get-Date).dayofyear"; "Get date" = "FLGD0"; "Get day of the year" = "FLGD1"}
$var_fm1 = Menu -MenuItems $hash.keys
Invoke-Expression $hash[$var_fm1]
}
#Commands
Import-Module Terminal-Icons
oh-my-posh init pwsh --config $oh_my_posh_theme_path | Invoke-Expression
Invoke-Expression (& { (zoxide init powershell | Out-String) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment