There are various issues hooking into this with an alias or a simple bash function, but you can write a little wrapper for a command and stick it in /usr/local/bin
which takes priority in your path.
This is a little trick to create a script and chmod it at the same time.
It'll dump an executable wrapper script in /usr/local/bin/add-apt-repository
.
sudo install -b -m 755 /dev/stdin /usr/local/bin/add-apt-repository << 'EOF'
#!/bin/sh
/usr/bin/add-apt-repository "$@"
apt-get update
EOF
To reverse this, just delete /usr/local/bin/add-apt-repository
.
If you want to do something fruitier (like linking apt-get install
and apt-get update
so you always update before installing), we just need to expand the script to look at the arguments.
sudo install -b -m 755 /dev/stdin /usr/local/bin/apt-get << 'EOF'
#!/bin/sh
if [ "$1" = "install" ] ; then
/usr/bin/apt-get update
fi
/usr/bin/apt-get "$@"
EOF
Though consider that this will run an update before every apt-get install
call. This might sound helpful but could be really tedious in practice.