Skip to content

Instantly share code, notes, and snippets.

@Rudxain
Created July 21, 2025 14:28
Show Gist options
  • Save Rudxain/c8a9f9c91e8a43490a0c5df29c107de6 to your computer and use it in GitHub Desktop.
Save Rudxain/c8a9f9c91e8a43490a0c5df29c107de6 to your computer and use it in GitHub Desktop.
Function that renames a shell alias. Doesn't handle quotes properly
realias() {
if [ $# -ne 2 ]; then
echo "Usage: realias old_alias new_alias"
return 1
fi
local o
o="$(alias -- "$1")" || {
printf %s "$o"
return 1
}
unalias -- "$1"
alias -- "$2"="$(printf %s "$o" | sed -E "s/^alias $1=['\"](.*)['\"]$/\1/")"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment