Skip to content

Instantly share code, notes, and snippets.

@iwconfig
Created March 7, 2018 02:49
Show Gist options
  • Save iwconfig/a8dc8562d180540800ef5b048c205461 to your computer and use it in GitHub Desktop.
Save iwconfig/a8dc8562d180540800ef5b048c205461 to your computer and use it in GitHub Desktop.
A replace function. Like "[CMD] !!" but replacing the previous command instead if prefixing.
# A replace function. Like "[CMD] !!" but replacing the previous command instead if prefixing.
# Usage: __ [CMD]
function __() {
__=$(history -p \!\!)
[[ "$(echo '$__' | cut -d' ' -f1)" == "__" ]] && history -d $(history | tail -n1 | cut -d' ' -f2)
export __=${__/$(echo $__ | cut -d' ' -f1)/$1}
echo "$__"
$__
history -s "$__"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment