Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

## **Differences**

| | **`cnf`** | **`scout(cnf)`** |
|------------------------------------|-------------------|-------------------------------|
| **Uses** | `libsolv` | `libsolv` |
| **Written in** | Rust | Shell, two packages in Python |
| **Detect enabled/disabled repos?** | Yes | Yes |
| **Tries to refresh repos** | No | Yes |
| **`bash` integration** | Yes | Yes |
| **`zsh` integration** | Yes | Yes |
| **Disable integration** | Uninstall package | Magic variable |
| **Localization** | Yes (UTF-8 only) | Yes |
| | **`cnf`** | **`scout(cnf)`** |
|------------------------------------|---------------------------|-------------------------------|
| **Uses** | `libsolv` | `libsolv` |
| **Written in** | Rust | Shell, two packages in Python |
| **Detect enabled/disabled repos?** | Yes | Yes |
| **Tries to refresh repos** | No | Yes |
| **`bash` integration** | Yes | Yes |
| **`zsh` integration** | Yes | Yes |
| **`fish` integration** | Included with fish 1.23.1 | Included with fish 1.23.1 |
| **Disable integration** | Uninstall package | Magic variable |
| **Localization** | Yes (UTF-8 only) | Yes |
| **Package Managers Queried** | Dnf5, Zypper | Zypper |

## **Build**

Expand All @@ -32,8 +34,8 @@ To query not installed programs:
```
> ```.log
> The program 'cmake' can be found in following packages:
> * cmake-full [ path: /usr/bin/cmake, repository: zypp (repo-oss) ]
> * cmake-mini [ path: /usr/bin/cmake, repository: zypp (repo-oss) ]
> * cmake-full [ path: /usr/bin/cmake, repository: repo-oss ]
> * cmake-mini [ path: /usr/bin/cmake, repository: repo-oss ]
>
> Try installing with:
> sudo zypper install <selected_package>
Expand All @@ -57,17 +59,17 @@ To query installed programs in `/usr/bin`:
> Absolute path to 'vim' is '/usr/bin/vim'. Please check your $PATH variable to see whether it contains the mentioned path
> ```

## **Integrate with `bash`**
## **Integrate with `bash`, `zsh`, and `fish`**

```.sh
source command_not_found_bash
source command_not_found.bash # or command_not_found.zsh, or command_not_found.fish
export COMMAND_NOT_FOUND_BIN=./target/debug/cnf
cmake
```
> ```.log
> The program 'cmake' can be found in following packages:
> * cmake-full [ path: /usr/bin/cmake, repository: zypp (repo-oss) ]
> * cmake-mini [ path: /usr/bin/cmake, repository: zypp (repo-oss) ]
> * cmake-full [ path: /usr/bin/cmake, repository: repo-oss ]
> * cmake-mini [ path: /usr/bin/cmake, repository: repo-oss ]
>
> Try installing with:
> sudo zypper install <selected_package>
Expand All @@ -85,13 +87,19 @@ The testing itself is wrapped in [bats](https://github.com/bats-core/bats-core)
> ```.log
> test.bats
> ✓ root: installed /usr/bin/rpm
> ✓ root: installed /usr/sbin/sysctl
> ✓ root: not installed single package
> ✓ root: not installed more packages
> ✓ root: bash handler: not installed more packages
> ✓ nonroot: not installed more packages
>
> 6 tests, 0 failures
> > ✓ root: installed /usr/sbin/sysctl
> ✓ root: not installed xnake
> ✓ root: not installed make
> ✓ root: not installed cmake
> ✓ nonroot: not installed cmake
> ✓ nonroot: bash without handler: not installed cmake
> ✓ nonroot: bash handler: not installed cmake
> ✓ nonroot: zsh without handler: not installed cmake
> ✓ nonroot: zsh handler: not installed cmake
> ✓ nonroot: fish handler: not installed cmake
> ✓ issue26: do not list not installable files
>
> 12 tests, 0 failures
> ```

Every test can be executed on a command line. The `root.sh` wrapper mounts the
Expand Down
7 changes: 5 additions & 2 deletions cnf.1
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ cnf \- A command not found handler for openSUSE
libsolv(3) under the hood. The source of truth of information about
repositories, packages and their content.
.PP
This works with enabled dnf5 or zypper repostiores: the first one found in /usr/bin will be used.
Use dnf5 \-\-refresh makecache or zypper \-\-force refresh to update the metadata used.
.PP
It is typically called through command-not-found mechanism of bash(1) or zsh(1)
or fish(1). This is enabled via installing the cnf-bash or cnf-zsh
packages. Simply typing missing command executes the handler.
.PP
cmake

The program 'cmake' can be found in following packages:
* cmake-full [ path: /usr/bin/cmake, repository: zypp (repo-oss) ]
* cmake-mini [ path: /usr/bin/cmake, repository: zypp (repo-oss) ]
* cmake-full [ path: /usr/bin/cmake, repository: repo-oss ]
* cmake-mini [ path: /usr/bin/cmake, repository: repo-oss ]

Try installing with:
sudo zypper install <selected_package>
Expand Down
7 changes: 7 additions & 0 deletions command_not_found.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function fish_command_not_found
if test -z "$COMMAND_NOT_FOUND_BIN"
set -l COMMAND_NOT_FOUND_BIN /usr/bin/cnf
end
# The 'env' is there in case your fish is older than v3.0.0
env $COMMAND_NOT_FOUND_BIN $argv[1]
end
5 changes: 3 additions & 2 deletions command_not_found.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
# - one to be generic command_not_found_handler() and to be hooked
# - one to be available when command_not_found_handler() is redefined
function command_not_found_handler cnf_handler {
if [ -x /usr/bin/cnf ]; then
local cnf_bin=${COMMAND_NOT_FOUND_BIN:-/usr/bin/cnf}
if [ -x $cnf_bin ]; then
# take first parameter and remove quotes if there were any so
# $ 'foo'
# will search for foo
/usr/bin/cnf "${(Q)1}"
$cnf_bin "${(Q)1}"
fi
}
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ mod pool;

const ZYPPER_REPO_GLOB: &str = "/etc/zypp/repos.d/*.repo";
// Default value of the reposdir configuration directory
const DNF5_REPOS_GLOBS: [&str; 3] = [
// (Note that /etc/dnf/repos.d is patched in by the openSUSE dnf5 package)
const DNF5_REPOS_GLOBS: [&str; 4] = [
"/etc/dnf/repos.d/*.repo",
"/etc/yum.repos.d/*.repo",
"/etc/distro.repos.d/*.repo",
"/usr/share/dnf5/repos.d/*.repo",
Expand Down Expand Up @@ -70,8 +72,11 @@ fn main() {
let pm = if Path::exists(Path::new("/usr/bin/dnf5")) {
// Use DNF5 if it's installed (this should probably be set via a config file, in case you have both installed but prefer zypper)
PackageManager::Dnf5
} else {
} else if Path::exists(Path::new("/usr/bin/zypper")) {
PackageManager::Zypper
} else {
println!("Neither /usr/bin/dnf5 nor /usr/bin/zypper could be found.");
exit(127);
};

let repos = match load_repos(pm) {
Expand Down