Tools+ reference

From CodeBlocks
Jump to: navigation, search

Tool Creation


Creating a new tool is fairly simple, and can be completed in a few simple steps. First open Tools(+)->Configure Tools... to access the "User-defined Tools" dialog.

Tool Name

This is the name that will be displayed in the Tools(+) drop-down menu. It will also be displayed as the tab name for tools that redirect to the Tools output window.

Command Line

Any valid command line function and switches can be placed here. Variable substitution is also accepted. The following list contains the more useful variables; see variable expansion for the full list.

$relfile,$file: respectively the relative and absolute name of a selected file

$reldir,$dir: respectively the relative and absolute name of a selected directory

$relpath,$path: the relative and absolute name of the selected file or directory

$mpaths: a list of selected files or directories (absolute paths only)

$fname,$fext: the name without extension and the extension without name of a selected file

$inputstr{prompt}: prompts the user to enter a string of text which is substituted into the command line

$if(condition){true clause}{false clause}: resolves to false clause if condition is empty, 0, or false; otherwise true clause

File Types

Wildcard expressions separated by semicolons will restrict population of the right click menu of a file, directory, or multiple paths in the Project Tree, File Explorer, or Editor Pane to the specified type(s). Leave blank to handle all file/directory types.

Working Directory

The directory from which the command is executed. Code::Blocks variables, project variables, and global variables are available. Also,

  1. If you have specified $dir in the command line then you can use $dir here also.
  2. $parentdir is available for $relfile, $file, $reldir, $dir, $relpath, $path, $fname, $fext and is the absolute path of the directory containing the item.

Tools Menu Path


Controls the placement of the command in the Tools(+) menu, giving the option of adding submenues (multiple levels are allowed).


Will create this structure.

The command name will be used if this entry is blank. If the first character is a period, the command will be hidden.

Context Menu Path


This controls the command's placement in the right-click menu of the Projects and Files tabs of the Management pane. The same rules of structure with the Tools Menu Path apply here.

Please note that the command will not show up in the context menu unless the Command Line contains one or more of the following: $relfile, $file, $reldir, $dir, $relpath, $path, $fname, and $fext.

Output to

This determines where the output of the command will be redirected. The purpose and function of the command will determine which is best to select.

Tools Output Window

Tools that only output results command line (and require no input) generally use this setting. The program will be run invisibly and any output will be redirected to the appropriate tab of the Tools Output Window. The text [DONE] will be added upon the tool's completion.


Code::Blocks Console

This will cause the program to be run through the executable cb_console_runner (the same program that is launched after Build and run). This is generally used for command line tools with more advanced user interactions, although GUI programs can also be used (especially if the program is unstable and/or also leaves messages in the standard output). Console runner will pause the window (prevent it from closing), display the run time, and the exit code when the program finishes.

Standard Shell

This is the same as placing the command in a batch or shell script, then running it. The program will run in whatever its default method is, and when it finishes, its window will close. This setting is useful for running a program (for example a file or web browser) that must remain open after Code::Blocks is closed.


As the Tools+ plugin is not yet complete, some functionality - specifically Menu Priority and Environment Variables - are not available.

If the Tools Output window is open when Code::Blocks is closed, it may trigger Code::Blocks to crash.

Example Tools

Open file browser to selected file

  • Windows Explorer
explorer /select,"$(PROJECTFILE)" (Tools Menu)
explorer /select,"$path" (Context Menu)
  • Dolphin
dolphin --select "$(PROJECTFILE)" (Tools Menu)
dolphin --select "$path" (Context Menu)

Note: the following three commands Context Menu only support folders (but not files). If you know how to script a conversion to cause $path or $file to return the parent directory, please add it here.

  • Nautilus
nautilus --no-desktop --browser "$(PROJECTDIR)" (Tools Menu)
nautilus --no-desktop --browser "$dir" (Context Menu)
  • Thunar
thunar "$(PROJECTDIR)" (Tools Menu)
thunar "$dir" (Context Menu)
  • PCMan File Manager
pcmanfm "$(PROJECTDIR)" (Tools Menu)
pcmanfm "$dir" (Context Menu)

Update Subversion directory

  • Windows
"path_to_svn\bin\svn" update "$inputstr{Directory}" (Tools Menu)
"path_to_svn\bin\svn" update "$dir" (Context Menu and Tools Menu)
  • Linux
svn update "$inputstr{Directory}" (Tools Menu)
svn update "$dir" (Context Menu and Tools Menu)

Export makefile

Note: this uses the command line-tool cbp2make. Discussion: [1] Download: [2]

  • Windows
"path_to_cbp2make\cbp2make" -in "$(PROJECTFILE)" (Tools Menu)
  • Linux
"path_to_cbp2make/cbp2make" -in "$(PROJECTFILE)" (Tools Menu)

Compress active project to archive

  • Windows
    • 7z or zip
"path_to_7z\7z" a -t$if(zip == $inputstr{7z or zip?}){zip -mm=Deflate -mmt=on -mx9 -mfb=128 -mpass=10}{7z -m0=LZMA -mx9 -md=64m -mfb=64 -ms=on} -sccUTF-8 "-w$(PROJECTDIR).." "$(PROJECTDIR)..\$(PROJECT_NAME)" "$(PROJECTDIR)*" (Tools Menu)
  • tar.gz or tar.bz2 (Note: works in Tools Output Window and Standard Shell, but not Code::Blocks Console.)
cmd /c ""path_to_7z\7z" a -ttar -mx0 -sccUTF-8 "-w$(PROJECTDIR).." "$(PROJECTDIR)..\$(PROJECT_NAME)" "$(PROJECTDIR)*" && "path_to_7z\7z" a -t$if(gz == $inputstr{gz or bz2?}){gzip -mx9 -mfb=128 -mpass=10 -sccUTF-8 "-w$(PROJECTDIR).." "$(PROJECTDIR)..\$(PROJECT_NAME).tar.gz}{bzip2 -mmt=on -mx9 -md=900k -mpass=7 -sccUTF-8 "-w$(PROJECTDIR).." "$(PROJECTDIR)..\$(PROJECT_NAME).tar.bz2}" "$(PROJECTDIR)..\$(PROJECT_NAME).tar" && cmd /c del "$(PROJECTDIR)..\$(PROJECT_NAME).tar"" (Tools Menu)
  • Linux
    • 7z or zip
7z a -t$if(zip == $inputstr{7z or zip?}){zip -mm=Deflate -mmt=on -mx9 -mfb=128 -mpass=10}{7z -m0=LZMA -mx9 -md=64m -mfb=64 -ms=on} -sccUTF-8 "-w$(PROJECTDIR).." "$(PROJECTDIR)../$(PROJECT_NAME)" "$(PROJECTDIR)*" (Tools Menu)
  • tar.gz or tar.bz2
tar -cf "$(PROJECTDIR)../$(PROJECT_NAME).tar.$if(gz == $inputstr{gz or bz2?}){gz" -I 'gzip}{bz2" -I 'bzip2} -9' "$(PROJECTDIR)*" (Tools Menu)