Giter Site home page Giter Site logo

fastlocate's Introduction

Table of Contents

fastlocate

fast locate a file or directory using locate command in linux.

The script can get the results according given keywords using locate command. When there is only one result, it will output only one path match the keywords. While reading a input when there are many results.

Combine the script and bash, we can do a lot of fast moves.

depends

the script depends the following software:

  • python3
  • mlocate

usage

usage: fastlocate.py [-h] (-d | -f) [-l LIMIT] [-i IGNORE]
                     keywords [keywords ...]

locate the file using locate command in linux.

positional arguments:
  keywords              keywords

optional arguments:
  -h, --help            show this help message and exit
  -d, --dir             to find directory.
  -f, --file            to find file.
  -l LIMIT, --limit LIMIT
                        the maximum number of the results.
  -i IGNORE, --ignore IGNORE
                        ignore the paths containing the given word.

Example

Search the directory whose base name is "test" and also whose path contains "Dropbox":

fastlocate.py -d test Dropbox

Because there is only one result. So it outputs:

/home/klniu/Dropbox/code/go/test

Search the directory whose base name is "ldar" and also whose path contains "Dropbox":

fastlocate.py -d ldar Dropbox

Because there are many results. So it outputs a menu for you to select the right item:

1) /home/klniu/Dropbox/code/python/ldar
2) /home/klniu/Dropbox/code/python/ldar/system/ldar
3) /home/klniu/Dropbox/documents/ldar
Please select the directory(default=1, "q" for quit):
input a integer and the script will output the right path. Press enter to select the first result, or "q" to quit.

Awesome

Combile the script and bash, we can move around fast:

put the fastlocate.py in some place, such as ~/bin, and:

chmod +x ~/bin/fastlocate.py

put the following functions into ~/.bashrc, we can do a lot of thing:

# cd around 
function lcd(){
    result=`~/bin/fastlocate.py -d $@|tee /dev/stderr`
    if [[ ! -z $result ]]; then
        cd $result
    fi
}

# vim a file around
function lvim(){
    result=`~/bin/fastlocate.py -f -i % $@|tee /dev/stderr`
    if [[ ! -z $result ]]; then
        vim -p -g --servername GVIM --remote-tab-silent $result
    fi
}

# krusader a file around
function lfm(){
    result=`~/bin/fastlocate.py -d $@|tee /dev/stderr`
    if [[ ! -z $result ]]; then
        krusader $result
    fi
}

# open a file using xdg-open
function open(){
    result=`$CODE/fastlocate/fastlocate.py -f $@|tee /dev/stderr`
    if [[ ! -z $result ]]; then
        xdg-open $result > /dev/null 2>&1 
    fi
}

In terminal, input:

lvim .bashrc /home
to edit .bashrc

lcd Dropbox
to change directory to Dropbox

lfm test /home
to open the test directory which locates in /home in krusader.

You can create your own functions to extend the script.

Tips

You can edit the /usr/lib/systemd/system/updatedb.timer to update the database of mlocate every hour.

[Unit]
Description=Daily locate database update

[Timer]
OnBootSec=10min
OnUnitActiveSec=1h
Persistent=true

fastlocate's People

Contributors

cowsmiles avatar

Stargazers

 avatar

Watchers

 avatar  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.