From f89209737eb47c9b3f7b25556428ca3f9d8a9f1b 2007-08-22 20:21:07 From: vivainio Date: 2007-08-22 20:21:07 Subject: [PATCH] prompt and set_term_title now include drive letter and / characters on win32 --- diff --git a/IPython/Magic.py b/IPython/Magic.py index a6bfd5d..27abbdc 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 2649 2007-08-21 18:19:20Z vivainio $""" +$Id: Magic.py 2659 2007-08-22 20:21:07Z vivainio $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -2496,9 +2496,7 @@ Defaulting color scheme to 'NoColor'""" os.chdir(os.path.expanduser(ps)) if self.shell.rc.term_title: #print 'set term title:',self.shell.rc.term_title # dbg - ttitle = ("IPy:" + ( - os.getcwd() == '/' and '/' or \ - os.path.basename(os.getcwd()))) + ttitle = 'IPy ' + abbrev_cwd() platutils.set_term_title(ttitle) except OSError: print sys.exc_info()[1] @@ -2511,7 +2509,7 @@ Defaulting color scheme to 'NoColor'""" else: os.chdir(self.shell.home_dir) if self.shell.rc.term_title: - platutils.set_term_title("IPy:~") + platutils.set_term_title("IPy ~") cwd = os.getcwd() dhist = self.shell.user_ns['_dh'] dhist.append(cwd) diff --git a/IPython/Prompts.py b/IPython/Prompts.py index 37e9c58..9d2d9e1 100644 --- a/IPython/Prompts.py +++ b/IPython/Prompts.py @@ -2,7 +2,7 @@ """ Classes for handling input/output prompts. -$Id: Prompts.py 2601 2007-08-10 07:01:29Z fperez $""" +$Id: Prompts.py 2659 2007-08-22 20:21:07Z vivainio $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez @@ -309,10 +309,15 @@ class BasePrompt(object): $HOME is always replaced with '~'. If depth==0, the full path is returned.""" - cwd = os.getcwd().replace(HOME,"~").split(os.sep) + full_cwd = os.getcwd() + cwd = full_cwd.replace(HOME,"~").split(os.sep) if '~' in cwd and len(cwd) == depth+1: depth += 1 - out = os.sep.join(cwd[-depth:]) + drivepart = '' + if sys.platform == 'win32' and len(cwd) > depth: + drivepart = os.path.splitdrive(full_cwd)[0] + out = drivepart + '/'.join(cwd[-depth:]) + if out: return out else: diff --git a/IPython/genutils.py b/IPython/genutils.py index 5dbbc7e..1f0ad54 100644 --- a/IPython/genutils.py +++ b/IPython/genutils.py @@ -5,7 +5,7 @@ General purpose utilities. This is a grab-bag of stuff I find useful in most programs I write. Some of these things are also convenient when working at the command line. -$Id: genutils.py 2602 2007-08-12 22:45:38Z fperez $""" +$Id: genutils.py 2659 2007-08-22 20:21:07Z vivainio $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez. @@ -300,6 +300,19 @@ def system(cmd,verbose=0,debug=0,header=''): if not debug: stat = os.system(cmd) return stat +def abbrev_cwd(): + """ Return abbreviated version of cwd, e.g. d:mydir """ + cwd = os.getcwd() + drivepart = '' + if sys.platform == 'win32': + if len(cwd) < 4: + return cwd + drivepart = os.path.splitdrive(cwd)[0] + return (drivepart + ( + cwd == '/' and '/' or \ + os.path.basename(cwd))) + + # This function is used by ipython in a lot of places to make system calls. # We need it to be slightly different under win32, due to the vagaries of # 'network shares'. A win32 override is below. @@ -326,9 +339,9 @@ def shell(cmd,verbose=0,debug=0,header=''): sys.stdout.flush() if not debug: - platutils.set_term_title("IPy:" + cmd) + platutils.set_term_title("IPy " + cmd) os.system(cmd) - platutils.set_term_title("IPy:" + os.path.basename(os.getcwd())) + platutils.set_term_title("IPy " + abbrev_cwd()) # override shell() for win32 to deal with network shares if os.name in ('nt','dos'): diff --git a/doc/ChangeLog b/doc/ChangeLog index d37a567..2342c92 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -13,6 +13,10 @@ * clearcmd.py: shadow history compression & erasing * envpersist.py, history.py: %env (sh profile only), %hist completers + + * genutils.py, Prompts.py, Magic.py: win32 - prompt (with \yDEPTH) and + term title now include the drive letter, and always use / instead of + os.sep (as per recommended approach for win32 ipython in general). 2007-08-21 Ville Vainio