├── install.sh ├── bloc-populate ├── LICENSE ├── bloc └── README.md /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # bloc installer script 4 | 5 | installPath="$1" 6 | dbPath="$2/bloc.db" 7 | 8 | echo "exporting $installPath into $PATH" 9 | export $PATH=$PATH:$installPath 10 | echo "Installing bloc" 11 | replace "#DEFAULT" "$dbPath" -- ./bloc 12 | replace "#DEFAULT" "$dbPath" -- ./bloc-populate 13 | echo "linking bloc from current folder into $installPath" 14 | ln -s ./bloc $installPath/bloc 15 | echo "linking bloc-populate from current folder into $installPath" 16 | ln -s ./bloc-populate $installPath/bloc-populate 17 | echo "Populating bloc database" 18 | bloc-populate -o $dbPath -v 19 | -------------------------------------------------------------------------------- /bloc-populate: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Populate bloc database 3 | 4 | output=#DEFAULT 5 | 6 | function usage { 7 | echo "Usage: populate-bloc [options] 8 | -h, --help print this message 9 | -v, --verbose verbose 10 | -vv,-v2 second verbosity level, more data shown 11 | -o specify output database file. default: #DEFAULT" 12 | } 13 | 14 | if [ $# -gt 0 ]; then 15 | while [ -n "$1" ] 16 | do 17 | case $1 in 18 | -o) 19 | shift 20 | case $1 in 21 | -*|"") 22 | ;; 23 | *) 24 | output=$1 25 | ;; 26 | esac 27 | ;; 28 | -h|--help) 29 | usage 30 | exit 31 | ;; 32 | -v|--verbose) 33 | verbose=true 34 | ;; 35 | -v2|-vv) 36 | verbose=true 37 | verbose2=true 38 | ;; 39 | 40 | *) 41 | usage 42 | exit 43 | ;; 44 | esac 45 | shift 46 | done 47 | fi 48 | 49 | if [ $verbose2 ]; then 50 | find / > $output 51 | else 52 | (find / 2>/dev/null > $output) 53 | fi 54 | 55 | if [ $verbose ]; then 56 | echo "Generated database file on $output" 57 | fi 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 bootzin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bloc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Searches system for a file or directory 4 | 5 | database=#DEFAULT 6 | #$HOME/Software/bloc/bloc.db 7 | searcher='rg -Np' 8 | dataout="" 9 | file="" 10 | 11 | function help { 12 | echo "Usage: bloc [OPTIONS] FILE 13 | Searches system for a file or directory 14 | -h, --help displays this help message and exits. 15 | -c specifies where to load the database from 16 | -s specifies searcher to be used. Defaults to ripgrep. Additional commands may be used within '' i.e. 'grep -v' 17 | -v, --verbose verbose 18 | -v2, -vv Second verbosity level, outputs more information 19 | -p, --populate populate bloc database and saves it to . If no arguments are given it defaults to #DEFAULT" 20 | } 21 | 22 | 23 | 24 | if [ $# -gt 0 ]; then 25 | while [ -n "$1" ] 26 | do 27 | case $1 in 28 | -c) shift 29 | database=$1 30 | ;; 31 | -s) shift 32 | searcher=$1 33 | ;; 34 | -v|--verbose|-v2|-vv) 35 | verbose=true 36 | v=$1 37 | ;; 38 | -h|--help) 39 | help 40 | exit 41 | ;; 42 | --populate|-p) 43 | populate=true 44 | if [ $# -gt 0 ]; then 45 | case $2 in 46 | -*) 47 | ;; 48 | *) 49 | shift 50 | dataout=$1 51 | ;; 52 | esac 53 | fi 54 | ;; 55 | *) 56 | file=$1 57 | search=true 58 | ;; 59 | esac 60 | shift 61 | done 62 | 63 | if [ $populate ]; then 64 | if [ -n $dataout ]; then 65 | if [ $verbose ]; then 66 | bloc-populate $v -o $dataout 67 | else 68 | bloc-populate -o $dataout 69 | fi 70 | else 71 | if [ $verbose ]; then 72 | bloc-populate $v 73 | else 74 | bloc-populate 75 | fi 76 | fi 77 | fi 78 | 79 | if [ $search ]; then 80 | ($searcher $file $database) 81 | if [ $verbose ]; then 82 | echo "Searched for `tput setaf 1`\"$file\" `tput sgr0`with database:`tput setaf 1`[$database] `tput sgr0`using `tput setaf 1`\"$searcher\"`tput sgr0`" 83 | fi 84 | fi 85 | 86 | else 87 | help 88 | fi 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Locating your files has never been faster! 2 | 3 | **bloc** is a **b**etter **loc**ate which is capable of quickly finding any file/archive you have stored in your computer with as much flexibility as needed. The speed increase may be of up to 10 times faster compared to normal locate, and up to 30 times compared to find. (Pictures will be available in a future release) 4 | 5 | ### How it works 6 | `bloc`works pretty much in the same way that locate does: it is a cli searching tool that creates a database where it looks for the specified file or directory and outputs its name/location to STDOUT. The 2 major differences here are that: 7 | 8 | * 1: `bloc` does not compress the database. 9 | whereas this means that the database file is larger, it also means that it doesn't have to waste time decompressing the database before searching for certain query. Moreover, most tests reported that locate can only decrease database size to about a third of the original's, which, nowadays, isn't that much of a problem for most computers. 10 | 11 | * 2: `bloc` uses [rg](https://github.com/BurntSushi/ripgrep) to search for it's files, which provides a much faster result than most other search tools. 12 | 13 | ### Prerequisites 14 | * [rg](https://github.com/BurntSushi/ripgrep) (Optional if you change the default searching tool in the bloc file) 15 | 16 | ### Installation 17 | 18 | Installation of `bloc` can be made by running the install script provided, it needs two arguments, or it won't work. The first is the install directory. As of now, the script will create a symbolic link into that specified install folder, and add that folder to $PATH, a later release will allow you to choose whether to have it symlinked or hard copied. The second argument is the place where you want to store the database, and where the database will be stored by default on future updates. Please keep in mind that neither of these values have a default yet, it shall be added soon though. 19 | 20 | The other option that you have is to follow below instructions, in case you have any problems with the installation script. 21 | 22 | **1.** Clone this repo to your local machine 23 | 24 | git clone https://github.com/bootzin/bloc 25 | 26 | **2** Add `bloc` to your local bin folder so that you can execute it from anywhere. I usually keep them on a separate folder and symlink them to ~/bin (which must be in $PATH). 27 | 28 | **3** Edit the default path for database file in bloc/bloc-populate. They default to ~/Software/bloc, but make sure that folder exists before running the program. 29 | 30 | **4.** Run `bloc-populate` or `bloc -p` in order to create the initial database (In a future release `bloc` will automatically do this before it's first run) 31 | 32 | bloc --populate 33 | 34 | **5.** [Optional] Add on your autostart script an execution command to populate bloc database, so that when you start the system it gets automatically updated 35 | 36 | ### Usage 37 | 38 | Usage: bloc [OPTIONS] FILE 39 | Searches system for a file or directory 40 | -h, --help displays this help message and exits. 41 | -c specifies where to load the database from 42 | -s specifies searcher to be used. Defaults to ripgrep. Additional commands may be used within '' i.e. 'grep -v' 43 | -v, --verbose verbose 44 | -v2, -vv Second verbosity level, more information is shown 45 | -p, --populate populate bloc database and saves it to . Default saves to ~/Software/bloc.db 46 | 47 | ### Autoupdate 48 | 49 | As of now there are two main ways of performing automatic updates of `bloc`. The first one is to use [cron](https://en.wikipedia.org/wiki/Cron) to schedule regular interval updates by adding 50 | 51 | */5 * * * bloc -p 52 | 53 | in your cronstab file, which will perform the update every 5 minutes. The other one is by using a useful program created by z3bra called [wendy](https://github.com/z3bra/wendy). What this program does is it checks for changes under certain directory and executes a command if any changes are detected. The command you'd use in this case would be 54 | 55 | wendy -f /home/user/ -t 300 bloc -p 56 | 57 | which would check at every 5 minutes if there's been a change in your $HOME dir and if there is, it would perform an update. This would work because every time you run a shell command it gets registered under your history file (.bash-history, .zsh-history, etc), and wendy would detect that change. If your shell doesn't have a history then you have to stick with the first method. 58 | 59 | ### Tips 60 | 61 | * By default `bloc` does not detect files/directories you do not normally have access to. To change this, simply run `bloc -p` as sudo, and it will detect /root/ files as well 62 | * You can use any searching toll you want with bloc (grep, ag, ack ...), as long as you pass it as an argument using the `-s` tag or change the default searcher command in the bloc file 63 | * If you want to add any arguments to the searcher (i.e. -v, -E, -N) you can do so by specifing them with the `-s` tag, they should all work just right! (Remember to also add the searcher you're using, i.e 'rg -vE') 64 | * You can populate `bloc` database by running `bloc -p` instead of `bloc-populate` 65 | * bloc-populate can recieve an output file as an argument when used with the `-o` tag 66 | * You can use the `-c` tag on `bloc` to make it search for inside file, not just its database 67 | 68 | ### Troubleshooting 69 | 70 | If you're getting /root/path/to/db instead of /home/user/path/to/db in when running `bloc-populate` as sudo make sure you have the following line in your sudoers file: 71 | 72 | Default env_keep += "HOME" 73 | 74 | Besides that, leave me an Issue reporting the steps necessary to reproduce the error you've got and I'll look into it 75 | 76 | ### License 77 | 78 | This Project is Lincensed under the MIT License 79 | 80 | #### Disclaimer 81 | This is a WIP, I intend to implement more functionalities to `bloc` to make it even better. For now, if you have any ideas you wish to contribute, please feel free to contact me (: 82 | --------------------------------------------------------------------------------