Repository: cantino/mcfly (language: rust)

Issue:
Fails to start on WSL
hi,

I just installed in WSL in windows 10, with the install script, and I get something very similar, anyone knows what's up?

```
error: Found argument 'is' which wasn't expected, or isn't valid in this context

USAGE:
    mcfly [FLAGS] [OPTIONS] <SUBCOMMAND>

For more information try --help
```

thanks

_Originally posted by @jmlucjav in https://github.com/cantino/mcfly/issues/128#issuecomment-962210659_


Discussion / hints:
When do you get this message?
when I open a wsl terminal 
Bash shell?
yep
Hmm, I have no idea. There is no reference to `is` in mcfly.bash. What happens if you type `mcfly --version` or `eval "$(mcfly init bash)"` after the shell loads?
I think I already tried and got the same output. But I'll confirm when I get to the pc where I installed mcfly, not there currently.

thanks!
this is what I get when opening a bash terminal, and trying what you suggested:

```
error: Found argument 'is' which wasn't expected, or isn't valid in this context

USAGE:
    mcfly [FLAGS] [OPTIONS] <SUBCOMMAND>

For more information try --help
-Users/xx❯ mcfly --version
McFly 0.5.10
error: Found argument 'is' which wasn't expected, or isn't valid in this context

USAGE:
    mcfly [FLAGS] [OPTIONS] <SUBCOMMAND>

For more information try --help
-Users/xx ➜ eval "$(mcfly init bash)"
-bash: return: can only `return' from a function or sourced script
error: Found argument 'is' which wasn't expected, or isn't valid in this context

USAGE:
    mcfly [FLAGS] [OPTIONS] <SUBCOMMAND>

For more information try --help
error: Found argument 'is' which wasn't expected, or isn't valid in this context

USAGE:
    mcfly [FLAGS] [OPTIONS] <SUBCOMMAND>

For more information try --help

```
Ok, I'm pretty baffled. It feels like maybe `$?` in WSL bash isn't an exit code?

You could try pasting this into a shell:

```bash
function mcfly_prompt_command {
  local exit_code=$? # Record exit status of previous command.

  echo "Exit code: '${exit_code}'"

  # Populate McFly's temporary, per-session history file from recent commands in the shell's primary HISTFILE.
  if [[ ! -f "${MCFLY_HISTORY}" ]]; then
    MCFLY_HISTORY=$(mktemp -t mcfly.XXXXXXXX)
    export MCFLY_HISTORY
    command tail -n100 "${HISTFILE}" >| "${MCFLY_HISTORY}"
  fi

  history -a "${MCFLY_HISTORY}" # Append history to $MCFLY_HISTORY.
  # Run mcfly with the saved code. It will:
  # * append commands to $HISTFILE, (~/.bash_history by default)
  #   for backwards compatibility and to load in new terminal sessions;
  # * find the text of the last command in $MCFLY_HISTORY and save it to the database.
  $MCFLY_PATH add --exit ${exit_code} --append-to-histfile
  # Clear the in-memory history and reload it from $MCFLY_HISTORY
  # (to remove instances of '#mcfly: ' from the local session history).
  history -cr "${MCFLY_HISTORY}"
  return ${exit_code} # Restore the original exit code by returning it.
}

PROMPT_COMMAND="mcfly_prompt_command"
```
Arch on WSL2 works fine here.

- Download from latest realease
- Extract and `sudo mv mcfly /usr/local/bin/`
- `Ctrl-R` works
@cantino 
getting the same issue with that function. Does this shed any light?

```
~$  echo "look [$MCFLY_PATH]"
look [mcfly is /usr/local/bin/mcfly]
error: Found argument 'is' which wasn't expected, or isn't valid in this context

USAGE:
    mcfly [FLAGS] [OPTIONS] <SUBCOMMAND>

For more information try --help
~$
```
Yes! This is definitely the problem, `which mcfly` must return `mcfly is /usr/local/bin/mcfly` instead of just `/usr/local/bin/mcfly` in WSL. Could you tell me the output of the following commands?

- `which mcfly`
- `env which mcfly`
- `builtin which mcfly`
- `command which mcfly`
```
~ ❯ which mcfly
mcfly is /usr/local/bin/mcfly
error: Found argument 'is' which wasn't expected, or isn't valid in this
context

