最近使用 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
保持更新;