Skip to content

Commit

Permalink
Make --top-level the default behavior of nix-locate
Browse files Browse the repository at this point in the history
It happens pretty often to me that I'm trying to find out which packages
contain a certain header file (e.g. `unistd.h`). In those cases I
usually don't care at all about which e.g. FHS env has this header as
well.

I can't remember a single time where this was actually helpful, so I'm
questioning whether this is a sensible default. I'll use this patch in
my own setup for now, but I thought I could suggest it here as well.
  • Loading branch information
Ma27 committed Feb 24, 2024
1 parent b5fcd08 commit 2b48ed1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
### Added
### Fixed
### Changed

* `--top-level` is now the default. To use the old default, add `--all`.

### Removed

## 0.1.7
Expand Down
2 changes: 1 addition & 1 deletion command-not-found.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ command_not_found_handle () {

toplevel=nixpkgs # nixpkgs should always be available even in NixOS
cmd=$1
attrs=$(@out@/bin/nix-locate --minimal --no-group --type x --type s --top-level --whole-name --at-root "/bin/$cmd")
attrs=$(@out@/bin/nix-locate --minimal --no-group --type x --type s --whole-name --at-root "/bin/$cmd")
len=$(echo -n "$attrs" | grep -c "^")

case $len in
Expand Down
6 changes: 3 additions & 3 deletions src/bin/nix-locate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn process_args(matches: Opts) -> result::Result<Args, clap::Error> {
file_type: matches
.r#type
.unwrap_or_else(|| files::ALL_FILE_TYPES.to_vec()),
only_toplevel: matches.top_level,
only_toplevel: !matches.all,
color,
minimal: matches.minimal,
};
Expand Down Expand Up @@ -255,9 +255,9 @@ struct Opts {
#[clap(long, name = "HASH")]
hash: Option<String>,

/// Only print matches from packages that show up in `nix-env -qa`.
/// Print all matches, not only print from packages that show up in `nix-env -qa`.
#[clap(long)]
top_level: bool,
all: bool,

/// Only print matches for files that have this type. If the option is given multiple times,
/// a file will be printed if it has any of the given types.
Expand Down

0 comments on commit 2b48ed1

Please sign in to comment.