有时候写代码的时候,要新建一个文件,假如是.py。那么首先我们得新建一个文本文件(.txt),然后再重命名成xxx.py,因为改变文件扩展名的缘故,还会弹出一个确认的对话框。非常烦,那么有适合懒人的方法吗?答案是肯定的,只要你肯去找,网上的方法非常多。
Windows下一些定制或者或少要去修改注册表,说实话,对Windows的注册表真得不是非常感冒,但是Windows许多神秘的东西都隐藏在这里。
首先创建一个文本文件,改名为add_item_in_new_context.reg(注册表文件是以.reg为扩展名的)。然后将以下内容写到该文件中:
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.py\ShellNew] "FileName"="sample.py" "NullFile"=""
该文件的目的是在HKEY_CLASSES_ROOT\.py路径下创建一个项ShellNew,并在该项下创建一些键值。ShellNew就是对应于右键新建菜单,换句话说,如果要删除不要的新建项目,也可以在注册表中删除对应的ShellNew项。而FileName这个键的目的是,在新建的时候使用一个模板文件来创建,有时候代码都是需要在文件开始处放一些注释和说明的,那么可以写一个sample.py:
#!/bin/env python # coding=utf-8 '''A simple sentence to describe the function of this module. Add detailed description here if need. Eample: # python ./sample.py -t # ... ''' # Can be 'Prototype', 'Development', 'Product' __status__ = 'Development' __author__ = 'yourname <yourname @example.com>' # Add your code here # Delete the description when you start coding. def usage(): '''Show script help information.''' pass def main(): '''The main entry.''' pass if __name__ == '__main__': main() # vim: set expandtab smarttab shiftwidth=4 tabstop=4:
然后把sample.py放到C:\Windows\ShellNew目录,现在再试试右键新建,会出现Python文件。
不过我并没有用这种方法,让.sh文件也成功,有空再研究下。
在 win7 下测试貌似没有生效,右键新建没有出现对应的菜单。