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

Mac Fish #56

Open
hankliu62 opened this issue Nov 3, 2021 · 0 comments
Open

Mac Fish #56

hankliu62 opened this issue Nov 3, 2021 · 0 comments
Assignees
Labels
blog 博客文章 toolkit 开发、系统工具箱相关

Comments

@hankliu62
Copy link
Owner

hankliu62 commented Nov 3, 2021

Mac Fish使用

安装 fish

brew install fish

修改/etc/shells文件

sudo vi /etc/shells

添加/usr/local/bin/fish

【我的文件,包含zsh、fish】

/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
/usr/local/bin/fish

修改默认的shell

sudo -u [用户名] chsh -s /usr/local/bin/fish

Fish 配置主题

fish_config

Fish 中使用 nvm

问题描述: nvm 主要用于 Node 版本控制,macOS 系统下,在 zsh 或 bash 终端,使用 Homebrew 下载,一般都能正常使用,但是切换到 fish 终端就会无法找到此命令。

**主要原因: **fish 环境下无法识别 nvm shell 命令,比如 Gihub issues:NVM in fish:

May I request that this issue be reformatted in the form of a bug?

NVM does not install if you use the fish shell.
NVM does not work in the fish shell shell shell if previously installed in the bash shell. In fact, nvm > isn’t even in the path.

解决办法

在刚刚 Github Issues 下就有解决方案:

I also wrote a general wrapper to bring almost any bash utility to fish shell: https://github.com/edc/bass. It works flawlessly with nvm using syntax like bass source ~/.nvm/nvm.sh ; nvm --version. For convenience, one can create an alias Fish function:

function nvm
      bass source ~/.nvm/nvm.sh ';' nvm $argv
end

# and then just use nvm --version, nvm ls, etc.

动手实践

第一步 下载 oh-my-fish

Oh My Fish provides core infrastructure to allow you to install packages which extend or modify the look of your shell. It’s fast, extensible and easy to use.

默认设置安装:

curl -L https://get.oh-my.fish | fish

检测:

omf -v
Oh My Fish version 7

或者可以自定义安装:

curl -L https://get.oh-my.fish > install
fish install --path=~/.local/share/omf --config=~/.config/omf

关于使用 curl,这里可能会报错:

Failed to connect to raw.githubusercontent.com port 443: Connection refused

说得也很明白,就是请求被拒绝访问,那我们怎么办?问度娘!咔咔咔,一段萌操作…之后:

访问ipaddress.com,获取 raw.githubusercontent.com 域名真实 IP,然后在本地 hosts 文件添加即可:

sudo vim /etc/hosts

添加如下内容,并保存退出:

199.232.28.133 raw.githubusercontent.com

第二步 下载 Bass

官网介绍:Bass makes it easy to use utilities written for Bash in fish shell.

下载好 oh-my-fish,直接下载 bass:

omf install bass

当然,也可以使用官网提到的 fisher、Fundle 等包管理器。

第三步 配置 nvm

前提是你已经下载好了 nvm,比如我使用 Homebrew 安装:

brew install nvm

然后,安装完成会有一堆提示,如一下关键信息:

You should create NVM's working directory if it doesn't exist:

  mkdir ~/.nvm

Add the following to ~/.config/fish/config.fish or your desired shell
configuration file:

  export NVM_DIR="$HOME/.nvm"
  [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

You can set $NVM_DIR to any location, but leaving it unchanged from
/usr/local/opt/nvm will destroy any nvm-installed Node installations
upon upgrade/reinstall.

根据提示进入如下目录,并创建 config.fish 文件:

cd ~/.config/fish/
touch config.fish

config.fish添加如下配置:

function nvm
    bass source /opt/homebrew/opt/nvm/nvm.sh ';' nvm $argv
end

激活配置:

source ~/.config/fish/config.fish

最后检测:

nvm --version
0.35.3

如果你是全局安装 nvm,比如使用 curl 或者 wget,config.fish应该是:

function nvm
      bass source ~/.nvm/nvm.sh ';' nvm $argv
  end

主要是 nvm.sh 文件的路径问题是否存在!

大功告成,打完收工!

Fish 中使用 brew

**主要原因: **fish 环境下无法识别 brew shell 命令。

根据提示进入如下目录,并创建 config.fish 文件:

cd ~/.config/fish/
touch config.fish

config.fish添加如下配置:

function brew
    /opt/homebrew/bin/brew $argv
end

激活配置:

source ~/.config/fish/config.fish

iterm2新开tab为fish shell

image

@hankliu62 hankliu62 self-assigned this Nov 3, 2021
@hankliu62 hankliu62 added the blog 博客文章 label Nov 3, 2021
@hankliu62 hankliu62 added the toolkit 开发、系统工具箱相关 label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blog 博客文章 toolkit 开发、系统工具箱相关
Projects
None yet
Development

No branches or pull requests

1 participant