It’s been a long time in the making, but I am proud to announce the first beta release of cppsh, the bash-like shell specifically designed for those engineers who find themselves most comfortable at the reins of a C++ compiler. The best features from both bash and the C++ language come together in cppsh to make you a more productive shell user. Some of the most important features of cppsh include:
File Iterators
File iterators allow you to traverse the files in your working directory using the convenient C++ STL iterator syntax:
for ( cppsh::file::const_iterator file_iterator =
cppsh::list_cwd().begin();
file_iterator != cppsh::list_cwd().end();
++file_iterator )
{
typedef cppsh::command_line_entry<std::string> entry;
std::vector<entry> command_line;
command_line.push_back( entry( "mv" ) );
command_line.push_back( entry( "-f" ) );
command_line.push_back( entry( *file_iterator ) );
command_line.push_back( entry( *file_iterator + ".bak" ) );
cppsh::execute_command( command_line, std::cout );
}
Command Pipelines
Following the UNIX tradition, cppsh makes it easy to feed the output of one command into another command:
typedef cppsh::command_line_entry<std::string> entry;
typedef std::vector<entry> command;
command cat_command;
cat_command.push_back( entry( "cat" ) );
cat_command.push_back( entry( "datafile" ) );
command sort_command;
sort_command.push_back( entry( "sort" ) );
sort_command.push_back( entry( "--unique" ) );
command wc_command;
wc_command.push_back( entry( "wc" ) );
wc_command.push_back( entry( "--lines" ) );
cppsh::command_pipeline<command> pipeline;
pipeline.push_back( cat_command );
pipeline.push_back( sort_command );
pipeline.push_back( wc_command );
pipeline.execute( std::cout );
Configurability
Like many UNIX programs, cppsh can be configured by editing the .cppshrc file in your home directory. Unlike most UNIX programs, however, the .cppshrc file is a full-fledged C++ header file. The .cppshrc file is responsible for defining the cppsh_shell type. This is done by creating a user-specific traits class and passing it as a parameter basic_cppsh_shell template:
#define DOT_CPPSHRC
#include <cppsh/basic_cppsh_shell.hpp>
namespace cppsh {
struct user_cppsh_traits
{
typedef vi_editing_mode editing_mode_t;
static const int command_history = 1000;
static std::string prompt()
{
return "cppsh>";
}
};
typedef basic_cppsh_shell<user_cppsh_traits> cppsh_shell;
} // namespace cppsh
#endif // DOT_CPPSHRC
Extensibility
If you’re a demanding user, you might find that the .cppshrc file does not offer the power you need to customize cppsh to fit your needs. You’re still in luck! All of the features described above (and more) are packed into only 412,011 lines of C++ code, so you can easily hack cppsh to fit your own needs. Internally, cppsh makes extensive use of template metaprogramming, so the code is terse and easy to understand.
What are you waiting for?
Get started with cppsh today — visit the project page for downloads and documentation. You’ll be happy you did.
– The cppsh team
Comments are disabled for this post