scoop on git bash

starlitxiling Lv3

闲来无事又不想学习,折腾了一下Windows下的命令行什么的,发现scoop还是挺好用的,相较于winget,它更适合我这种比较喜欢linux命令行风格的,再加上mingwgit-bash,在Windows-Terminal下配上oh-my-zsh,实在是太舒服了。效果图如下:

下面记录一下使用过程中遇到的问题

miniconda安装

这里可以直接scoop install miniconda,但是安装完成后会让你conda init <your shell>,执行这一步会报错,是一个说在~/.zshrc^M符号有问题的,这里很自然的可以想到编码方式的不同,但是改变zshrc的编码方式并不能解决问题,后面找到https://github.com/conda/conda/issues/9922#issuecomment-1361695031,把这个写入zshrc中,然后再在这之前加入export PYTHONIOENCONFIG=utf-8,然后就可以解决这个问题了。配置参考如下图:

20250316更新

上面的方法今天试了一下依然没有解决问题,但是发现了一个新的方法,在~目录下新建conda-shell-zsh-hook.zsh,写入:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

export PYTHONIOENCODING=UTF-8
export CONDA_EXE="$(cygpath 'E:\scooptools\apps\miniconda3\current\Scripts\conda.exe')" # 这里注意更改路径
export _CE_M=''
export _CE_CONDA=''
export CONDA_PYTHON_EXE="$(cygpath 'E:\scooptools\apps\miniconda3\current\python.exe')" # 这里注意更改路径

if [ -d "/e/scooptools/apps/miniconda3/current/Scriptes" ]; then
export PATH="/e/scooptools/apps/miniconda3/current/Scripts:$PATH"
export PATH="/e/scooptools/apps/miniconda3/current:$PATH"
fi

__conda_exe() (
"$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d '\r'
)

__conda_hashr() {
if [ -n "${ZSH_VERSION:+x}" ]; then
\rehash
elif [ -n "${POSH_VERSION:+x}" ]; then
: # pass
else
\hash -r
fi
}

__conda_activate() {
if [ -n "${CONDA_PS1_BACKUP:+x}" ]; then
PS1="$CONDA_PS1_BACKUP"
\unset CONDA_PS1_BACKUP
fi
\local ask_conda
ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix "$@")" || \return
\eval "$ask_conda"
__conda_hashr
}

__conda_reactivate() {
\local ask_conda
ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix reactivate)" || \return
\eval "$ask_conda"
__conda_hashr
}

conda() {
\local cmd="${1-__missing__}"
case "$cmd" in
activate|deactivate)
__conda_activate "$@"
;;
install|update|upgrade|remove|uninstall)
__conda_exe "$@" || \return
__conda_reactivate
;;
*)
__conda_exe "$@"
;;
esac
}

if [ -z "${CONDA_SHLVL+x}" ]; then
\export CONDA_SHLVL=0

if [ -n "${_CE_CONDA:+x}" ] && [ -n "${WINDIR+x}" ]; then
PATH="$(\dirname "$CONDA_EXE")/condabin${PATH:+":${PATH}"}"
else
PATH="$(\dirname "$(\dirname "$CONDA_EXE")")/condabin${PATH:+":${PATH}"}"
fi
\export PATH

if [ -z "${PS1+x}" ]; then
PS1=
fi
fi

conda activate base

然后在.zshrc中写入:

1
2
3
4
5
6
7
8
9
10
11
12
13
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!

if [ -f '/e/scooptools/apps/miniconda3/current/Scripts/conda.exe' ]; then
source ~/conda-shell-zsh-hook.zsh
fi

# 注释掉conda init <shell>生成的东西
# if [ -f '/e/scooptools/apps/miniconda3/current/Scripts/conda.exe' ]; then
# eval "$('/e/scooptools/apps/miniconda3/current/Scripts/conda.exe' 'shell.zsh' 'hook')"
# fi
# <<< conda initialize <<<

最后在source ~/.zshrc一下就可以成功运行conda了。

LunarVim

直接scoop install lunarvim,在这之前要scoop install neovim一下,然后关于NodeJs的,建议在这之前装好nvmminiconda,都可以使用scoop安装。对于nvm,在Windows下直接nvm install 18大概率会出错,具体可以参考https://github.com/coreybutler/nvm-windows/issues/436。所以你可以nvm install latest all --insecure,这里的重点在这个insecure。对于npm,可以使用npm proxy http://127.0.0.1:7890设置代理。scoop install lunarvim之后要lvim_install,每次更新之后都要重新执行一下lvim_install

