Skip to content

Maheswara660/Powershell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PowerShell Core Profile & Performance Optimization Suite

An enterprise-ready PowerShell Core profile customization framework. This suite transforms PowerShell Core into a high-performance, developer-friendly shell with professional themes, terminal iconography, and Unix-equivalent utilities. It features an asynchronous startup sequence to guarantee sub-second interactive load times.


πŸ“· Showcase

Here is an image, how the finished config looks like, but this can be easily changed, via OhMyPosh. However, this preview is not so meaningful, as most of the visual configuration is done by OhMyPosh:

PowerShell Customization Showcase


πŸ—οΈ Architecture & Startup Lifecycle

PowerShell profiles often suffer from slow startup times due to heavy imports and check sequences. This project solves that via Asynchronous / Deferred Initialization.

sequenceDiagram
    autonumber
    actor User as User
    participant Host as PWSH Host
    participant Profile as Microsoft.PowerShell_profile.ps1
    participant Runspace as Background Runspace
    participant Config as pwsh_custom_config.yml
    
    User->>Host: Open Terminal
    Host->>Profile: Execute Profile Script
    Profile->>Config: Check cached dependency state
    Note over Profile,Config: Fast path (cached True): Skip Winget/NuGet checks
    Profile->>Host: Immediately load Oh My Posh & Terminal Icons
    Host->>User: Render Interactive Prompt (<0.8s)
    
    rect rgb(240, 240, 240)
        Note right of Profile: Asynchronous Deferred Load
        Profile->>Runspace: Spawn Background Runspace
        Runspace->>Runspace: Dot-source functions.ps1 (Unix utilities)
        Runspace->>Runspace: Run BackgroundTasks (Update checks)
    end
Loading

1. Minimal Initial Load (Foreground)

  • Checks the local cache configuration (pwsh_custom_config.yml).
  • If dependencies are missing, redirects execution to installer.ps1 in the foreground.
  • Imports Terminal-Icons and initializes oh-my-posh with the configured theme.
  • Renders the prompt immediately for the user.

2. Deferred Loading (Background Runspace)

  • Spawns a background PowerShell runspace ([runspacefactory]) to avoid blocking the user input thread.
  • Loads custom Unix-like aliases and helper scripts (functions.ps1).
  • Executes background checks (powershell_helper.ps1) to verify engine updates (via winget) and download updated scripts from GitHub asynchronously.

πŸ“‚ Project Structure

This repository contains the following core files:

.
β”œβ”€β”€ LICENSE                          # Project license (GNU GPL v3)
β”œβ”€β”€ Microsoft.PowerShell_profile.ps1 # Primary profile entry point and configuration header
β”œβ”€β”€ README.md                        # Documentation and reference manual
β”œβ”€β”€ assets/
β”‚   └── preview.png                  # Showcase image of the customized prompt
β”œβ”€β”€ functions.ps1                    # Main script file defining Unix-like utilities and aliases
β”œβ”€β”€ installer.ps1                    # Automated bootstrap and dependency installer
└── powershell_helper.ps1            # Background worker script managing engine updates and cache syncing

✨ Features

  • Blazing Fast Startup: Asynchronous runspace loading ensures a responsive prompt in less than a second.
  • Oh My Posh Prompt Integration: Customizable prompts with Git branch indicators, exit codes, and resource metrics.
  • Terminal Icons: Enhances files and folders listings with visual glyphs (Nerd Fonts).
  • Silent Background Updates: Automatically checks for new PowerShell Core releases and upgrades them via Windows Package Manager (winget).
  • Offline Reliability: Caches functions and settings locally for full offline access.
  • Elevated Execution: Optional gsudo configuration for inline elevation matching Unix sudo.

πŸš€ Installation & Quick Start

Automated Installation

To configure your profile automatically, open a PowerShell console and execute the following bootstrap script:

iex (iwr "https://raw.githubusercontent.com/Maheswara660/Powershell/main/Microsoft.PowerShell_profile.ps1").Content

Manual Installation

  1. Clone this repository to your computer:
    git clone https://github.com/Maheswara660/Powershell.git
  2. Place the repository folder in your home directory or custom location.
  3. Edit your PowerShell profile file (check path by running $PROFILE in your terminal) and append the following block:
    # BEGIN Powershell v1.0.0
    if (Test-Path (Join-Path -Path $env:USERPROFILE -ChildPath "Powershell\Microsoft.PowerShell_profile.ps1")) {
        . (Join-Path -Path $env:USERPROFILE -ChildPath "Powershell\Microsoft.PowerShell_profile.ps1")
    } else {
        iex (iwr "https://raw.githubusercontent.com/Maheswara660/Powershell/main/Microsoft.PowerShell_profile.ps1").Content
    }
    # END Powershell v1.0.0
  4. Restart your terminal. The profile will automatically download and install required dependencies (FiraCode Nerd Font, Oh My Posh, modules) on the first run.

