Skip to content

rajeshkio/context-aware-shell-aliases

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Context-Aware Shell Aliases

Never forget your shell shortcuts again. Get context-aware reminders based on your current directory.

The Problem

You built dozens of shell aliases. purn to grab Pulumi resource URNs. kgp instead of kubectl get pods. Each one saved keystrokes.

Then you forgot they existed.

Your brain reaches for the long commands under pressure, not the shortcuts you created later.

The Solution

Display relevant shortcuts based on your current directory. Git repo? Show git aliases. Pulumi project? Show Pulumi helpers. Kubernetes context? Show kubectl shortcuts.

cd ~/my-pulumi-project/
💡 Quick shortcuts available:
   Git: ga (add) | gc (commit) | gco (checkout) | gp (push)
   Pulumi: purn <n> | pdelete <n> | pprotected | pfind <term>
   K8s: kg (get) | kgp (pods) | kd (describe)
   Type 'halias' for complete list, 'halias-off' to disable

Quick Start

One-Command Installation

curl -fsSL https://raw.githubusercontent.com/rajeshkio/context-aware-shell-aliases/main/install.sh | bash

Customized Installation

Clone the repo, customize the scripts, then install:

git clone https://github.com/rajeshkio/context-aware-shell-aliases.git
cd context-aware-shell-aliases

# Edit scripts/sample_aliases.sh to add your own shortcuts
# Edit scripts/alias_reminder.sh to customize detection

./install-local.sh

Features

Smart Context Detection

  • Git repositories
  • Kubernetes clusters (kubectl)
  • Pulumi projects
  • Docker projects
  • Terraform configs
  • Node.js projects

Configurable Reminders

  • Always (on every context change)
  • Daily (once per day)
  • Never (manual with halias command)

Zero Performance Impact

  • ~16ms overhead per directory change
  • Intelligent caching for network mounts
  • Early exit when context unchanged

Platform Support

  • bash 4.0+
  • zsh 5.0+
  • macOS and Linux

Usage

After installation, reminders appear automatically when you change directories:

cd my-terraform-project/
💡 Quick shortcuts available:
   Git: ga (add) | gc (commit) | gco (checkout) | gp (push)
   Terraform: tf (terraform) | tfa (apply) | tfp (plan)

Commands

halias          # Show all available shortcuts
halias git      # Show git shortcuts only
halias k8s      # Show Kubernetes shortcuts
halias pulumi   # Show Pulumi shortcuts
halias-off      # Disable reminders
halias-on       # Re-enable reminders

Sample Aliases Included

Git

  • ga → git add
  • gc → git commit
  • gco → git checkout
  • gp → git push
  • gs → git status

Kubernetes

  • k → kubectl
  • kg → kubectl get
  • kgp → kubectl get pods
  • kd → kubectl describe

Pulumi

  • p → pulumi
  • pup → pulumi up
  • purn <n> → Get resource URN
  • pdelete <n> → Remove from state
  • pfind <term> → Search resources

Docker

  • dps → docker ps -a
  • dlogs → docker logs -f
  • dstop → Stop all containers
  • dclean → System prune

Terraform

  • tf → terraform
  • tfa → terraform apply
  • tfp → terraform plan

See all aliases

Customization

Add Your Own Contexts

Edit scripts/alias_reminder.sh to detect new contexts:

# Check for your custom context
if [ -f "your-marker-file" ]; then
    aliases_to_show+=("YourTool: cmd1 (desc) | cmd2 (desc)")
    context_found=true
fi

Update your shell integration in ~/.bashrc or ~/.zshrc:

if [ -f "your-marker-file" ]; then
    current_context="${current_context}yourtool,"
fi

Add Custom Aliases

Edit scripts/sample_aliases.sh:

# Your custom aliases
alias mycommand='your-long-command --with-flags'

Then reinstall:

./install-local.sh

Performance

Benchmarked on three systems:

2019 MacBook Pro (SSD):

  • Overhead: 1.6ms per cd

Linux Workstation (NVMe):

  • Overhead: 1.4ms per cd

Network-Mounted Home:

  • Overhead: 16ms per cd

Detection runs in parallel with your actual directory change, making it imperceptible during normal use.

How It Works

Three components make this system:

  1. Detection Script (~/.alias_reminder.sh): Checks for git repos, Pulumi configs, kubectl access, etc.

  2. Help System (~/.alias_help.sh): Provides the halias command and toggle functions.

  3. Shell Integration: Overrides cd to run detection when context changes.

The system tracks your last context to prevent spam. Moving between subdirectories in the same project won't trigger new reminders.

Uninstalling

Run either installer with the --uninstall flag:

./install.sh --uninstall
# or
./install-local.sh --uninstall

This removes:

  • ~/.alias_reminder.sh
  • ~/.alias_help.sh
  • Integration from your shell config

Your custom aliases remain in your shell config for manual removal if desired.

Real-World Impact

Tracked over three months:

Before:

  • Used full command 147 times
  • Used alias 12 times
  • Adoption: 8%

After:

  • Used full command 23 times
  • Used alias 139 times
  • Adoption: 86%

Time saved: ~45 minutes weekly (39 hours yearly).

The bigger win is reduced cognitive load. No more thinking "what was that jq filter?" or "which kubectl command do I need?" The reminder appears exactly when you need it.

Contributing

Contributions welcome! Areas for improvement:

  • Additional context detection (Go projects, Rust, etc.)
  • More sample aliases for common tools
  • Fish shell support
  • Performance optimizations
  • Better docs

License

MIT

Acknowledgments

Built out of frustration with forgetting my own shortcuts. If you've ever typed the same 60-character command that your 10-character alias replaces, this is for you.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages