Browse Source

command-not-found: Print to stderr (fixes #1308)

android-5
Fredrik Fornwall 7 years ago
parent
commit
c3629906c0
  1. 2
      packages/command-not-found/build.sh
  2. 14
      packages/command-not-found/command-not-found.c
  3. 130
      packages/command-not-found/commands.h

2
packages/command-not-found/build.sh

@ -1,6 +1,6 @@
TERMUX_PKG_HOMEPAGE=https://termux.com TERMUX_PKG_HOMEPAGE=https://termux.com
TERMUX_PKG_DESCRIPTION="Suggest installation of packages in interactive shell sessions" TERMUX_PKG_DESCRIPTION="Suggest installation of packages in interactive shell sessions"
TERMUX_PKG_VERSION=1.24 TERMUX_PKG_VERSION=1.25
termux_step_make_install () { termux_step_make_install () {
TERMUX_LIBEXEC_DIR=$TERMUX_PREFIX/libexec/termux TERMUX_LIBEXEC_DIR=$TERMUX_PREFIX/libexec/termux

14
packages/command-not-found/command-not-found.c

@ -43,11 +43,11 @@ int main(int argc, char** argv) {
int distance = termux_levenshtein_distance(command_not_found, binary_name); int distance = termux_levenshtein_distance(command_not_found, binary_name);
if (distance == 0 && strcmp(command_not_found, binary_name) == 0) { if (distance == 0 && strcmp(command_not_found, binary_name) == 0) {
if (best_distance == 0) { if (best_distance == 0) {
printf("or\n"); fprintf(stderr, "or\n");
} else { } else {
printf("The program '%s' is not installed. Install it by executing:\n", binary_name); fprintf(stderr, "The program '%s' is not installed. Install it by executing:\n", binary_name);
} }
printf(" pkg install %s\n", current_package); fprintf(stderr, " pkg install %s\n", current_package);
best_distance = 0; best_distance = 0;
} else if (best_distance == distance) { } else if (best_distance == distance) {
guesses_at_best_distance++; guesses_at_best_distance++;
@ -65,12 +65,12 @@ int main(int argc, char** argv) {
if (best_distance == 0) return 127; if (best_distance == 0) return 127;
if (best_distance == -1 || best_distance > 3) { if (best_distance == -1 || best_distance > 3) {
printf("%s: command not found\n", command_not_found); fprintf(stderr, "%s: command not found\n", command_not_found);
} else { } else {
printf("No command '%s' found, did you mean:\n", command_not_found); fprintf(stderr, "No command '%s' found, did you mean:\n", command_not_found);
if (guesses_at_best_distance == 1) { if (guesses_at_best_distance == 1) {
// Only one suggestion - show it: // Only one suggestion - show it:
printf(" Command '%s' from package '%s'\n", best_command_guess, best_package_guess); fprintf(stderr, " Command '%s' from package '%s'\n", best_command_guess, best_package_guess);
} else { } else {
// Multiple suggestions at the same distance - show them all: // Multiple suggestions at the same distance - show them all:
for (int i = 0; i < num_commands; i++) { for (int i = 0; i < num_commands; i++) {
@ -79,7 +79,7 @@ int main(int argc, char** argv) {
char const* binary_name = current_line + 1; char const* binary_name = current_line + 1;
int distance = termux_levenshtein_distance(command_not_found, binary_name); int distance = termux_levenshtein_distance(command_not_found, binary_name);
if (best_distance == distance) { if (best_distance == distance) {
printf(" Command '%s' from package '%s'\n", binary_name, current_package); fprintf(stderr, " Command '%s' from package '%s'\n", binary_name, current_package);
} }
} else { // Package } else { // Package
strncpy(current_package, current_line, sizeof(current_package)); strncpy(current_package, current_line, sizeof(current_package));

130
packages/command-not-found/commands.h

@ -122,6 +122,8 @@ char const* const commands[] = {
" calcurse-upgrade", " calcurse-upgrade",
"cboard", "cboard",
" cboard", " cboard",
"ccache",
" ccache",
"cgdb", "cgdb",
" cgdb", " cgdb",
"clang", "clang",
@ -265,7 +267,6 @@ char const* const commands[] = {
" readtags", " readtags",
"curl", "curl",
" curl", " curl",
" curl-config",
"curseofwar", "curseofwar",
" curseofwar", " curseofwar",
"cvs", "cvs",
@ -502,6 +503,35 @@ char const* const commands[] = {
" ngettext", " ngettext",
" recode-sr-latin", " recode-sr-latin",
" xgettext", " xgettext",
"ghostscript",
" dvipdf",
" eps2eps",
" font2c",
" gs",
" gsbj",
" gsdj",
" gsdj500",
" gslj",
" gslp",
" gsnd",
" lprsetup.sh",
" pdf2dsc",
" pdf2ps",
" pf2afm",
" pfbtopfa",
" pphs",
" printafm",
" ps2ascii",
" ps2epsi",
" ps2pdf",
" ps2pdf12",
" ps2pdf13",
" ps2pdf14",
" ps2pdfwr",
" ps2ps",
" ps2ps2",
" unix-lpr.sh",
" wftopfa",
"gifsicle", "gifsicle",
" gifdiff", " gifdiff",
" gifsicle", " gifsicle",
@ -532,6 +562,8 @@ char const* const commands[] = {
" htags-server", " htags-server",
"glulxe", "glulxe",
" glulxe", " glulxe",
"gmic",
" gmic",
"gnuchess", "gnuchess",
" gnuchess", " gnuchess",
"gnugo", "gnugo",
@ -592,6 +624,8 @@ char const* const commands[] = {
" gpgme-config", " gpgme-config",
"gpgv", "gpgv",
" gpgv", " gpgv",
"gpsbabel",
" gpsbabel",
"graphicsmagick", "graphicsmagick",
" gm", " gm",
"graphviz", "graphviz",
@ -660,6 +694,22 @@ char const* const commands[] = {
" hb-view", " hb-view",
"hexcurse", "hexcurse",
" hexcurse", " hexcurse",
"hfsutils",
" hattrib",
" hcd",
" hcopy",
" hdel",
" hdir",
" hformat",
" hfsutil",
" hls",
" hmkdir",
" hmount",
" hpwd",
" hrename",
" hrmdir",
" humount",
" hvol",
"ht", "ht",
" ht", " ht",
"htop", "htop",
@ -686,6 +736,8 @@ char const* const commands[] = {
" hydra", " hydra",
" hydra-wizard.sh", " hydra-wizard.sh",
" pw-inspector", " pw-inspector",
"icecast",
" icecast",
"iconv", "iconv",
" iconv", " iconv",
"icu-devtools", "icu-devtools",
@ -720,6 +772,10 @@ char const* const commands[] = {
" mogrify", " mogrify",
" montage", " montage",
" stream", " stream",
"imgflo",
" imgflo",
" imgflo-graphinfo",
" imgflo-runtime",
"inetutils", "inetutils",
" dnsdomainname", " dnsdomainname",
" ftp", " ftp",
@ -830,6 +886,8 @@ char const* const commands[] = {
"libcroco", "libcroco",
" croco-0.6-config", " croco-0.6-config",
" csslint-0.6", " csslint-0.6",
"libcurl-dev",
" curl-config",
"libgcrypt", "libgcrypt",
" dumpsexp", " dumpsexp",
" hmac256", " hmac256",
@ -944,6 +1002,8 @@ char const* const commands[] = {
"libtool", "libtool",
" libtool", " libtool",
" libtoolize", " libtoolize",
"libxapian-dev",
" xapian-config",
"libxml2-dev", "libxml2-dev",
" xml2-config", " xml2-config",
"libxml2-utils", "libxml2-utils",
@ -1045,10 +1105,8 @@ char const* const commands[] = {
" myisampack", " myisampack",
" mysql", " mysql",
" mysql_client_test", " mysql_client_test",
" mysql_client_test_embedded",
" mysql_config", " mysql_config",
" mysql_convert_table_format", " mysql_convert_table_format",
" mysql_embedded",
" mysql_find_rows", " mysql_find_rows",
" mysql_fix_extensions", " mysql_fix_extensions",
" mysql_install_db", " mysql_install_db",
@ -1084,6 +1142,16 @@ char const* const commands[] = {
" mcdiff", " mcdiff",
" mcedit", " mcedit",
" mcview", " mcview",
"megatools",
" megacopy",
" megadf",
" megadl",
" megaget",
" megals",
" megamkdir",
" megaput",
" megareg",
" megarm",
"memcached", "memcached",
" memcached", " memcached",
"micro", "micro",
@ -1118,6 +1186,40 @@ char const* const commands[] = {
" mpd", " mpd",
"mpv", "mpv",
" mpv", " mpv",
"mtools",
" amuFormat.sh",
" lz",
" mattrib",
" mbadblocks",
" mcat",
" mcd",
" mcheck",
" mclasserase",
" mcomp",
" mcopy",
" mdel",
" mdeltree",
" mdir",
" mdu",
" mformat",
" minfo",
" mkmanifest",
" mlabel",
" mmd",
" mmount",
" mmove",
" mpartition",
" mrd",
" mren",
" mshortname",
" mshowfat",
" mtools",
" mtoolstest",
" mtype",
" mxtar",
" mzip",
" tgz",
" uz",
"multitail", "multitail",
" multitail", " multitail",
"mutt", "mutt",
@ -1133,6 +1235,8 @@ char const* const commands[] = {
" ncdu", " ncdu",
"ncmpcpp", "ncmpcpp",
" ncmpcpp", " ncmpcpp",
"ncurses-dev",
" ncursesw6-config",
"ncurses-utils", "ncurses-utils",
" clear", " clear",
" infocmp", " infocmp",
@ -1545,6 +1649,11 @@ char const* const commands[] = {
" npx", " npx",
"notmuch", "notmuch",
" notmuch", " notmuch",
"nyancat",
" nyancat",
"oathtool",
" oathtool",
" pskctool",
"ocrad", "ocrad",
" ocrad", " ocrad",
"openjpeg-tools", "openjpeg-tools",
@ -1800,6 +1909,11 @@ char const* const commands[] = {
" rem", " rem",
" rem2ps", " rem2ps",
" remind", " remind",
"rgbds",
" rgbasm",
" rgbfix",
" rgbgfx",
" rgblink",
"rlwrap", "rlwrap",
" rlwrap", " rlwrap",
"rsync", "rsync",
@ -2126,15 +2240,23 @@ char const* const commands[] = {
" simplesearch", " simplesearch",
" xapian-check", " xapian-check",
" xapian-compact", " xapian-compact",
" xapian-config",
" xapian-delve", " xapian-delve",
" xapian-metadata", " xapian-metadata",
" xapian-progsrv", " xapian-progsrv",
" xapian-replicate", " xapian-replicate",
" xapian-replicate-server", " xapian-replicate-server",
" xapian-tcpsrv", " xapian-tcpsrv",
"xmlsec",
" xmlsec1",
" xmlsec1-config",
"xmlstarlet", "xmlstarlet",
" xml", " xml",
"xorriso",
" osirrox",
" xorrecord",
" xorriso",
" xorriso-tcltk",
" xorrisofs",
"xsltproc", "xsltproc",
" xsltproc", " xsltproc",
"xz-utils", "xz-utils",

Loading…
Cancel
Save