Cursor安装

openai推出的一个编辑器,优点在于可以使用AI辅助coding,还可以同步VsCode的所有设置和插件,非常不错,这个的安装要自己去官网下载安装包安装,然后安装的适合可以选择是否安装到命令行,对于git-bash下,直接cursor会出错,需要cd $(dirname $(which cursor)),然后参考https://github.com/getcursor/cursor/issues/1121修改cursor这个脚本就可以了。

zsh history

在Windows下,我的zsh会将history全部存储在/c/Users/$(Username)下,然后它还不会把history全部存储在一个.zsh_history文件中,你可以使用以下命令定期对这些文件进行整理。

1
2
cat ~/.zsh_history.* >> ~/.zsh_history
rm ~/.zsh_history.*

cargo

直接scoop install rustup会在使用的时候报一个link.exe什么的错误,你可以这样:

1
2
3
scoop install rustup-gnu
rustup toolchain install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu

具体可以参考https://stackoverflow.com/questions/73421853/how-to-install-rust-via-cli-on-windows

pip install

如果你在使用pip install过程中遇到报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

ERROR: Exception:
Traceback (most recent call last):
File "E:\scooptools\apps\miniconda3\24.7.1-0\Lib\site-packages\pip\_internal\cli\base_command.py", line 105, in _run_wrapper
status = _inner_run()
^^^^^^^^^^^^
File "E:\scooptools\apps\miniconda3\24.7.1-0\Lib\site-packages\pip\_internal\cli\base_command.py", line 96, in _inner_run
return self.run(options, args)
^^^^^^^^^^^^^^^^^^^^^^^
File "E:\scooptools\apps\miniconda3\24.7.1-0\Lib\site-packages\pip\_internal\cli\req_command.py", line 67, in wrapper
return func(self, options, args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\scooptools\apps\miniconda3\24.7.1-0\Lib\site-packages\pip\_internal\commands\install.py", line 343, in run
reqs = self.get_requirements(args, options, finder, session)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\scooptools\apps\miniconda3\24.7.1-0\Lib\site-packages\pip\_internal\cli\req_command.py", line 255, in get_requirements
for parsed_req in parse_requirements(
File "E:\scooptools\apps\miniconda3\24.7.1-0\Lib\site-packages\pip\_internal\req\req_file.py", line 151, in parse_requirements
for parsed_line in parser.parse(filename, constraint):
File "E:\scooptools\apps\miniconda3\24.7.1-0\Lib\site-packages\pip\_internal\req\req_file.py", line 332, in parse
yield from self._parse_and_recurse(filename, constraint)
File "E:\scooptools\apps\miniconda3\24.7.1-0\Lib\site-packages\pip\_internal\req\req_file.py", line 337, in _parse_and_recurse
for line in self._parse_file(filename, constraint):
File "E:\scooptools\apps\miniconda3\24.7.1-0\Lib\site-packages\pip\_internal\req\req_file.py", line 368, in _parse_file
_, content = get_file_content(filename, self._session)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\scooptools\apps\miniconda3\24.7.1-0\Lib\site-packages\pip\_internal\req\req_file.py", line 548, in get_file_content
content = auto_decode(f.read())
^^^^^^^^^^^^^^^^^^^^^
File "E:\scooptools\apps\miniconda3\24.7.1-0\Lib\site-packages\pip\_internal\utils\encoding.py", line 34, in auto_decode
return data.decode(
^^^^^^^^^^^^
UnicodeDecodeError: 'gbk' codec can't decode byte 0xb4 in position 343: illegal multibyte sequence
decoding with 'cp936' codec failed

你需要在Windows的系统变量中添加PYTHONUTF8,将其值设置为1,如图:

或许也可以使用chcp 65001临时修改编码,然后pip install,但是我依然报错。

  • Title: scoop on git bash
  • Author: starlitxiling
  • Created at : 2024-08-27 20:51:29
  • Updated at : 2025-03-16 18:23:17
  • Link: http://starlitxiling.github.io/2024/08/27/scoop-on-git-bash/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
scoop on git bash