#NEWLINE# def format_path( pathname ) : #NEWLINE# #INDENT# "\n    Shorten a pathname to make it more human friendly.\n\n    :param pathname: An absolute pathname (a string).\n    :returns: The pathname with the user's home directory abbreviated.\n\n    Given an absolute pathname, this function abbreviates the user's home\n    directory to ``~/`` in order to shorten the pathname without losing\n    information. It is not an error if the pathname is not relative to the\n    current user's home directory.\n\n    Here's an example of its usage:\n\n    >>> from os import environ\n    >>> from os.path import join\n    >>> vimrc = join(environ['HOME'], '.vimrc')\n    >>> vimrc\n    '/home/peter/.vimrc'\n    >>> from humanfriendly import format_path\n    >>> format_path(vimrc)\n    '~/.vimrc'\n    " #NEWLINE# pathname = os . path . abspath ( pathname ) #NEWLINE# home = os . environ . get ( 'HOME' ) #NEWLINE# if home : #NEWLINE# #INDENT# home = os . path . abspath ( home ) #NEWLINE# if pathname . startswith ( home ) : #NEWLINE# #INDENT# pathname = os . path . join ( '~' , os . path . relpath ( pathname , home ) ) #NEWLINE# #UNINDENT# #UNINDENT# return pathname