Q:

Can I run a command after the user uses Ctrl-C to kill a command? 

So at my position we use a shared set of aliases to do builds.   Something like...
alias 'build'='cd $BUILD_ROOT; m; cp ...; cp...; deploy; deploy; deploy; cd -'

This is super irritating because the make command takes about 3 minutes and I usually realize I missed something, hit Ctrl-C, and then immediately run build again.   This leaves me in a directory I don't care to be in, with a painful path to retype. 
What I'd really like is something like...
alias 'betterbuild'='pushd .;  build; even-if-the-user-cancelled popd'

Is there a way to do this? 

A:

You may be able to use a subshell. 
alias build='( cd $BUILD_ROOT; m; cp ...; cp...; deploy; deploy; deploy; )'

In the above example, cd $BUILD_ROOT changes the current working directory of
the subshell, but not the interactive shell that calls the alias.  For a generic
case, you can use a subshell and an exit trap. 
alias build='( cleanup() { do; cleanup; }; trap cleanup EXIT; cd $BUILD_ROOT; m; cp ...; cp...; deploy; deploy; deploy; )'

Do reconsider using a script though.  The above example would look much cleaner
in a script.  Scripts are interpreted in their own shell instances.  The subshell
syntax would not be necessary in a script. 
You mentioned in a comment that scripts depend on your alias.  This suggests
that you are sourcing your scripts instead of executing them, which is
generally a bad practice.  Also, you mentioned that there are aliases that
depend on your alias.  You can use scripts within aliases. 

A:

Well, I was going to say make it a script, because aliases aren't really meant to do complex things like this and scripts are meant for more-complex or longer-running tasks.  Aliases are basically meant to map one command to another, for example to provide default parameters to a command that doesn't support that natively. 
However, since you stated in a comment that you want to keep this an alias, we'll have to figure out how to do what you want within the boundaries of an alias. 
The natural choice then becomes to launch a subshell from within the alias.  For example:
~$ alias xyz1='( cd ~/tmp; sleep 10; cd ~ )'
~$ alias xyz2='cd ~/tmp; sleep 10; cd ~'
~$ xyz2
^C
~/tmp$ cd
~$ xyz1
^C
~$

This changes the working directory only within the subshell, which exits when either the alias finishes executing normally, or is aborted e.g. through Ctrl+C.

