Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu' "command not found" breaks when "mise activate" is added to .bashrc #1557

Closed
Chlorophytus opened this issue Jan 30, 2024 · 3 comments · Fixed by #1558
Closed

Ubuntu' "command not found" breaks when "mise activate" is added to .bashrc #1557

Chlorophytus opened this issue Jan 30, 2024 · 3 comments · Fixed by #1558
Labels
bug Something isn't working

Comments

@Chlorophytus
Copy link

Describe the bug
When mise is activated in $HOME/.bashrc, user does not get a recommendation for a Ubuntu command that is not installed.

To Reproduce
Activate mise on bash using $HOME/.bashrc using Ubuntu 23.10.

Expected behavior
When mise is activated in $HOME/.bashrc, user should get a command recommendation by command-not-found package for packages that aren't present.

mise doctor output

mise version:
  2024.1.30 linux-x64 (3a195bc 2024-01-27)

build:
  Target: x86_64-unknown-linux-gnu
  Features: DEFAULT, NATIVE_TLS, OPENSSL
  Built: Sat, 27 Jan 2024 01:04:29 +0000
  Rust Version: rustc 1.75.0 (82e1608df 2023-12-21)
  Profile: release

shell:
  /bin/bash
  GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
  Copyright (C) 2022 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

  This is free software; you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.

mise data directory:
  /home/accelshark/.local/share/mise

mise environment variables:
  MISE_SHELL=bash

settings:
  {
    "activate_aggressive": false,
    "all_compile": false,
    "always_keep_download": false,
    "always_keep_install": false,
    "asdf_compat": false,
    "cargo_binstall": true,
    "color": true,
    "disable_default_shorthands": false,
    "disable_tools": [],
    "experimental": false,
    "jobs": 4,
    "legacy_version_file": true,
    "legacy_version_file_disable_tools": [],
    "node_compile": false,
    "not_found_auto_install": true,
    "paranoid": false,
    "plugin_autoupdate_last_check_duration": "7d",
    "python_compile": false,
    "python_default_packages_file": "/home/accelshark/.default-python-packages",
    "python_patch_url": null,
    "python_precompiled_os": null,
    "python_patches_directory": null,
    "python_precompiled_arch": null,
    "python_pyenv_repo": "https://github.com/pyenv/pyenv.git",
    "python_venv_auto_create": false,
    "raw": false,
    "shorthands_file": null,
    "status": {
      "missing_tools": true,
      "show_env": false,
      "show_tools": false
    },
    "task_output": null,
    "trusted_config_paths": [],
    "quiet": false,
    "verbose": false,
    "yes": false,
    "ci": false,
    "cd": null,
    "debug": false,
    "env_file": null,
    "trace": false,
    "log_level": "info"
  }

config files:

plugins:
  bun      (core)
  deno     (core)
  elixir   https://github.com/mise-plugins/mise-elixir.git#7b06439
  erlang   https://github.com/asdf-vm/asdf-erlang.git#ef8f04b
  go       (core)
  java     (core)
  mill     https://github.com/asdf-community/asdf-mill.git#0536aee
  node     (core)
  python   (core)
  ruby     (core)

toolset:


1 problem found:
shims are missing, run mise reshim to create them
Missing shims: mix

Additional context

When running "smartctl" with it not installed:

Actual:

$ smartctl
bash: command not found: smartctl

Expected:

$ smartctl
Command 'smartctl' not found, but can be installed with:
sudo apt install smartmontools
@Chlorophytus Chlorophytus added the bug Something isn't working label Jan 30, 2024
@Chlorophytus
Copy link
Author

I might've found the problem, but I don't know how to fix it well.

                [ -n "$(declare -f command_not_found_handler)" ] && eval "${{$(declare -f command_not_found_handler)/command_not_found_handler/_command_not_found_handler}}"

The solution is probably something along the lines of this:

                [ -n "$(declare -f command_not_found_handle)" ] && eval "${{$(declare -f command_not_found_handle)/command_not_found_handle/_command_not_found_handle}}"

Bash considers the command-not-found handle to be command_not_found_handle instead of Zsh's command_not_found_handler.

I'll test this in a bit...

@jdx
Copy link
Owner

jdx commented Jan 30, 2024

huh yeah looks like you're right. That's incredibly confusing. I tested this but that (I think) was by manually creating command_not_found_handler in bash which made for a bad test case.

jdx added a commit that referenced this issue Jan 30, 2024
Fixes #1557

Also refactored all the shell activate scripts
jdx added a commit that referenced this issue Jan 30, 2024
Fixes #1557

Also refactored all the shell activate scripts
jdx added a commit that referenced this issue Jan 30, 2024
Fixes #1557

Also refactored all the shell activate scripts
@jdx jdx closed this as completed in #1558 Jan 30, 2024
jdx added a commit that referenced this issue Jan 30, 2024
* fix bash not_found handler

Fixes #1557

Also refactored all the shell activate scripts

* Commit from GitHub Actions (test)

---------

Co-authored-by: mise[bot] <123107610+mise-en-dev@users.noreply.github.com>
@Chlorophytus
Copy link
Author

Chlorophytus commented Jan 30, 2024

@jdx Seems there's a different Bash-related quirk now, it's printing this line when I launch the terminal. I think I figured it out though.

bash: ${$(declare -f command_not_found_handle)/command_not_found_handle/_command_not_found_handle}: bad substitution

I've done some modification on a copy of the activate script and I think this modification to the hook might fix it. Seems like Bash doesn't seem to do command substitution inside string substitution.

diff --git a/src/shell/bash.rs b/src/shell/bash.rs
index 31b9d81d..978c3ca2 100644
--- a/src/shell/bash.rs
+++ b/src/shell/bash.rs
@@ -48,7 +48,8 @@ impl Shell for Bash {
             out.push_str(&formatdoc! {r#"
             if [ -z "${{_mise_cmd_not_found:-}}" ]; then
                 _mise_cmd_not_found=1
-                [ -n "$(declare -f command_not_found_handle)" ] && eval "${{$(declare -f command_not_found_handle)/command_not_found_handle/_command_not_found_handle}}"
+                _mise_cmd_not_found_handle=$(declare -f command_not_found_handle)
+                [ -n "$_mise_cmd_not_found_handle" ] && eval "${{_mise_cmd_not_found_handle/command_not_found_handle/_command_not_found_handle}}"
 
                 command_not_found_handle() {{
                     if {exe} hook-not-found -s bash -- "$1"; then

The output of mise activate bash should be single-brackets on that _mise_cmd_not_found_handle substitution, but I'm not sure if the formatter in the Rust code converts double-brackets into single-brackets, so I left it as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants