編寫shell指令碼自動自動生成註釋簡介
在編輯sh指令碼的時候經常會在shell裡面寫一些註釋,今天介紹一個漸變的方法,可以在每次vim一個shell指令碼的時候都會自動在shell裡面自動生成註釋簡介等資訊。
方法很簡單,在任意一個目錄下vim 一個.vimrc的檔案
[root@iZc7dl28gmxoznZ ~]# vim .vimrc
然後根據自己的需求將下面檔案貼上進去並進行根據自己的要求更改,儲存退出就可以了。
set ignorecase set cursorline set autoindent autocmd BufNewFile *.sh exec ":call SetTitle()" func SetTitle() if expand("%:e") == 'sh' call setline(1,"#!/bin/bash") call setline(2,"#") call setline(3,"#********************************************************************") call setline(4,"#Author:一隻剛剛開始吃貓糧的運維狗") call setline(5,"#QQ:314420029") call setline(6,"#Date:".strftime("%Y-%m-%d")) call setline(7,"#FileName:".expand("%")) call setline(8,"#URL:https://www.jianshu.com/u/8dd0b208be76") call setline(9,"#Description:The test script") call setline(10,"#Copyright (C):".strftime("%Y")." All rights reserved") call setline(11,"#********************************************************************") call setline(12,"#") call setline(13,"") endif endfunc autocmd BufNewFile * normal G
編輯完發現,ls檢視不到這個檔案了,這是因為它變成了一個隱藏檔案,ll -a就可以檢視到了
[root@iZc7dl28gmxoznZ ~]# ll -a total 412 dr-xr-x---.6 root root4096 Oct 27 18:40 . dr-xr-xr-x. 19 root root4096 Sep 14 00:04 .. -rw-------1 root root4965 Oct 26 18:51 .bash_history -rw-r--r--.1 root root18 Dec 292013 .bash_logout -rw-r--r--.1 root root176 Dec 292013 .bash_profile -rw-r--r--.1 root root176 Dec 292013 .bashrc drwx------3 root root4096 Oct 152017 .cache -rw-r--r--.1 root root100 Dec 292013 .cshrc -rw-r--r--1 root root 333678 Sep 11 18:13 harbor-online-installer-v1.6.0.tgz -rwxr-xr-x1 root root25 Oct 27 17:32 hello1.sh -rwxrwxrwx1 root root30 Oct 27 17:28 hello.sh drwxr-xr-x2 root root4096 Oct 152017 .pip drwxr-----3 root root4096 Sep 11 20:40 .pki -rw-r--r--1 root root64 Oct 152017 .pydistutils.cfg -rw-------1 root root1024 Sep 14 00:06 .rnd drwx------2 root root4096 Sep 11 16:40 .ssh -rw-r--r--.1 root root129 Dec 292013 .tcshrc -rw-r--r--1 root root395 Oct 27 18:34 test.sh -rw-------1 root root5524 Oct 27 18:40 .viminfo -rw-r--r--1 root root840 Oct 27 18:35 .vimrc [root@iZc7dl28gmxoznZ ~]#
然就可以vim 編輯shell檔案了
#!/bin/bash # #******************************************************************** #Author:一隻剛剛開始吃貓糧的運維狗 #QQ:314420029 #Date:2018-10-27 #FileName:one.sh #URL:https://www.jianshu.com/u/8dd0b208be76 #Description:The test script #Copyright (C):2018 All rights reserved #********************************************************************