以前一直在windows下面寫hexo博客,可是每次同步須要運行一大堆指令,因而想到用python 寫一個腳原本自動同步,用到了os.chdir,由於直接os.system('cd xxx')
會自動返回當前路徑。python
具體程序以下:git
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2017/8/10 19:42 import os os.chdir((ur'E:\項目\blog')) os.system('hexo d \-g') os.system(ur'git add .') os.system("git commit -m 'Updated'") os.system('git push origin source') print 'done'
而後將啓動這個命令設置爲簡短的命令,相似於aliaswindows
Run the below command in a command prompt to alias ls to run the command dir. The $* on the end are required so that any additional arguments are also passed to the dir command.****session
1 | doskey ls=dir $* |
---|---|
The problem with this is that all of your alias commands will be lost when you close the cmd session. To make them persist we need to create a batch file and add the entry to the windows registry.hexo
Create a new folder in the windows directory called bin and create a new batch file inside it.ide
12 | C:>mkdir c:\windows\binC:>notepad.exe c:\windows\bin\doskey.bat |
---|---|
Add your entries to the batch file in the below format.ui
12345 | @echo offdoskey ls=dir $doskey mv=move $doskey cp=copy $doskey cat=type $ |
---|---|
Next, open up regedit.exe and add an entry to the batch file to make the doskey commands permanent for each cmd session.this
1 | HKEY_CURRENT_USER\Software\Microsoft\Command Processor |
---|---|
Add a new String Value called AutoRun and set the absolute path in the value of c:\windows\bin\doskey.bat.****code
The doskey.bat file will now be executed before opening a new cmd session which will set all of your alias ready for you to use.orm