3

From time to time I see similar framing for comments in bash scripts:

#!/bin/bash
#===================================================================================
#
# FILE: stale-links.sh
#
# USAGE: stale-links.sh [-d] [-l] [-oD logfile] [-h] [starting directories]
#
# DESCRIPTION: List and/or delete all stale links in directory trees.
# The default starting directory is the current directory.
# Don’t descend directories on other filesystems.
#===================================================================================

Is there any program to generate such a decoration for comments or do people usually create it manually?

P.S. After some search, I found similar threads:
How can I create a message box from the command line?
bash script , echo output in box

4
  • If you mention which text editor you're using, it might get you better-focused answers.
    – MDeBusk
    Jun 20 at 1:50
  • 3
    Please think about defining usage and help functions instead at the beginning of your scripts. They carry the same information, look a little less fancy, but it's a good convention to print a usage message on wrong arguments and a description at -h option. Having this information twice in the functions and in the block header may lead to one of them not getting updated on changes.
    – Philippos
    Jun 20 at 5:44
  • 1
    In vim you can do: i # Esc 60 a = Esc Jun 20 at 13:12
  • ...and once you've created a line that way, you can keep using yy + pp to duplicate it.
    – steve
    Jun 20 at 20:12

2 Answers 2

5

I really like Thomas Jensen's boxes. It does a lot more than just the comment boxes you describe, and more than just for shell scripts. It's a command-line utility and it also integrates with several text editors, including my personal favorite.

2
  • Thanks for the hint. It looks like the only program in the Internet I managed to find for this purpose. Are there any similar alternatives?
    – t7e
    Jun 20 at 19:48
  • 1
    @t7e I've never seen anything else like it. There's always Tim Pope's commentary if you prefer plugins.
    – MDeBusk
    Jun 20 at 20:26
0

If all you want is the informative header at the top of your scripts, you could do it without a plugin or external utility. Create a bash_script_template.sh that looks something like this:

#!/bin/bash

############################################################
# Filename   : x                                           #
# Author     : x                                           #
# Created    : x                                           #
# Last edit  : x                                           #
# Purpose    : x                                           #
# Reference  : x                                           #
# Depends    : x                                           #
# Arguments  : x                                           #
# Known bugs : x                                           #
# To do      : x                                           #
############################################################

# GNU All-Permissive License {{{
#############################################################
# Copyright © 2022 my_name                                  #
#                                                           #
# Copying and distribution of this file, with or without    #
# modification, are permitted in any medium without         #
# royalty, provided the copyright notice and this notice    #
# are preserved.                                            #
#                                                           #
# This file is offered as-is, without any warranty.         #
#############################################################
# End license }}}

When you want to write a new script, copy the template to a new filename or read it into the top of an empty buffer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.