dim modules

The Dim user commands are designed and implemented in a way which makes the extension and customization process extremely easy.

  • There is no need to edit or modify the dim script itself.
  • The extension file must be installed in the executable path. The user must add a line containing . my_dim_ext in her $HOME/.dimrc.
  • The user simply provides a separate file containing the function body, written in shell script, usage, a short summary, and optionally a longer description text, documenting what the function does.
  • The summary of user commands as per dim -h, the command detailed help as per dim cmd -h, and the complete manual page as per dim man, are automatically extended.
  • All the argument parsing, option processing and context loading is performed by the main script prior to invoke the function, allowing the user code to focus on its specific added value.
  • The command line is consistent with the rest of the script. Option flags and argument parsing work the same for all commands.
  • The user function has complete access to the dim internal objects, can provide callbacks or overload dim existing functions.

Following is a sample dim extension module, to generate diffstat reports between 2 arbitrary versions of an item:

# This is a sample extension to dim.
# Install this file somewhere in your PATH and add in ~/.dimrc:
#	. dim_sample_module
#
# Verify that the help and the manpage are updated: 
#  $ dim -h | grep diffstat
#  $ diff diffstat -h
#  $ dim man | txt2man -T
#
cmd diffstat '[-e][-0-9] [Vers [Vers2]]' 'Print diff statistics' \
'       Invoke diff dim internal function, and filter the output
	through diffstat(1) executable. This command is provided
	as a sample separate extention of dim.'
diffstat()
{
	setv1v2 "$@"
	getpvers $v1 old 
	getpvers $v2 new
	echo "old: $old"
	echo "new: $new"
	ddiff=1 diffopt=-Nau diff "$@" | command diffstat
}

So get started, write your own dim extensions. You can contribute them, and we will include the best ones in official dim distribution (so they get support).


Copyright © 2008, Oligem
html css