如何阻止Cygwin终端在非主文件夹中打开时忘记环境?

如何阻止Cygwin终端在非主文件夹中打开时忘记环境?,cygwin,ocaml,Cygwin,Ocaml,我买的是预先包装好的Cygwin。因为我希望能够从当前目录中的命令行打开mintty,所以我将它添加到PATH中,然后运行mintty就可以了。虽然这会导致它在当前目录中打开,但问题是,当我运行任何Ocaml可执行文件(如opam)时,都会出现错误 Marko@Lain /cygdrive/e/Webdev/Ocaml/todolist $ opam bash: opam: command not found 当我使用mintty运行它时,就像快捷方式一样,这实际上是有效的 Marko@Lai

我买的是预先包装好的Cygwin。因为我希望能够从当前目录中的命令行打开mintty,所以我将它添加到PATH中,然后运行mintty就可以了。虽然这会导致它在当前目录中打开,但问题是,当我运行任何Ocaml可执行文件(如opam)时,都会出现错误

Marko@Lain /cygdrive/e/Webdev/Ocaml/todolist
$ opam
bash: opam: command not found
当我使用mintty运行它时,就像快捷方式一样,这实际上是有效的

Marko@Lain ~
$ cd "E:\Webdev\Ocaml\todolist"

Marko@Lain /cygdrive/e/Webdev/Ocaml/todolist
$ opam
usage: opam [--version]
            [--help]
            <command> [<args>]

The most commonly used opam commands are:
    init         Initialize opam state, or set init options.
    list         Display the list of available packages.
    show         Display information about specific packages.
    install      Install a list of packages.
    remove       Remove a list of packages.
    update       Update the list of available packages.
    upgrade      Upgrade the installed package to latest version.
    config       Display configuration options for packages.
    repository   Manage opam repositories.
    switch       Manage multiple installation prefixes.
    pin          Pin a given package to a specific version or source.
    admin        Tools for repository administrators

See 'opam help <command>' for more information on a specific command.
我必须做些什么才能正常地获得这种行为

另外,由于mintty在独立窗口中运行终端,所以最好运行bash,但bash-对我来说不起作用。在我完成这项工作后,我想将bash添加到我的VS代码shell列表中,为此我需要了解如何在保留主环境内存的同时从命令行在任意目录中运行它。

此命令mintty-以登录方式启动shell。 如果运行not login shell,大多数配置脚本都不会被读取,环境也会从父进程中获取,但当然,您的链接会失败,因为Windows无法提供正确的链接。 如果您希望能够从资源管理器打开登录shell,最好的方法是安装chere软件包

您可以在资源管理器的右键单击菜单上作为附加项安装首选或默认shell。它将在所选目录中打开一个登录shell

$ chere -h
/usr/bin/chere version 1.4

Usage:
/usr/bin/chere -<iuxlrhv> [-lracnmpf12] [-t <term>] [-s <shell>]
        [-d <display> ] [-o <options>] [-e <menutext>]

Adds the stated terminal/shell combination to the folder context menu
This allows you to right click a folder in Windows Explorer and open
a Cygwin shell in that folder.

Options:
  i - Install
  u - Uninstall
  x - Freshen eXisting entries
  l - List currently installed chere items
  r - Read all chere registry entries to stdout
  a - All users
  c - Current user only
  n - Be Nice and provide Control Panel uninstall option (Default)
  m - Minimal, no Control Panel uninstall
  p - Print regtool commands to stdout rather than running them
  f - Force write (overwrite existing, ignore missing files)
  1 - Start using registry one-liners. This doesn't work with ash,
      tcsh or network shares.
  2 - Start via bash script. Relies on windows to change directory,
      and login scripts avoiding doing a cd /home/Marco 
  h - Help
  v - Version

  t <term> - Use terminal term. Supported terminals are:
        cmd rxvt mintty xterm urxvt

  s <shell> - Use the named shell. Supported shells are:
        ash bash cmd dash fish mksh pdksh posh tcsh zsh passwd

  d <display> - DISPLAY to use (xterm, urxvt). Defaults to :0.
      Set to env to use the runtime environment variable.

  o <options> - Add <options> to the terminal startup command.
      If more than one option is specified, they should all be
      contained within a single set of quotes.

  e <menutext> - Use <menutext> as the context menu text.

See the man page for more detail.