Package: busca-py
buscaCLI and library to search for files with content that most closely match the lines of a reference string.Table of ContentsbuscaTable of ContentsPython LibraryCommand Line InterfaceCLI UsageExamplesFind files that most closely match the sourcefile_5.pyfile in a search directoryFind files that most closely match the sourcepath_to_reference.jsonfile in a search directoryChange search to scan the current working directoryNarrow search to only consider.jsonfiles whose paths include the substring "foo" and that contain fewer than 1,000 linesPiped input mode to search the output of a commandCLI InstallationMac OSHomebrewAll platforms (Windows, MacOS, Linux)Compile from sourcePython Library🐍 The Python library is renamed tobusca_pydue to a name conflict with anexisting (possibly abandoned) project.pipinstallbusca_pyimportbusca_pyasbuscareference_file_path="./sample_dir_hello_world/file_1.py"withopen(reference_file_path,"r")asfile:reference_string=file.read()# Perform search with required parametersall_file_matches=busca.search_for_lines(reference_string=reference_string,search_path="./sample_dir_hello_world",)# File matches are returned in descending order of percent matchclosest_file_match=all_file_matches[0]assertclosest_file_match.path==reference_file_pathassertclosest_file_match.percent_match==1.0assertclosest_file_match.lines==reference_string# Perform search for top 5 matches with additional filters# to speed up runtime by skipping files that will not matchrelevant_file_matches=busca.search_for_lines(reference_string=reference_string,search_path="./sample_dir_hello_world",max_lines=10_000,include_globs=["*.py"],count=5,)assertlen(relevant_file_matches)<len(all_file_matches)# Create new file match objectnew_file_match=busca.FileMatch("file/path",1.0,"file\ncontent")Command Line InterfaceCLI Usage🧑‍💻️ To see usage documentation, runbusca-hOutput for v2.1.3Simple utility to search for files with content that most closely match the lines of a reference string

Usage: busca --ref-file-path <REF_FILE_PATH> [OPTIONS]
       <SomeCommand> | busca [OPTIONS]

Options:
  -r, --ref-file-path <REF_FILE_PATH>  Local or absolute path to the reference comparison file. Overrides any piped input
  -s, --search-path <SEARCH_PATH>      Directory or file in which to search. Defaults to CWD
  -m, --max-lines <MAX_LINES>          The number of lines to consider when comparing files. Files with more lines will be skipped [default: 10000]
  -i, --include-glob <INCLUDE_GLOB>    Globs that qualify a file for comparison
  -x, --exclude-glob <EXCLUDE_GLOB>    Globs that disqualify a file from comparison
  -c, --count <COUNT>                  Number of results to display [default: 10]
  -h, --help                           Print help
  -V, --version                        Print versionExamplesFind files that most closely match the sourcefile_5.pyfile in a search directory❯busca--ref-file-pathsample_dir_mix/file_5.py--search-pathsample_dir_mix

?Selectafiletocompare:sample_dir_mix/file_5.py++++++++++100.0%
>sample_dir_mix/file_5v2.py++++++++++97.5%sample_dir_mix/nested_dir/file_7.py++++42.3%sample_dir_mix/aldras/aldras_settings.py++24.1%sample_dir_mix/aldras/aldras_core.py++21.0%sample_dir_mix/file_3.py+13.2%sample_dir_mix/file_1.py+11.0%sample_dir_mix/file_2.py+9.4%sample_dir_mix/aldras/aldras_execute.py+7.5%sample_dir_mix/file_4.py+6.9%[↑↓tomove,entertoselect,typetofilter]Find files that most closely match the sourcepath_to_reference.jsonfile in a search directorybusca--ref-file-pathpath_to_reference.json--search-pathpath_to_search_dirChange search to scan the current working directorybusca--ref-file-pathpath_to_reference.jsonNarrow search to only consider.jsonfiles whose paths include the substring "foo" and that contain fewer than 1,000 linesbusca--ref-file-pathpath_to_reference.json--include-glob'*.json'--include-glob'**foo**'--max-lines1000Glob referencePiped input mode to search the output of a command# <SomeCommand> | busca [OPTIONS]echo'String to find in files.'|buscaMacOS piped input mode📝 There is anopen issuefor MacOS incrossterm, one of busca's dependencies, that does not allow prompt interactivity when using piped input. Therefore, when a non interactive mode is detected, the file matches will be displayed but not interactively.This can be worked around by adding the following aliases to your shell.bashrcor.zshrcfile:# Wrap commands for busca searchbusca_cmd_output(){eval"$*> /tmp/busca_search.tmp"&&busca-r/tmp/busca_search.tmp}One-liners to add the wrapper function:ShellCommandBashecho -e 'busca_cmd_output() {\n\teval "$* > /tmp/busca_search.tmp" && busca -r /tmp/busca_search.tmp\n}' >> ~/.bashrcZshecho -e 'busca_cmd_output() {\n\teval "$* > /tmp/busca_search.tmp" && busca -r /tmp/busca_search.tmp\n}' >> ~/.zshrcReload your shell for the function to become available:# busca_cmd_output <SomeCommand>busca_cmd_outputecho'String to find in files.'CLI InstallationMac OSHomebrewbrewtapnoahbaculi/busca
brewinstallbuscaTo update, runbrewupdate
brewupgradebuscaAll platforms (Windows, MacOS, Linux)Compile from sourceInstall Rustusingrustup.Clone this repo.In the root of this repo, runcargobuild--releaseAdd to path. For example, by copying the compiled binary to your local bin directory.cptarget/release/busca$HOME/bin/