Update command-not-found
This commit is contained in:
parent
02eb3a1a7f
commit
d03f7fe6a5
|
@ -1,15 +1,10 @@
|
|||
TERMUX_PKG_HOMEPAGE=http://termux.com
|
||||
TERMUX_PKG_DESCRIPTION="Suggest installation of packages in interactive shell sessions"
|
||||
TERMUX_PKG_VERSION=0.3
|
||||
TERMUX_PKG_VERSION=0.4
|
||||
|
||||
termux_step_make_install () {
|
||||
TERMUX_SHARE_DIR=$TERMUX_PREFIX/share/termux
|
||||
mkdir -p $TERMUX_SHARE_DIR
|
||||
cp $TERMUX_PKG_BUILDER_DIR/commands.txt $TERMUX_SHARE_DIR/commands.txt
|
||||
|
||||
TERMUX_LIBEXEC_DIR=$TERMUX_PREFIX/libexec/termux
|
||||
mkdir -p $TERMUX_LIBEXEC_DIR
|
||||
$CC $CFLAGS $LDFLAGS -std=c11 $TERMUX_PKG_BUILDER_DIR/command-not-found.c \
|
||||
-DTERMUX_COMMANDS_LISTING=$TERMUX_PREFIX/share/termux/commands.txt \
|
||||
$CC -Wall -Wextra -Werror -pedantic $CFLAGS $LDFLAGS -std=c11 $TERMUX_PKG_BUILDER_DIR/command-not-found.c \
|
||||
-o $TERMUX_LIBEXEC_DIR/command-not-found
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define STRINGIFY(x) #x
|
||||
#define TOSTRING(x) STRINGIFY(x)
|
||||
#include "commands.h"
|
||||
|
||||
inline int termux_min3(unsigned int a, unsigned int b, unsigned int c) {
|
||||
return (a < b ? (a < c ? a : c) : (b < c ? b : c));
|
||||
|
@ -31,26 +30,16 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
char* command_not_found = argv[1];
|
||||
|
||||
FILE* commands_file = fopen(TOSTRING(TERMUX_COMMANDS_LISTING), "r");
|
||||
if (commands_file == NULL) {
|
||||
perror(TOSTRING(TERMUX_COMMANDS_LISTING));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int best_distance = -1;
|
||||
int guesses_at_best_distance = 0;
|
||||
char current_package[128];
|
||||
char best_package_guess[128];
|
||||
char best_command_guess[128];
|
||||
char* current_line = NULL;
|
||||
while (true) {
|
||||
size_t buffer_length = sizeof(current_line);
|
||||
ssize_t read_bytes = getline(¤t_line, &buffer_length, commands_file);
|
||||
if (read_bytes <= 1) break;
|
||||
size_t line_length = strlen(current_line);
|
||||
current_line[line_length-1] = 0;
|
||||
const int num_commands = sizeof(commands) / sizeof(commands[0]);
|
||||
for (int i = 0; i < num_commands; i++) {
|
||||
char const* current_line = commands[i];
|
||||
if (current_line[0] == ' ') { // Binary
|
||||
char* binary_name = current_line + 1;
|
||||
char const* binary_name = current_line + 1;
|
||||
int distance = termux_levenshtein_distance(command_not_found, binary_name);
|
||||
if (distance == 0 && strcmp(command_not_found, binary_name) == 0) {
|
||||
printf("The program '%s' is currently not installed. You can install it by executing:\n apt install %s\n", binary_name, current_package);
|
||||
|
@ -77,15 +66,10 @@ int main(int argc, char** argv) {
|
|||
printf(" Command '%s' from package '%s'\n", best_command_guess, best_package_guess);
|
||||
} else {
|
||||
// Multiple suggestions at the same distance - show them all:
|
||||
rewind(commands_file);
|
||||
while (true) {
|
||||
size_t buffer_length = sizeof(current_line);
|
||||
ssize_t read_bytes = getline(¤t_line, &buffer_length, commands_file);
|
||||
if (read_bytes <= 1) break;
|
||||
size_t line_length = strlen(current_line);
|
||||
current_line[line_length-1] = 0;
|
||||
for (int i = 0; i < num_commands; i++) {
|
||||
char const* current_line = commands[i];
|
||||
if (current_line[0] == ' ') { // Binary
|
||||
char* binary_name = current_line + 1;
|
||||
char const* binary_name = current_line + 1;
|
||||
int distance = termux_levenshtein_distance(command_not_found, binary_name);
|
||||
if (best_distance == distance) {
|
||||
printf(" Command '%s' from package '%s'\n", binary_name, current_package);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue