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_DESCRIPTION="Suggest installation of packages in interactive shell sessions"
TERMUX_PKG_VERSION=1.24
TERMUX_PKG_VERSION=1.25
termux_step_make_install () {
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);
if (distance == 0 && strcmp(command_not_found, binary_name) == 0) {
if (best_distance == 0) {
printf("or\n");
fprintf(stderr, "or\n");
} 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;
} else if (best_distance == distance) {
guesses_at_best_distance++;
@ -65,12 +65,12 @@ int main(int argc, char** argv) {
if (best_distance == 0) return 127;
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 {
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) {
// 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 {
// Multiple suggestions at the same distance - show them all:
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;
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);
fprintf(stderr, " Command '%s' from package '%s'\n", binary_name, current_package);
}
} else { // 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",
"cboard",
" cboard",
"ccache",
" ccache",
"cgdb",
" cgdb",
"clang",
@ -265,7 +267,6 @@ char const* const commands[] = {
" readtags",
"curl",
" curl",
" curl-config",
"curseofwar",
" curseofwar",
"cvs",
@ -502,6 +503,35 @@ char const* const commands[] = {
" ngettext",
" recode-sr-latin",
" 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",
" gifdiff",
" gifsicle",
@ -532,6 +562,8 @@ char const* const commands[] = {
" htags-server",
"glulxe",
" glulxe",
"gmic",
" gmic",
"gnuchess",
" gnuchess",
"gnugo",
@ -592,6 +624,8 @@ char const* const commands[] = {
" gpgme-config",
"gpgv",
" gpgv",
"gpsbabel",
" gpsbabel",
"graphicsmagick",
" gm",
"graphviz",
@ -660,6 +694,22 @@ char const* const commands[] = {
" hb-view",
"hexcurse",
" hexcurse",
"hfsutils",
" hattrib",
" hcd",
" hcopy",
" hdel",
" hdir",
" hformat",
" hfsutil",
" hls",
" hmkdir",
" hmount",
" hpwd",
" hrename",
" hrmdir",
" humount",
" hvol",
"ht",
" ht",
"htop",
@ -686,6 +736,8 @@ char const* const commands[] = {
" hydra",
" hydra-wizard.sh",
" pw-inspector",
"icecast",
" icecast",
"iconv",
" iconv",
"icu-devtools",
@ -720,6 +772,10 @@ char const* const commands[] = {
" mogrify",
" montage",
" stream",
"imgflo",
" imgflo",
" imgflo-graphinfo",
" imgflo-runtime",
"inetutils",
" dnsdomainname",
" ftp",
@ -830,6 +886,8 @@ char const* const commands[] = {
"libcroco",
" croco-0.6-config",
" csslint-0.6",
"libcurl-dev",
" curl-config",
"libgcrypt",
" dumpsexp",
" hmac256",
@ -944,6 +1002,8 @@ char const* const commands[] = {
"libtool",
" libtool",
" libtoolize",
"libxapian-dev",
" xapian-config",
"libxml2-dev",
" xml2-config",
"libxml2-utils",
@ -1045,10 +1105,8 @@ char const* const commands[] = {
" myisampack",
" mysql",
" mysql_client_test",
" mysql_client_test_embedded",
" mysql_config",
" mysql_convert_table_format",
" mysql_embedded",
" mysql_find_rows",
" mysql_fix_extensions",
" mysql_install_db",
@ -1084,6 +1142,16 @@ char const* const commands[] = {
" mcdiff",
" mcedit",
" mcview",
"megatools",
" megacopy",
" megadf",
" megadl",
" megaget",
" megals",
" megamkdir",
" megaput",
" megareg",
" megarm",
"memcached",
" memcached",
"micro",
@ -1118,6 +1186,40 @@ char const* const commands[] = {
" mpd",
"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",
"mutt",
@ -1133,6 +1235,8 @@ char const* const commands[] = {
" ncdu",
"ncmpcpp",
" ncmpcpp",
"ncurses-dev",
" ncursesw6-config",
"ncurses-utils",
" clear",
" infocmp",
@ -1545,6 +1649,11 @@ char const* const commands[] = {
" npx",
"notmuch",
" notmuch",
"nyancat",
" nyancat",
"oathtool",
" oathtool",
" pskctool",
"ocrad",
" ocrad",
"openjpeg-tools",
@ -1800,6 +1909,11 @@ char const* const commands[] = {
" rem",
" rem2ps",
" remind",
"rgbds",
" rgbasm",
" rgbfix",
" rgbgfx",
" rgblink",
"rlwrap",
" rlwrap",
"rsync",
@ -2126,15 +2240,23 @@ char const* const commands[] = {
" simplesearch",
" xapian-check",
" xapian-compact",
" xapian-config",
" xapian-delve",
" xapian-metadata",
" xapian-progsrv",
" xapian-replicate",
" xapian-replicate-server",
" xapian-tcpsrv",
"xmlsec",
" xmlsec1",
" xmlsec1-config",
"xmlstarlet",
" xml",
"xorriso",
" osirrox",
" xorrecord",
" xorriso",
" xorriso-tcltk",
" xorrisofs",
"xsltproc",
" xsltproc",
"xz-utils",

Loading…
Cancel
Save