I have access to a couple of remote accounts, which I mount via sshfs in subdirs of $HOME/SSHFS. In order to remind me that I'm not working with local files, I have set $PROMPT_COMMAND to a function prmt_cmd, where I set a different $PS1 if $PWD matches $HOME/SSHFS*. Now, to add a little extra protection, I'd like to add the -i flags automatically to the rm, mv and cp commands whenever I'm in a subdir of $HOME/SSHFS. So I ended up with something like
function prmt_cmd () {
if [[ $PWD == $HOME/SSHFS* ]] ; then
PS1=some prompt
alias rm='rm -I'
alias mv='mv -i'
alias cp='cp -i'
else
# Reset the PS1, remove aliases
PS1=my default prompt
unalias rm mv cp
fi
}
(In the actual definition, I do some other stuff, but this is irrelevant.) However, unalias complains when the aliases do not exist, meaning that I get three error messages before each prompt when I'm not in SSHFS/*. unalias doesn't seem to have a switch to silence it. So my question is: Is there a better way to achieve what I want? Maybe I'm simply Doing It (Completely) Wrong.
In case it's relevant, $BASH_VERSION = 4.1.5(1)-release on Ubuntu 10.10.