Thanks to visit codestin.com
Credit goes to github.com

Skip to content

openSUSE/cnf

Repository files navigation

Command not found handler for openSUSE

  1. A replacement for a python based command-not-found handler for openSUSE.
  2. Written in Rust, so has as few runtime dependencies as is possible.
  3. Uses libsolv under the hood, so is 100% compatible with zypper.

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
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, Dnf4, Zypper Zypper

Build

cargo build

Direct usage

To query not installed programs:

./target/debug/cnf cmake
The program 'cmake' can be found in following packages:
  * 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>

To query installed programs in /usr/sbin:

./target/debug/cnf chcpu
Absolute path to 'chcpu' is '/usr/sbin/chcpu', so running it may require superuser privileges (eg. root).

To query installed programs in /usr/bin:

./target/debug/cnf vim
Absolute path to 'vim' is '/usr/bin/vim'. Please check your $PATH variable to see whether it contains the mentioned path

Integrate with bash, zsh, and fish

source command_not_found.bash # or command_not_found.zsh, or command_not_found.fish
export COMMAND_NOT_FOUND_BIN=./target/debug/cnf
cmake
The program 'cmake' can be found in following packages:
  * 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>

Integration tests

Integration tests run inside docker images tagged local/cnf-ci-zypper, local/cnf-ci-dnf, and local/cnf-ci-dnf5; these are built as a part of a Github Action and can be built locally with:

for pm in zypper dnf dnf5; do
    docker build -t local/cnf-ci-$pm:latest -f test/$pm.dockerfile test
done

The testing itself is wrapped in bats and in order to make it run, one needs to initialize the git submodules (git submodule update --init). Then tests can be executed using following command

./test/bats/bin/bats ./test/
test.bats
 ✓ zypper root: installed /usr/bin/rpm
 ✓ zypper root: installed /usr/sbin/sysctl
 ✓ zypper root: not installed xnake
 ✓ zypper root: not installed make
 ✓ zypper root: not installed cmake
 ✓ zypper nonroot: not installed cmake
 ✓ zypper nonroot: bash without handler: not installed cmake
 ✓ zypper nonroot: bash handler: not installed cmake
 ✓ zypper nonroot: zsh without handler: not installed cmake
 ✓ zypper nonroot: zsh handler: not installed cmake
 ✓ zypper nonroot: fish handler: not installed cmake
 ✓ zypper issue26: do not list not installable files
 ✓ dnf root: installed /usr/bin/rpm
 ✓ dnf root: installed /usr/sbin/sysctl
 ✓ dnf root: not installed xnake
 ✓ dnf root: not installed make
 ✓ dnf root: not installed cmake
 ✓ dnf nonroot: not installed cmake
 ✓ dnf nonroot: bash without handler: not installed cmake
 ✓ dnf nonroot: bash handler: not installed cmake
 ✓ dnf nonroot: zsh without handler: not installed cmake
 ✓ dnf nonroot: zsh handler: not installed cmake
 ✓ dnf nonroot: fish handler: not installed cmake
 ✓ dnf issue26: do not list not installable files
 ✓ dnf5 root: installed /usr/bin/rpm
 ✓ dnf5 root: installed /usr/sbin/sysctl
 ✓ dnf5 root: not installed xnake
 ✓ dnf5 root: not installed make
 ✓ dnf5 root: not installed cmake
 ✓ dnf5 nonroot: not installed cmake
 ✓ dnf5 nonroot: bash without handler: not installed cmake
 ✓ dnf5 nonroot: bash handler: not installed cmake
 ✓ dnf5 nonroot: zsh without handler: not installed cmake
 ✓ dnf5 nonroot: zsh handler: not installed cmake
 ✓ dnf5 nonroot: fish handler: not installed cmake
 ✓ dnf5 issue26: do not list not installable files

36 tests, 0 failures

Every test can be executed on a command line. The `root.sh` wrapper mounts the
binary to `/usr/bin/cnf` and bash/fish integrations.

```.sh
./root.sh /usr/bin/cnf rpm
Absolute path to 'rpm' is '/usr/bin/rpm'. Please check your $PATH variable to see whether it contains the mentioned path

dnf backend

The step by step instructions for how to test the dnf part is

distrobox ephemeral
sudo zypper install dnf rpm-repos-openSUSE-Tumbleweed libcurl4
sudo dnf makecache
# run osc getbinaries utilities cnf openSUSE_Factory x86_64
sudo zypper in binaries/cnf-0.9*x86_64.rpm
cnf fractal

The program 'fractal' can be found in the following package:
  * fractal [ path: /usr/bin/fractal, repository: opensuse-tumbleweed-oss ]

Try installing with:
    sudo dnf install fractal

libcurl4 dependency is mandatory avoiding the No handler specified error from dnf/dnf5.

PowerShell users

As cnf does not integrate with PowerShell by default, please read the issue comment #8 (comment) to learn how to configure your system properly:

Here's an example command_not_found.ps1 file that somewhat emulates what command_not_found.bash does:

#!/usr/bin/env -S pwsh

#Requires -PSEdition Core
#Requires -Version 7

$Env:TEXTDOMAINDIR = '/usr/share/locale'
$Env:TEXTDOMAIN = 'cnf'

$ExecutionContext.InvokeCommand.CommandNotFoundAction = {

    param($commandAsSubmitted, $commandLookupEventArgs)

    # Ignore the following invocations via:
    # *   A 'get-*' prefix stemming from PowerShell's default-verb logic;
    # *   A repeated lookup in the *current* dir. (./…) - PowerShell itself will provide feedback on that; and
    # *   Calls from scripts.
    if ($commandAsSubmitted -like 'Get-*' -or $commandAsSubmitted -like '.[/\]*' -or (Get-PSCallStack)[1].ScriptName) { return }

    # Determine the executable path.
    $cnf_bin = $env:COMMAND_NOT_FOUND_BIN ?? '/usr/bin/cnf'

    # Invoke and output the results directly to the terminal (host).
    & $cnf_bin $commandAsSubmitted *>&1 | Out-Host

    # Note:
    # *   PowerShell's not-found error is seemingly invariably printed afterwards; the following does *NOT* prevent that:
    #     ```.PS1
    #     $commandLookupEventArgs.StopSearch = $true
    #     ```
    # *   Supposedly, returning a `[System.Management.Automation.CommandInfo]` instance - such as output by `Get-Command` - can provide the command to execute, but that doesn't seem to work.

}
  • This script can be invoked directly (doesn't need sourcing); e.g.. ./command_not_found.ps1
  • A call to this script (or the code it contains) is best placed in the user's $PROFILE file.
  • As in the Bash case, the mechanism supports only one custom command-not-found handler.
    • However, a plug-in system is being worked on that supports multiple third-party handlers, called feedback providers - see this blog post.
    • Someone could write a custom feedback provider that incorporates cnf, similar to the one in the command-not-found provider; the latter currently relies solely on the presence of /usr/lib/command-not-found, as preinstalled on Ubuntu distros.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published