USAGE:
    mcfly [FLAGS] [OPTIONS] <SUBCOMMAND>

For more information try --help
~ ➜ env which mcfly
/usr/local/bin/mcfly
error: Found argument 'is' which wasn't expected, or isn't valid in this
context

USAGE:
    mcfly [FLAGS] [OPTIONS] <SUBCOMMAND>

For more information try --help
~ ➜ builtin which mcfly
-bash: builtin: which: not a shell builtin
error: Found argument 'is' which wasn't expected, or isn't valid in this
context

USAGE:
    mcfly [FLAGS] [OPTIONS] <SUBCOMMAND>

For more information try --help
~ ❯ command which mcfly
/usr/local/bin/mcfly
error: Found argument 'is' which wasn't expected, or isn't valid in this
context

USAGE:
    mcfly [FLAGS] [OPTIONS] <SUBCOMMAND>

For more information try --help
~ ➜
```


On Mon, Nov 15, 2021 at 7:31 PM Andrew Cantino ***@***.***>
wrote:

> Yes! This is definitely the problem, which mcfly must return mcfly is
> /usr/local/bin/mcfly instead of just /usr/local/bin/mcfly in WSL. Could
> you tell me the output of the following commands?
>
>    - which mcfly
>    - env which mcfly
>    - builtin which mcfly
>    - command which mcfly
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/cantino/mcfly/issues/206#issuecomment-969198064>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAN2V5LWNPW23X4USCSENGLUMFGXRANCNFSM5HPX6VLQ>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
>


Fix patch:
diff --git a/mcfly.bash b/mcfly.bash
index b6795b2e..2633334e 100644
--- a/mcfly.bash
+++ b/mcfly.bash
@@ -21,7 +21,7 @@ MCFLY_SESSION_ID="$(command dd if=/dev/urandom bs=256 count=1 2> /dev/null | LC_
 export MCFLY_SESSION_ID
 
 # Find the binary
-MCFLY_PATH=${MCFLY_PATH:-$(which mcfly)}
+MCFLY_PATH=${MCFLY_PATH:-$(command which mcfly)}
 if [ -z "$MCFLY_PATH" ]; then
   echo "Cannot find the mcfly binary, please make sure that mcfly is in your path before sourcing mcfly.bash."
   return 1
diff --git a/mcfly.fish b/mcfly.fish
index 8b69c73c..4a0c5224 100644
--- a/mcfly.fish
+++ b/mcfly.fish
@@ -20,7 +20,7 @@ end
 set -gx MCFLY_SESSION_ID (dd if=/dev/urandom bs=256 count=1 2>/dev/null | env LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c 24)
 
 # Find the binary
-set -q MCFLY_PATH; or set -l MCFLY_PATH (which mcfly)
+set -q MCFLY_PATH; or set -l MCFLY_PATH (command which mcfly)
 if test -z "$MCFLY_PATH"; or test "$MCFLY_PATH" = "mcfly not found"
   echo "Cannot find the mcfly binary, please make sure that mcfly is in your path before sourcing mcfly.fish"
   exit 1
diff --git a/mcfly.zsh b/mcfly.zsh
index 1d55e38e..1266f453 100644
--- a/mcfly.zsh
+++ b/mcfly.zsh
@@ -20,7 +20,7 @@ fi
 export MCFLY_SESSION_ID=$(command dd if=/dev/urandom bs=256 count=1 2> /dev/null | LC_ALL=C command tr -dc 'a-zA-Z0-9' | command head -c 24)
 
 # Find the binary
-MCFLY_PATH=${MCFLY_PATH:-$(which mcfly)}
+MCFLY_PATH=${MCFLY_PATH:-$(command which mcfly)}
 if [[ -z "$MCFLY_PATH" || "$MCFLY_PATH" == "mcfly not found" ]]; then
   echo "Cannot find the mcfly binary, please make sure that mcfly is in your path before sourcing mcfly.zsh."
   return 1


Test patch: