最近使用 fish进行工作,发现环境变量忘记如何设置;
fish 环境变量保存在两个地方;
- ~ 目录下,.config/fish 目录下;
- /etc/fish/ 目录下
如果配置所有用户都能用的环境变量,可以在 /etc/fish/config.fish 文件中进行配置;
如果单独使用,可以在~/.config/fish/ 目录下配置;
首先打开~/.config/fish/config.fish这个文件(不论它是否存在)
配置环境变量的命令为:
set -x PATH /opt/demo/bin /home/guest/bin $PATH
其中,/opt/demo/bin 和 /home/guest/bin 两个路径为添加的两个路径;用空格隔开;重新加载shell 即可以使用;
对于服务器环境,因为无浏览器,只要复制对应的配置文件即可:
mkdir -p ~/.config/fish/functions
scp ./fish_prompt.fish xxx@10.134.150.162:/home/xxx/.config/fish/functions/fish_prompt.fish
推荐阅读:
参考链接:
https://www.xuebuyuan.com/2046505.html
补充(2021年06月18日18:45:02)我常用的fish_prompt.fish文件,此种适合在服务器情况下使用:
上图是配置的效果图;
function fish_prompt set -l __last_command_exit_status $status if not set -q -g __fish_robbyrussell_functions_defined set -g __fish_robbyrussell_functions_defined function _git_branch_name set -l branch (git symbolic-ref --quiet HEAD ^/dev/null) if set -q branch[1] echo (string replace -r '^refs/heads/' '' $branch) else echo (git rev-parse --short HEAD ^/dev/null) end end function _is_git_dirty echo (git status -s --ignore-submodules=dirty ^/dev/null) end function _is_git_repo type -q git or return 1 git status -s >/dev/null ^/dev/null end function _hg_branch_name echo (hg branch ^/dev/null) end function _is_hg_dirty echo (hg status -mard ^/dev/null) end function _is_hg_repo type -q hg or return 1 hg summary >/dev/null ^/dev/null end function _repo_branch_name eval "_$argv[1]_branch_name" end function _is_repo_dirty eval "_is_$argv[1]_dirty" end function _repo_type if _is_hg_repo echo 'hg' else if _is_git_repo echo 'git' end end end set -l cyan (set_color -o cyan) set -l yellow (set_color -o yellow) set -l red (set_color -o red) set -l green (set_color -o green) set -l blue (set_color -o blue) set -l normal (set_color normal) set -l arrow_color "$green" if test $__last_command_exit_status != 0 set arrow_color "$red" end set -l arrow "$arrow_color➜ " if test "$USER" = 'root' set arrow "$arrow_color# " end set -l cwd $cyan(basename (prompt_pwd)) set -l repo_type (_repo_type) if [ $repo_type ] set -l repo_branch $red(_repo_branch_name $repo_type) set repo_info "$blue $repo_type:($repo_branch$blue)" if [ (_is_repo_dirty $repo_type) ] set -l dirty "$yellow ✗" set repo_info "$repo_info$dirty" end end echo -n -s $arrow ' '$cwd $repo_info $normal ' ' end
保持更新;