πŸ› οΈ Configuration

Custom parameters are stored in ~/Powershell/pwsh_custom_config.yml. This YAML file caches the installation status of key components to expedite subsequent startup runs:

Configuration Key Type Description
Terminal-Icons_installed Boolean (True/False) Status of the Terminal-Icons module.
Powershell-Yaml_installed Boolean (True/False) Status of the Powershell-Yaml module.
PoshFunctions_installed Boolean (True/False) Status of the PoshFunctions utility module.
FiraCode_installed Boolean (True/False) Status of the FiraCode Nerd Font installer.
ohmyposh_installed Boolean (True/False) Status of the Oh My Posh prompt engine.
vscode_installed Boolean (True/False) Indicates if VS Code integration is configured.

🐚 Command Reference Table

This profile imports custom aliases and helper functions that provide a familiar Unix command line environment on Windows:

Unix Command PowerShell Equivalent / Custom Implementation Description
cd Set-Location Changes the current working directory.
ls Get-ChildItem Lists directory contents.
ll Custom Get-ChildItem wrapper Lists files only (excluding directories) in the current directory.
dirs Custom dirs function Performs a recursive file search (dir /s /b equivalent).
grep Select-String wrapper Searches for patterns inside text files recursively or via pipeline.
sed Custom replace helper Performs simple stream-editing to replace target text within a file.
touch Custom touch function Creates an empty file or updates the access/modification timestamps of an existing file.
unzip Expand-Archive wrapper Extracts zip archives directly in the working directory.
du Custom directory measure Displays human-readable file sizes and counts recursively.
df Get-Volume wrapper Displays disk space usage statistics.
top Interactive CPU/Handle Monitor Launches an interactive process explorer that updates dynamically.
uptime Custom uptime calculator Calculates and displays system online duration.
which Get-Command lookup Resolves the absolute executable/command path.
export env: provider Sets environment variables.
pgrep Get-Process Searches for running processes by name.
pkill Stop-Process Stops or terminates running processes by name.
head Get-Content -Head wrapper Displays the first N lines of a file (default: 10).
tail Get-Content -Tail wrapper Displays the last N lines of a file (default: 10).
md5 Get-FileHash -Algorithm MD5 Calculates MD5 checksum for files.
sha1 Get-FileHash -Algorithm SHA1 Calculates SHA-1 checksum for files.
sha256 Get-FileHash -Algorithm SHA256 Calculates SHA-256 checksum for files.
ssh-copy-key Custom SSH script Copies the default public key (id_ed25519.pub) to a remote host.
reboot Restart-Computer -Force Reboots the system immediately.
poweroff Stop-Computer -Force Shuts down the system immediately.
cd... Set-Location ..\.. Moves up two directory levels.
cd.... Set-Location ..\..\.. Moves up three directory levels.

Interactive process monitor (top) Shortcuts:

  • c: Sort processes by CPU usage.
  • h: Sort processes by Handles count.
  • n: Sort processes by Non-Paged Memory (NPM).
  • p: Sort processes by Paged Memory (PM).
  • w: Sort processes by Working Set (WS).
  • q: Quit the interactive monitor.

🎨 Customization & Personalization

Forking and Base Variables

To customize this project for your own GitHub repository, modify the header variables in Microsoft.PowerShell_profile.ps1:

$githubUser = "Maheswara660" # Update to your GitHub username
$githubRepo = "Powershell"   # Update to your repository name
$name = "YourName"           # Welcoming message name

Prompt Themes

The default profile configures the montys.omp.json theme. You can swap this out by updating $OhMyPoshConfigFileName to any of the official Oh My Posh themes, or customize it locally in the installation directory.


🀝 Contributing

Contributions, bug reports, and enhancements are welcome! Please open an issue or submit a pull request on the repository.


πŸ“œ License

This project is licensed under the GNU General Public License v3.

Developed by Maheswara660 with ❀️

About

πŸš€ A high-performance PowerShell Core customization framework. Features asynchronous (deferred) startup loading, Oh My Posh prompt integration, Terminal Icons, and Unix-like command aliases.

Topics

Resources

License

Stars

Watchers

Forks

Contributors