Skip to content
Myr

Add initial code

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by sharkdp · parent 2145973 · Browse files · 3 files+82 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+82 added−0 removed

  • other:+82 added−0 removed

3 files+82 added−0 removed

added:src/fnd.cpp+62 added
1#include <iostream>2#include <regex>3#include <boost/filesystem.hpp>45namespace fs = boost::filesystem;67static const std::string ANSI_PURPLE = "\x1b[35;06m";8static const std::string ANSI_CYAN = "\x1b[36;01m";9static const std::string ANSI_RESET = "\x1b[0m";1011void printPath(const fs::path& path) {12 if (fs::is_symlink(path)) {13 std::cout << ANSI_PURPLE;14 } else if (fs::is_directory(path)) {15 std::cout << ANSI_CYAN;16 }1718 std::cout << path.string();1920 std::cout << ANSI_RESET << std::endl;2122}2324void findFiles(const std::regex& pattern) {25 const fs::path& currentPath = fs::current_path();2627 for (auto& entry: fs::recursive_directory_iterator(currentPath)) {28 const fs::path& path = entry.path().lexically_relative(currentPath);2930 if (std::regex_search(path.string(), pattern)) {31 printPath(path);32 }33 }34}3536int main(int argc, char* argv[]) {37 std::string argument;3839 if (argc == 1) {40 argument = "";41 } else if (argc == 2) {42 argument = argv[1];43 }4445 if (argc > 2 || argument == "-h" || argument == "--help") {46 std::cerr << "Usage: fnd [PATTERN]" << std::endl;47 return 1;48 }4950 // try to parse the argument as a regex51 try {52 std::regex re(argument);5354 findFiles(re);55 }56 catch (const std::regex_error& e) {57 std::cerr << "Regex error: " << e.what() << std::endl;58 return 1;59 }6061 return 0;62}
added:.gitignore+6 added
1CMakeCache.txt2CMakeFiles3Makefile4cmake_install.cmake5build6fnd
added:CMakeLists.txt+14 added
1cmake_minimum_required(VERSION 3.1.0)23project(fnd CXX)45find_package(Boost 1.56 REQUIRED COMPONENTS filesystem)6include_directories( ${Boost_INCLUDE_DIR} )78file(GLOB SOURCES "src/*.cpp")910set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")1112add_executable(fnd ${SOURCES})1314target_link_libraries(fnd ${Boost_LIBRARIES})