Skip to content

Instantly share code, notes, and snippets.

@stormbrew
Created February 20, 2014 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stormbrew/9124044 to your computer and use it in GitHub Desktop.
Save stormbrew/9124044 to your computer and use it in GitHub Desktop.
# Run this to get a default autocomplete that, if you press
# tab on an empty prompt it will expand to the first term of
# the last command you ran.
#
# Inspired by http://thechangelog.com/interactive-shell-git/
# where I don't really want to have to go in and out of a mode
# when I don't necessarily know it'll be worth it, but being
# able to skip typing git every command would be nice. This way
# you can go (using their example):
#
# git status
# <t> add .
# <t> commit -m "Ship it!"
# <t> push
#
# This is actually fewer total keystrokes than the example given,
# and I didn't have to predict how many commands I'd run to decide
# whether or not to do it.
#
# Plus it works with any command.
function _auto_last_cmd() {
COMPREPLY=$(history -- -1 | awk '{ print $2 }')
}
complete -F _auto_last_cmd -E
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment