Skip to content

Commit

Permalink
Add smart case setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Maarrk committed Jul 24, 2024
1 parent a2e9d46 commit 43db30d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Setting for smart case search

## [1.0.0] - 2024-07-24

Initial release with core functionality

[1.0.0]: https://github.com/Maarrk/silverbullet-grep/releases/tag/v1.0.0
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ You may want to set [Shortcuts](https://silverbullet.md/Shortcuts) for them.

The results are written to [[GREP RESULTS]] page, which is a regular [meta page](https://silverbullet.md/Meta%20Pages), but ignored in the search.

### Configuration

This plug can be configured in the SETTINGS, these are the default values and their usage:

```yaml
grep:
# ignore case when search pattern is all lowercase
smartCase: true
```

## Is it any good?

Yes.
Expand All @@ -63,7 +73,7 @@ Yes.

- Handles UTF-8
- Gives the same output on all platforms
- Better defaults (recursive search, parses `.gitignore`)
- Better defaults (recursive search, parses `.gitignore`, multithreaded)
- Flags that made it easy to create this output
- Should be available on the same platforms as SilverBullet, since it's written in Rust like [Deno](https://deno.com)

Expand Down
7 changes: 7 additions & 0 deletions grep.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { editor, shell } from "$sb/syscalls.ts";
import { readSetting } from "$sb/lib/settings_page.ts";

const VERSION = "1.0.0";

Expand All @@ -24,13 +25,19 @@ async function grep(
folder: string = "."
) {
console.log(`grep("${pattern}", ${literal}, "${folder}")`);

let smartCase = true;
const config = await readSetting("grep", {});
if (config && config.smartCase === false) smartCase = false;

let output: string;
try {
const result = await shell.run("rg", [
"--heading", // group by file
"--byte-offset", // location in file
"--type",
"md", // we're only interested in markdown
smartCase ? "--smart-case" : "--case-sensitive",
literal ? "--fixed-strings" : "--regexp",
pattern,
folder,
Expand Down

0 comments on commit 43db30d

Please sign in to comment.