Skip to content

πŸ€”πŸ’­πŸ”„ A PowerShell Module to help remember those aliases you defined once

License

Notifications You must be signed in to change notification settings

codyduong/powershell-alias-tips

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

license PowerShell Gallery PowerShell Gallery

Alias Tips

alias-tips is a PowerShell module dedicated to help remembering those shell aliases you once defined. Inspired by the Oh My Zsh plugin alias-tips

The idea is that you might be too afraid to execute aliases defined because you can't remember them correctly, or just have forgotten about some aliases, or that aliases for your daily commands even exist.

Demonstration

Gif Demonstration of Alias Tips


$ git status
Alias tip: gst
:

$ git checkout -b master
Alias tip: gcb master
:

$ git rebase --interactive master
Alias tip: grb --interactive master
:

$ git rebase -i master
Alias tip: grbi master
:

$ Move-Item foo bar
Alias tip: mv foo bar
:

Installation and Usage

Install the module from the PowerShell Gallery:

Install-Module alias-tips -AllowClobber

Inside your PowerShell profile, import alias-tips.

Import-Module alias-tips

Important

alias-tips should be imported after all your aliases are already declared or imported

Everytime your aliases are updated or changed run Find-AliasTips

Find-AliasTips

This will store a hash of all aliased commands to: $HOME/.alias_tips.hash . It is not recommended to run on every profile load, as this can significantly slow down your profile startup times.

Other functionality:

Configuration

alias-tips can be configured via Environment Variables

Environment Variable Default Value Description
ALIASTIPS_DEBUG $false Enable to show debug messages when processing commands
ALIASTIPS_HASH_PATH [System.IO.Path]::Combine("$HOME", '.alias_tips.hash') File Path to store results from Find-AliasTips
ALIASTIPS_MSG "Alias tip: {0}" Alias hint message for non-virtual terminals
ALIASTIPS_MSG_VT `e[033mAlias tip: {0}`em" Alias hint message for virtual terminals*
ALIASTIPS_FUNCTION_INTROSPECTION $false POTENTIALLY DESTRUCTIVE Function Alias Introspection

* This uses ANSI Escape Codes, for a table of colors. This also means alias-tips supports any other virtual terminal features: blinking/bold/underline/italics.

How It Works

It will attempt to read all functions/aliases set in the current context.

Example Interactions/Limitations

Alias

New-Alias -Name g -Value git

Simple Function Alias

function grbi {
	git rebase -i $args
}

Note

This has a limitation in that alias-tips does not know in this case that -i is equivalent to the --interactive flag.

Function Alias Introspection

function gcm {
	$MainBranch = Get-Git-MainBranch

	git checkout $MainBranch $args
}

Warning

This is potentially destructive behavior

This requires backparsing as it requires running Get-Git-MainBranch (in this example) to get the value of $MainBranch. This backparsing could be a destructive command is not known to alias-tips, and it will run anyways. (ie. rm, git add, etc.)

As a result this behavior is disabled by default.

Set $env:ALIASTIPS_FUNCTION_INTROSPECTION to $true to enable it.

License

Licensed under the MIT License, Copyright Β© 2023-present Cody Duong.

See LICENSE for more information.