Improved shell directory handling