Code Monkey home page Code Monkey logo

ngp's Introduction

Build Status

ngp

ncurses grep

ngp lets you look for a pattern and display results in ncurses.

ngp lets you browse results with ease.

ngp lets you open a result with your favorite editor at the right line.

Build and Install

  1. Install build dependencies for your platform/distribution : libconfig, libpcre & ncurses

  2. Enter the following commands in your terminal :

git clone [email protected]:jonathanklee/ngp.git
cd ./ngp
cmake .
make
make install
  1. That's it. You can now open a terminal and enjoy !
ngp my_pattern

Native or External parser

ngp implements it's own parser but you can also use it with an external parser.

By default, ngp looks into the extensions listed in the ngprc configuration file. If you want to override those extensions with a specific extension, you can use the -t option :

ngp my_pattern -t my_extension

For instance, we can look for the LOCAL_MODULE expression in Android Open Source Project makefiles.

ngp LOCAL_MODULE -t mk

To look into all the files, the native parser has also a raw option.

ngp my_pattern -r

To look for a regular expression, the native parser implements the -e option.

ngp my_regexp -e

For instance, we can look for a regular expression like ^._MODULE :=.$

ngp "^.*_MODULE :=.*$" -e

Have a look at ngp -h for more options.

You can also use an external tool to parse your source code. Currently only ag and git grep are supported.

The default parser can be specified in your ~/.config/ngp/ngprc file. Other available values for the 'default_parser' option are "ag" or "git". The parser can also be specified using command line arguments. For example, ngp --ag -- pattern will use ag as a parser anbd will overwrite the 'default_parser' setting. Please check ngp --help for further information on command line arguments.

Your ngprc file also allows you to customize the commands for ag and git grep. Thus, you can add options for ag like "-C" or you can change a tools location if it's not in your $PATH. Note that it is mandatory to specify the three arguments : options, pattern and path for each command.

Demo

Looking for "struct" pattern in ngp source code.

gif

License

Copyright (c) 2013 Jonathan Klee

ngp is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

ngp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ngp.  If not, see <http://www.gnu.org/licenses/>.

ngp's People

Contributors

ferruck avatar jonathanklee avatar jozie avatar youx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngp's Issues

ag / ack support

This app is super cool, just thought supporting those would be awesome. Eventually and all that.

Suggestion: support -C

Hi,

Thanks for this very nice tool. Are there any plans of supporting the -C (probably also -A and -B) parameters of grep to be able to see more context around matches (to decide whether to edit them?).

Just a suggestion, in case you find it relevant. :)

Unicode is not supported

Currently there's a bunch of issues with non-ASCII characters:

  • text gets cut in the output
  • random rubbish appears near the text
  • currently selected text has weird partial blinking animation
  • ignore case feature doesn't work

Is it planned to be supported? Thank you!

(And of course I don't have any non-ASCII source code, I use your awesome tool for Jupyter, to search and navigate to a particular section in page; I've got dozens of notes and it was very painful to navigate before I discovered your awesome tool, so thank you a lot)

Using a dir as argument

Using a directory as argument does not work so far. The file name is cropped when results are displayed and there is no way to open the file when using 'p'.

ngp does not run on ubuntu

On an ubuntu distribution:
error in /etc/ngprc
Configuration file has not been found

With ngprc in /etc/ngprc and /home/$USER/.ngprc
And installed packages:
- libconfig8
- libconfig-dev

Build on OSX/BSD

PATH_MAX is undefined unless you include <limits.h> or <sys/syslimits.h> on OSX/BSD

Suggestion: support --ignore

It would be nice if you could ignore certain directories and files. Manily through a switch but it would also be nice if it could be configured through a config file.

error: function may return address of local variable

$ CFLAGS="-fstack-protector-strong -O2" cmake . && make -j8
...
src/ngp_search.c: In function ‘get_file_name’:
cc1: error: function may return address of local variable [-Werror=return-local-addr]
src/ngp_search.c:60:10: note: declared here
     char copy[FILENAME_MAX];

I'd also enable other warnings to see more potential issues
-pedantic-errors -pedantic -Wextra -Wall
For some weird reason it disables the local variable issue for me.

I'm using gcc 6.4.0 on Gentoo GNU/Linux.
Thank you!

Documentation does not list dependencies

Rather than leaving people to hunt around for the appropriate development libraries perhaps you could specify in your README* files the libraries necessary for building?

FreeBSD: Incorrect command line parse throws "error: could not open directory"

Dear Jonathan,

Here is some difficulties running ngp on FreeBSD (13-STABLE). It compiles successfuly but when trying to run with actual command line parameters like:

ngp PATTERN

Moving forward in the order of execution:

int main(int argc, char *argv[]) {
 ..
    struct options_t *options = create_options(config, argc, argv);
     ..
       parse_args(options, argc, argv);

And reaches the piece of code where everything stops:

    int first_argument = 0;
    for (; optind < arg_count; optind++) {
        if (!first_argument) {
            strcpy(options->pattern, args[optind]);
            first_argument = 1;
        } else {
            strcpy(options->directory, args[optind]);
        }
    }

    free(args);

    DIR *dirp = opendir(options->directory);
    if (!dirp) {
        fprintf(stderr, "error: could not open directory \"%s\"\n",
                options->directory);

Can't grep lines that start with dash

It's a minor issue that can be avoided using -e

$ echo '-i' > test.txt
$ grep -r '\-i'
test.txt:-i
$ ngp '\-i'
(produces no output)
$ ngp -e '\-i'
(works fine)

Navigation issues

  • the "down" key can bring us to an empty page
  • there is no support for page up/page down

What needs to be done:

  • add page up/page down functionality (bugfree!)
  • factorize the up/down code so it may use the page up/down behavior

specific files issue

Specific files are not detected in other directories than the first level one.

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.