set -g HISTSIZE 1000 set -g HISTFILESIZE 2000 # 环境变量设置 # Java set -gx JAVA_HOME /usr/jvm/openjdk25/ set -gx PATH $PATH $JAVA_HOME/bin set -gx CLASSPATH .:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH set -gx JRE_HOME /$JAVA_HOME/jre # Bun set -gx BUN_INSTALL "$HOME/.bun" set -gx PATH $BUN_INSTALL/bin $PATH # 本地 bin set -gx PATH $HOME/.local/bin $PATH # nvm set --global nvm_data ~/.nvm function __auto_nvm_use --on-variable PWD # 防止在命令替换中触发 status --is-command-substitution; and return # 查找当前目录或父目录中的 .nvmrc 文件 set -l nvmrc_path (_nvm_find_nvmrc) if test -n "$nvmrc_path" # 读取文件中指定的版本 set -l required_version (cat $nvmrc_path | string trim) # 获取当前使用的版本 set -l current_version (nvm current 2>/dev/null; or echo "none") # 只有当版本不同或当前未使用 nvm 时才切换 if test "$required_version" != "$current_version" nvm use --silent end end end # 辅助函数:向上递归查找 .nvmrc 文件 function _nvm_find_nvmrc set -l current_dir (pwd) while test "$current_dir" != "/" if test -f "$current_dir/.nvmrc" echo "$current_dir/.nvmrc" return 0 end set current_dir (dirname $current_dir) end return 1 end # 提醒别名 (alert 的 Fish 版本) function alert set -l exit_code $status set -l last_command (history | head -n1 | sed -E 's/^\s*[0-9]+\s+//') if test $exit_code -eq 0 notify-send --urgency=low -i terminal "$last_command" "Command completed successfully" else notify-send --urgency=low -i error "$last_command" "Command failed with exit code $exit_code" end end # 提示符设置 (Fish 的提示符通过 fish_prompt 函数配置) function fish_prompt set -l last_status $status # 获取 chroot 信息 set -l debian_chroot if test -z "$debian_chroot" -a -r /etc/debian_chroot set debian_chroot (cat /etc/debian_chroot) end # 设置颜色 set -l normal (set_color normal) set -l green (set_color green) set -l blue (set_color blue) # 构建提示符 if set -q debian_chroot[1] echo -n "($debian_chroot)" end echo -n $green(whoami)@(hostname -s)$normal:$blue(prompt_pwd)$normal echo -n '$ ' end # 终端标题设置 function fish_title # 获取当前目录名 set -q debian_chroot[1]; and set -l chroot "($debian_chroot)" echo "$chroot"(whoami)@(hostname -s): (prompt_pwd) end # 自动补全增强 (Fish 默认已经很强大了) # 如果开启了 globstar 类似的功能,可以使用 set -g fish_glob_star 1 # 启用 ** 匹配 #fish theme function prompt_full_pwd --description 'Print the current working directory, NOT shortened to fit the prompt' if test "$PWD" != "$HOME" printf "%s" (echo $PWD|sed -e 's|/private||' -e "s|^$HOME|~|") else echo '~' end end function fish_prompt # Cache exit status set -l last_status $status # Just calculate these once, to save a few cycles when displaying the prompt if not set -q __fish_prompt_hostname set -g __fish_prompt_hostname (hostname|cut -d . -f 1) end if not set -q __fish_prompt_char switch (id -u) case 0 set -g __fish_prompt_char '#' case '*' set -g __fish_prompt_char '$' end end # Setup colors set -l bold (set_color -o) set -l normal (set_color normal) set -l black (set_color -o black) set -l blue (set_color -o blue) set -l brown (set_color -o brown) set -l cyan (set_color -o cyan) set -l green (set_color -o green) set -l magenta (set_color -o magenta) set -l purple (set_color -o purple) set -l red (set_color -o red) set -l white (set_color -o white) set -l yellow (set_color -o yellow) if tput setaf 1 &> /dev/null set bold (tput bold) set reset (tput sgr0) # Solarized colors, taken from http://git.io/solarized-colors. set black (tput setaf 0) set blue (tput setaf 33) set brown (tput setaf 166) set cyan (tput setaf 37) set green (tput setaf 64) set magenta (tput setaf 61) set purple (tput setaf 125) set red (tput setaf 124) set white (tput setaf 15) set yellow (tput setaf 136) end # Configure __fish_git_prompt set -g __fish_git_prompt_show_informative_status true set -g __fish_git_prompt_showcolorhints true set -l user_style $brown if [ (id -u) -eq 0 ] set user_style $red end set -l host_style $yellow if set -q SSH_TTY set host_style $bold$red end # Color prompt char red for non-zero exit status set -l pcolor $normal if [ $last_status -ne 0 ] set pcolor $red end set -l _date (printf '%s' (date "+%a %b %d")) set -l _time (printf '%s' (date +%H:%M:%S)) # Top echo -n "⋊>" $user_style$USER$normal at $host_style$__fish_prompt_hostname$normal in $bold$blue(prompt_full_pwd)$normal __fish_git_prompt echo -n "" since $green$_date $cyan$_time$normal echo # Bottom echo -n $pcolor$__fish_prompt_char $normal end function set_color_custom set -U fish_color_normal normal set -U fish_color_command 005fd7 purple set -U fish_color_param 00afff cyan set -U fish_color_redirection 005fd7 set -U fish_color_comment 600 set -U fish_color_error red --bold set -U fish_color_escape cyan set -U fish_color_operator cyan set -U fish_color_end green set -U fish_color_quote brown set -U fish_color_autosuggestion 555 yellow set -U fish_color_user green set -U fish_color_valid_path --underline set -U fish_color_cwd green set -U fish_color_cwd_root red set -U fish_color_match cyan set -U fish_color_search_match --background=purple set -U fish_color_selection --background=purple set -U fish_pager_color_prefix cyan set -U fish_pager_color_completion normal set -U fish_pager_color_description 555 yellow set -U fish_pager_color_progress cyan set -U fish_color_history_current cyan set -U fish_color_host normal end