Git Product home page Git Product logo

cmt's Introduction

cmt

An extensible POSIX shellscript for commenting text, written for use with vi(1). cmt will automatically comment or uncomment based on the first line it reads and the options passed.

Examples

Shell-style comments (the default)

$ echo 'foo bar' | cmt
# foo bar

$ printf '%s\n' foo bar | cmt
# foo
# bar

C-style comments

$ echo 'foo bar' | cmt -c
/* foo bar */

$ printf '%s\n' foo bar | cmt -C
/*
 * foo
 * bar
 */

Commented text will be uncommented:

$ echo foo | cmt | cmt
foo

$ cat c-style.txt
/*
 * foo
 * bar
 */

$ cmt -C c-style.txt
foo
bar

Indentation is preserved when commenting indented blocks:

E.g. File contents:

main ()
{
	trap 'test -t 1 && printf \\n' EXIT
	if test $# -eq 0
	then
		encode_stream
		return
	fi
	while test $# -gt 0
	do
		if test -f "$1"
		then
			encode_stream <"$1"
		else
			encode_string "$1"
		fi
		shift
	done
}

Ex-command :/while/;/done/!cmt

main ()
{
	trap 'test -t 1 && printf \\n' EXIT
	if test $# -eq 0
	then
		encode_stream
		return
	fi
	# while test $# -gt 0
	# do
	# 	if test -f "$1"
	# 	then
	# 		encode_stream <"$1"
	# 	else
	# 		encode_string "$1"
	# 	fi
	# 	shift
	# done
}

cmt can also reformat comments with the -f option:

Sample code with a very long comment:

# Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
def my_func(foo, bar):
    that = do.this(thing)
    return that

Ex-command :/^# Lorem/!cmt -f

# Lorem Ipsum is simply dummy text of the printing and typesetting
# industry. Lorem Ipsum has been the industry's standard dummy text ever since
# the 1500s, when an unknown printer took a galley of type and scrambled it
# to make a type specimen book.
def my_func(foo, bar):
    that = do.this(thing)
    return that

cmt's People

Contributors

jaf7c7 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.