Custom Header Script

How to Create Custom Bash Script Header Template File

First start by creating the template file called sh_header.temp, which contains your custom bash script header, possibly under ~/.vim/ directory under your home

Next add the following lines in it (feel free to set your own template file location and custom header) and save the file.

#!/bin/bash
{{
###################################################################

#Script Name    :

#Description    :

#Args               :

#Author         :Aaron Kili Kisinga

#Email          :aaronkilik@gmail.com
###################################################################
}}

Now open your vim initialization file ~/.vimrc for editing and add the following line to it.

au bufnewfile *.sh 0r /home/ben/.vim/sh_header.temp

Where:

  • au – means autocmd
  • bufnewfile – event for opening a file that doesn’t exist for editing.
  • *.sh – consider all files with .sh extension.

So the above line instructs vi/vim editor to read the contents of the template file (/home/aaronkilik/.vim/sh_header.temp) and insert it into every new .sh file opened by a user