function shorten_path
	if test -z $argv[2]
		echo $argv[1] | sed -e "s#$HOME#~#g" | sed -e 's#\\(\\.\\?[^/]\\{1\\}\\)[^/]*/#\\1/#g'
	else
		echo $argv[1] | sed -e "s#$argv[2]#$argv[3]#g" | sed -e 's#\\(\\.\\?[^/]\\{1\\}\\)[^/]*/#\\1/#g'
	end
end

function shorten_path
	if test (count $argv) -lt 3
		echo $argv[1] | sed -e "s#$HOME#~#g" | sed -e 's#\\(\\.\\?[^/]\\{1\\}\\)[^/]*/#\\1/#g'
	else
		echo $argv[1] | sed -e "s#$argv[2]#$argv[3]#g" | sed -e 's#\\(\\.\\?[^/]\\{1\\}\\)[^/]*/#\\1/#g'
	end
end

Use count to check if enough arguments are given
Use count to check if enough arguments are given

The old method gave errors about expanding arguments

wilfriedvanasten/miscvar,wilfriedvanasten/miscvar,wilfriedvanasten/miscvar