##// END OF EJS Templates
Fix win32 line endings.
fperez -
Show More
@@ -1,102 +1,102 b''
1 # -*- coding: utf-8 -*-
2 """ IPython extension: add %rehashdir magic
3
4 Usage:
5
6 %rehashdir c:/bin c:/tools
7 - Add all executables under c:/bin and c:/tools to alias table, in
8 order to make them directly executable from any directory.
9
10 This also serves as an example on how to extend ipython
11 with new magic functions.
12
13 Unlike rest of ipython, this requires Python 2.4 (optional
14 extensions are allowed to do that).
15
16 To install, add
17
18 "import_mod ext_rehashdir"
19
20 To your ipythonrc or just execute "import rehash_dir" in ipython
21 prompt.
22
23
24 $Id: InterpreterExec.py 994 2006-01-08 08:29:44Z fperez $
25 """
26
27 import IPython.ipapi
28 ip = IPython.ipapi.get()
29
30
31 import os,re,fnmatch
32
33 def rehashdir_f(self,arg):
34 """ Add executables in all specified dirs to alias table
35
36 Usage:
37
38 %rehashdir c:/bin;c:/tools
39 - Add all executables under c:/bin and c:/tools to alias table, in
40 order to make them directly executable from any directory.
41
42 Without arguments, add all executables in current directory.
43
44 """
45
46 # most of the code copied from Magic.magic_rehashx
47
48 def isjunk(fname):
49 junk = ['*~']
50 for j in junk:
51 if fnmatch.fnmatch(fname, j):
52 return True
53 return False
54
55 if not arg:
56 arg = '.'
57 path = map(os.path.abspath,arg.split(';'))
58 alias_table = self.shell.alias_table
59
60 if os.name == 'posix':
61 isexec = lambda fname:os.path.isfile(fname) and \
62 os.access(fname,os.X_OK)
63 else:
64
65 try:
66 winext = os.environ['pathext'].replace(';','|').replace('.','')
67 except KeyError:
68 winext = 'exe|com|bat|py'
69
70 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
71 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
72 savedir = os.getcwd()
73 try:
74 # write the whole loop for posix/Windows so we don't have an if in
75 # the innermost part
76 if os.name == 'posix':
77 for pdir in path:
78 os.chdir(pdir)
79 for ff in os.listdir(pdir):
80 if isexec(ff) and not isjunk(ff):
81 # each entry in the alias table must be (N,name),
82 # where N is the number of positional arguments of the
83 # alias.
84 src,tgt = os.path.splitext(ff)[0], os.path.abspath(ff)
85 print "Aliasing:",src,"->",tgt
86 alias_table[src] = (0,tgt)
87 else:
88 for pdir in path:
89 os.chdir(pdir)
90 for ff in os.listdir(pdir):
91 if isexec(ff) and not isjunk(ff):
92 src, tgt = execre.sub(r'\1',ff), os.path.abspath(ff)
93 print "Aliasing:",src,"->",tgt
94 alias_table[src] = (0,tgt)
95 # Make sure the alias table doesn't contain keywords or builtins
96 self.shell.alias_table_validate()
97 # Call again init_auto_alias() so we get 'rm -i' and other
98 # modified aliases since %rehashx will probably clobber them
99 self.shell.init_auto_alias()
100 finally:
101 os.chdir(savedir)
102 ip.expose_magic("rehashdir",rehashdir_f)
1 # -*- coding: utf-8 -*-
2 """ IPython extension: add %rehashdir magic
3
4 Usage:
5
6 %rehashdir c:/bin c:/tools
7 - Add all executables under c:/bin and c:/tools to alias table, in
8 order to make them directly executable from any directory.
9
10 This also serves as an example on how to extend ipython
11 with new magic functions.
12
13 Unlike rest of ipython, this requires Python 2.4 (optional
14 extensions are allowed to do that).
15
16 To install, add
17
18 "import_mod ext_rehashdir"
19
20 To your ipythonrc or just execute "import rehash_dir" in ipython
21 prompt.
22
23
24 $Id: InterpreterExec.py 994 2006-01-08 08:29:44Z fperez $
25 """
26
27 import IPython.ipapi
28 ip = IPython.ipapi.get()
29
30
31 import os,re,fnmatch
32
33 def rehashdir_f(self,arg):
34 """ Add executables in all specified dirs to alias table
35
36 Usage:
37
38 %rehashdir c:/bin;c:/tools
39 - Add all executables under c:/bin and c:/tools to alias table, in
40 order to make them directly executable from any directory.
41
42 Without arguments, add all executables in current directory.
43
44 """
45
46 # most of the code copied from Magic.magic_rehashx
47
48 def isjunk(fname):
49 junk = ['*~']
50 for j in junk:
51 if fnmatch.fnmatch(fname, j):
52 return True
53 return False
54
55 if not arg:
56 arg = '.'
57 path = map(os.path.abspath,arg.split(';'))
58 alias_table = self.shell.alias_table
59
60 if os.name == 'posix':
61 isexec = lambda fname:os.path.isfile(fname) and \
62 os.access(fname,os.X_OK)
63 else:
64
65 try:
66 winext = os.environ['pathext'].replace(';','|').replace('.','')
67 except KeyError:
68 winext = 'exe|com|bat|py'
69
70 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
71 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
72 savedir = os.getcwd()
73 try:
74 # write the whole loop for posix/Windows so we don't have an if in
75 # the innermost part
76 if os.name == 'posix':
77 for pdir in path:
78 os.chdir(pdir)
79 for ff in os.listdir(pdir):
80 if isexec(ff) and not isjunk(ff):
81 # each entry in the alias table must be (N,name),
82 # where N is the number of positional arguments of the
83 # alias.
84 src,tgt = os.path.splitext(ff)[0], os.path.abspath(ff)
85 print "Aliasing:",src,"->",tgt
86 alias_table[src] = (0,tgt)
87 else:
88 for pdir in path:
89 os.chdir(pdir)
90 for ff in os.listdir(pdir):
91 if isexec(ff) and not isjunk(ff):
92 src, tgt = execre.sub(r'\1',ff), os.path.abspath(ff)
93 print "Aliasing:",src,"->",tgt
94 alias_table[src] = (0,tgt)
95 # Make sure the alias table doesn't contain keywords or builtins
96 self.shell.alias_table_validate()
97 # Call again init_auto_alias() so we get 'rm -i' and other
98 # modified aliases since %rehashx will probably clobber them
99 self.shell.init_auto_alias()
100 finally:
101 os.chdir(savedir)
102 ip.expose_magic("rehashdir",rehashdir_f)
@@ -1,60 +1,60 b''
1 """ Set default options for "reasonable use"
2
3 Just import this module to get reasonable defaults for everything.
4
5 These configurations used to be performed in ipythonrc (or ipythonrc.ini).
6 Therefore importing this in your config files makes ipython basically
7 ignore your ipythonrc. This is *not* imported by default, you need to import
8 this manually in one of your config files.
9
10 You can further override these defaults in e.g. your ipy_user_config.py,
11 ipy_profile_PROFILENAME etc.
12
13 """
14
15 import IPython.rlineimpl as readline
16 import IPython.ipapi
17 ip = IPython.ipapi.get()
18
19 o = ip.options()
20
21
22 o.colors = "Linux"
23 o.color_info=1
24 o.confirm_exit=1
25 o.pprint=1
26 o.multi_line_specials=1
27 o.xmode="Context"
28
29
30 o.prompt_in1='In [\#]: '
31 o.prompt_in2 =' .\D.: '
32 o.prompt_out = 'Out[\#]: '
33 o.prompts_pad_left=1
34
35 o.readline_remove_delims="-/~"
36 o.readline_merge_completions=1
37
38 o.readline = 1
39
40 rlopts = """\
41 tab: complete
42 "\C-l": possible-completions
43 set show-all-if-ambiguous on
44 "\C-o": tab-insert
45 "\M-i": " "
46 "\M-o": "\d\d\d\d"
47 "\M-I": "\d\d\d\d"
48 "\C-r": reverse-search-history
49 "\C-s": forward-search-history
50 "\C-p": history-search-backward
51 "\C-n": history-search-forward
52 "\e[A": history-search-backward
53 "\e[B": history-search-forward
54 "\C-k": kill-line
55 "\C-u": unix-line-discard"""
56
57 for cmd in rlopts.split('\n'):
58 readline.parse_and_bind(cmd)
59
60 No newline at end of file
1 """ Set default options for IPython.
2
3 Just import this module to get reasonable defaults for everything.
4
5 These configurations used to be performed in ipythonrc (or ipythonrc.ini).
6 Therefore importing this in your config files makes ipython basically
7 ignore your ipythonrc. This is *not* imported by default, you need to import
8 this manually in one of your config files.
9
10 You can further override these defaults in e.g. your ipy_user_config.py,
11 ipy_profile_PROFILENAME etc.
12
13 """
14
15 import IPython.rlineimpl as readline
16 import IPython.ipapi
17 ip = IPython.ipapi.get()
18
19 o = ip.options()
20
21
22 o.colors = "Linux"
23 o.color_info=1
24 o.confirm_exit=1
25 o.pprint=1
26 o.multi_line_specials=1
27 o.xmode="Context"
28
29
30 o.prompt_in1='In [\#]: '
31 o.prompt_in2 =' .\D.: '
32 o.prompt_out = 'Out[\#]: '
33 o.prompts_pad_left=1
34
35 o.readline_remove_delims="-/~"
36 o.readline_merge_completions=1
37
38 o.readline = 1
39
40 rlopts = """\
41 tab: complete
42 "\C-l": possible-completions
43 set show-all-if-ambiguous on
44 "\C-o": tab-insert
45 "\M-i": " "
46 "\M-o": "\d\d\d\d"
47 "\M-I": "\d\d\d\d"
48 "\C-r": reverse-search-history
49 "\C-s": forward-search-history
50 "\C-p": history-search-backward
51 "\C-n": history-search-forward
52 "\e[A": history-search-backward
53 "\e[B": history-search-forward
54 "\C-k": kill-line
55 "\C-u": unix-line-discard"""
56
57 for cmd in rlopts.split('\n'):
58 readline.parse_and_bind(cmd)
59
60
@@ -1,45 +1,45 b''
1 import IPython.ipapi
2
3 ip = IPython.ipapi.get()
4
5 def clip_f( self, parameter_s = '' ):
6 """Save a set of lines to the clipboard.
7
8 Usage:\\
9 %clip n1-n2 n3-n4 ... n5 .. n6 ...
10
11 This function uses the same syntax as %macro for line extraction, but
12 instead of creating a macro it saves the resulting string to the
13 clipboard.
14
15 When used without arguments, this returns the text contents of the clipboard.
16 E.g.
17
18 mytext = %clip
19
20 """
21
22 import win32clipboard as cl
23 import win32con
24 args = parameter_s.split()
25 cl.OpenClipboard()
26 if len( args ) == 0:
27 data = cl.GetClipboardData( win32con.CF_TEXT )
28 cl.CloseClipboard()
29 return data
30 api = self.getapi()
31
32 if parameter_s.lstrip().startswith('='):
33 rest = parameter_s[parameter_s.index('=')+1:].strip()
34 val = str(api.ev(rest))
35 else:
36 ranges = args[0:]
37 val = ''.join( self.extract_input_slices( ranges ) )
38
39 cl.EmptyClipboard()
40 cl.SetClipboardText( val )
41 cl.CloseClipboard()
42 print 'The following text was written to the clipboard'
43 print val
44
45 ip.expose_magic( "clip", clip_f )
1 import IPython.ipapi
2
3 ip = IPython.ipapi.get()
4
5 def clip_f( self, parameter_s = '' ):
6 """Save a set of lines to the clipboard.
7
8 Usage:\\
9 %clip n1-n2 n3-n4 ... n5 .. n6 ...
10
11 This function uses the same syntax as %macro for line extraction, but
12 instead of creating a macro it saves the resulting string to the
13 clipboard.
14
15 When used without arguments, this returns the text contents of the clipboard.
16 E.g.
17
18 mytext = %clip
19
20 """
21
22 import win32clipboard as cl
23 import win32con
24 args = parameter_s.split()
25 cl.OpenClipboard()
26 if len( args ) == 0:
27 data = cl.GetClipboardData( win32con.CF_TEXT )
28 cl.CloseClipboard()
29 return data
30 api = self.getapi()
31
32 if parameter_s.lstrip().startswith('='):
33 rest = parameter_s[parameter_s.index('=')+1:].strip()
34 val = str(api.ev(rest))
35 else:
36 ranges = args[0:]
37 val = ''.join( self.extract_input_slices( ranges ) )
38
39 cl.EmptyClipboard()
40 cl.SetClipboardText( val )
41 cl.CloseClipboard()
42 print 'The following text was written to the clipboard'
43 print val
44
45 ip.expose_magic( "clip", clip_f )
General Comments 0
You need to be logged in to leave comments. Login now