GithubHelp home page GithubHelp logo

smorin / fsql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kashav/fsql

0.0 2.0 0.0 4.3 MB

Search through your filesystem with SQL-esque queries.

License: MIT License

Makefile 1.02% Go 98.98%

fsql's Introduction

fsql

Search through your file system with SQL-esque queries.

Demo

fsql.gif

Setup / installation

Requires Go to be installed and configured.

Install with go get:

$ go get -v github.com/kshvmdn/fsql/...
$ which fsql
$GOPATH/bin/fsql

Or, install directly via source:

$ git clone https://github.com/kshvmdn/fsql.git $GOPATH/src/github.com/kshvmdn/fsql
$ cd $_ # $GOPATH/src/github.com/kshvmdn/fsql
$ make install && make
$ ./fsql

Usage

fsql expects the query as a command line argument.

Query syntax

In general, each query requires one or more attributes, one or more source directories, and a condition.

SELECT attribute, ... FROM source, ... WHERE conditonal

Attribute

Currently supported attributes include name, size, mode, time, or * (for all).

Source

Each source should be a relative or absolute path to some directory on your machine. You can also use environment variables (e.g. $GOPATH) or ~ (for your home directory).

Use - to exclude a directory. For example, to exclude .git: "... FROM ., -.git/ ...".

Condition

Conjunction/Disjunction

Use AND / OR to join conditions. Note that precedence is assigned based on order of appearance.

This means "WHERE a AND b OR c" is not the same as "WHERE c OR b AND a". Use parentheses to get around this behaviour, "WHERE a AND b OR c" is the same as "WHERE c OR (b AND a)".

Negation

Use NOT to negate a condition. This keyword must precede the condition (e.g. "... WHERE NOT a ...").

Note that wrapping parentheses with NOT is currently not supported. This can easily be resolved with De Morgan's laws. For example, ... WHERE NOT (a AND b) ... is the same as ... WHERE NOT a OR NOT b ....

Condition Syntax

A single condition is made up of 3 parts: attribute, comparator, and value.

attribute

A valid attribute is any of the following: name, size, mode, time.

comparator

Comparators depend on the attribute.

For name:

  • = - Strings that are an exact match.
  • <> - Synonymous to using WHERE NOT ... = ....
  • LIKE - For simple pattern matching. Use % to match zero, one, or multiple characters. Check that a string begins with a value: <value>%, ends with a value: %<value>, or contains a value: <value>.
  • RLIKE - For pattern matching with regular expressions.

For size and time:

  • >
  • >=
  • <
  • <=
  • =
  • <>

And, for mode:

  • IS
value

If the value contains spaces and/or escaped characters, wrap the value in quotes (either single or double) or backticks.

The default unit for size is bytes. To use kilobytes / megabytes / gigabytes, append kb / mb / gb to the size value (e.g. 100kb for 100 kilobytes).

Attribute mode only has 2 supported values: DIR (to check that the file is a directory) and REG (to check that the file is regular).

Use the following format for time values: MMM DD YYYY HH MM (eg. Jan 02 2006 15 04).

Examples

List all files & directories in Desktop and Downloads that contain csc in the name:

$ fsql "SELECT name FROM ~/Desktop, ~/Downloads WHERE name LIKE %csc%"
$ # this is equivalent to:
$ fsql "SELECT name FROM ~/Desktop, ~/Downloads WHERE name RLIKE .*csc.*"

List all JavaScript files in the current directory that were modified after April 1st 2017 (try running this on a node_modules directory, it's fast ๐Ÿ˜Ž).

$ fsql "SELECT name, size, time FROM . WHERE name LIKE %.js AND time > 'Apr 01 2017 00 00'"

List all files named main.go in $GOPATH which are larger than 10.5 kilobytes or smaller than 100 bytes.

$ fsql "SELECT * FROM $GOPATH WHERE name = main.go AND (size >= 10.5kb OR size < 100)"

Contribute

This project is completely open source, feel free to open an issue or submit a pull request.

Before submitting code, please ensure your changes comply with Golint. Use make lint to test this.

Credits

Lexer & parser are based on the work of JamesOwenHall (json2, timed).

License

fsql source code is available under the MIT license.

fsql's People

Contributors

kashav avatar

Watchers

James Cloos avatar  avatar

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.