---
title: "Alias in ZSH with completion"
date: 2012-08-08
url: "http://travisjeffery.com/alias-in-zsh-with-completion/"
tags: ["zsh"]
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://travisjeffery.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Alias in ZSH with completion

I use git in a terminal all day, every day. 3 characters adds up if you type them enough, `g i t`, so let's shorten what we have to type.

You shorten a command by making a shorter alias. So I alias `g` to `git`:

    alias g=git

I like terminal commands with completion, especially a command like git with a many, long arguments. Aliases do not automatically assume the original command's completion. Here's how we add completion to our alias:

    compdef g=git

And boom! You can do `g st<TAB>` to complete `status`. The `compdef` makes the g alias complete as if ZSH was completing git instead.

Now I git away by typing `g`.

