编写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 root 4096 Oct 27 18:40 . dr-xr-xr-x. 19 root root 4096 Sep 14 00:04 .. -rw------- 1 root root 4965 Oct 26 18:51 .bash_history -rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout -rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile -rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc drwx------ 3 root root 4096 Oct 15 2017 .cache -rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc -rw-r--r-- 1 root root 333678 Sep 11 18:13 harbor-online-installer-v1.6.0.tgz -rwxr-xr-x 1 root root 25 Oct 27 17:32 hello1.sh -rwxrwxrwx 1 root root 30 Oct 27 17:28 hello.sh drwxr-xr-x 2 root root 4096 Oct 15 2017 .pip drwxr----- 3 root root 4096 Sep 11 20:40 .pki -rw-r--r-- 1 root root 64 Oct 15 2017 .pydistutils.cfg -rw------- 1 root root 1024 Sep 14 00:06 .rnd drwx------ 2 root root 4096 Sep 11 16:40 .ssh -rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc -rw-r--r-- 1 root root 395 Oct 27 18:34 test.sh -rw------- 1 root root 5524 Oct 27 18:40 .viminfo -rw-r--r-- 1 root root 840 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 #********************************************************************
原文地址:https://www.jianshu.com/p/1a5f2fd32a36
相关推荐
-
使用Kubernetes演示金丝雀发布 服务器
2019-9-18
-
yum安装CDH5.5 hive、impala 服务器
2020-6-21
-
PLSQLDeveloper连接远程Oracle数据库 转 服务器
2020-5-31
-
通过springBoot构建一个简单的Restful webService 服务器
2019-3-22
-
大型网站架构演化 服务器
2020-6-22
-
Mac OSX下的MySQL数据库升级 服务器
2019-3-21
-
如何写好 C main 函数 服务器
2019-7-2
-
ssh keys管理工具 服务器
2019-5-13
-
Jenkins使用简易教程 服务器
2019-2-2
-
kubernetes 集群水平扩展 自动伸缩 服务器
2019-11-2