Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Ability for west grep to output relative or absolute paths #714

Open
jhedberg opened this issue Jun 24, 2024 · 1 comment

Comments

@jhedberg
Copy link
Member

jhedberg commented Jun 24, 2024

Currently, west grep groups the output per-module, having a "header" line for each module and then results relative to that module's root directory. This may be fine for manual/human processing of the output, but it makes it more difficult to integrate it with an editor (to automatically be able to jump to the file/line in question) or even for a human to just copy-paste the full file location to the command line.

Current output:

❯ west grep lfs_format
=== manifest (zephyr):
subsys/fs/littlefs_fs.c:			ret = lfs_format(&fs->lfs, &fs->cfg);
subsys/fs/littlefs_fs.c:	ret = lfs_format(&fs->lfs, &fs->cfg);
=== littlefs (modules/fs/littlefs):
README.md:        lfs_format(&lfs, &cfg);
benches/bench_dir.toml:    lfs_format(&lfs, cfg) => 0;

Desired output:

❯ west topdir
/Users/johedber/src/zephyr
❯ pwd
/Users/johedber/src/zephyr/zephyr
❯ west grep --relative lfs_format
subsys/fs/littlefs_fs.c:			ret = lfs_format(&fs->lfs, &fs->cfg);
subsys/fs/littlefs_fs.c:	ret = lfs_format(&fs->lfs, &fs->cfg);
../modules/fs/littlefs/README.md:        lfs_format(&lfs, &cfg);
../modules/fs/littlefs/benches/bench_dir.toml:    lfs_format(&lfs, cfg) => 0;

Alternative (or in addition to the above):

❯ west topdir
/Users/johedber/src/zephyr
❯ pwd
/Users/johedber/src/zephyr/zephyr
❯ west grep --absolute lfs_format
/Users/johedber/src/zephyr/zephyr/subsys/fs/littlefs_fs.c:			ret = lfs_format(&fs->lfs, &fs->cfg);
/Users/johedber/src/zephyr/zephyr/subsys/fs/littlefs_fs.c:	ret = lfs_format(&fs->lfs, &fs->cfg);
/Users/johedber/src/zephyr/modules/fs/littlefs/README.md:        lfs_format(&lfs, &cfg);
/Users/johedber/src/zephyr/modules/fs/littlefs/benches/bench_dir.toml:    lfs_format(&lfs, cfg) => 0;
@jhedberg
Copy link
Member Author

Note to self: The editor integration is, at least in the short term, probably easiest done by avoiding west grep and instead using ripgrep as follows:

rg --vimgrep $(west topdir) -e <pattern>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant