| 1 | set -g HISTSIZE 1000 |
| 2 | set -g HISTFILESIZE 2000 |
| 3 | # 环境变量设置 |
| 4 | # Java |
| 5 | set -gx JAVA_HOME /usr/jvm/openjdk25/ |
| 6 | set -gx PATH $PATH $JAVA_HOME/bin |
| 7 | set -gx CLASSPATH .:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH |
| 8 | set -gx JRE_HOME /$JAVA_HOME/jre |
| 9 | |
| 10 | # Bun |
| 11 | set -gx BUN_INSTALL "$HOME/.bun" |
| 12 | set -gx PATH $BUN_INSTALL/bin $PATH |
| 13 | |
| 14 | # 本地 bin |
| 15 | set -gx PATH $HOME/.local/bin $PATH |
| 16 | |
| 17 | # nvm |
| 18 | set --global nvm_data ~/.nvm |
| 19 | function __auto_nvm_use --on-variable PWD |
| 20 | # 防止在命令替换中触发 |
| 21 | status --is-command-substitution; and return |
| 22 | |
| 23 | # 查找当前目录或父目录中的 .nvmrc 文件 |
| 24 | set -l nvmrc_path (_nvm_find_nvmrc) |
| 25 | |
| 26 | if test -n "$nvmrc_path" |
| 27 | # 读取文件中指定的版本 |
| 28 | set -l required_version (cat $nvmrc_path | string trim) |
| 29 | # 获取当前使用的版本 |
| 30 | set -l current_version (nvm current 2>/dev/null; or echo "none") |
| 31 | |
| 32 | # 只有当版本不同或当前未使用 nvm 时才切换 |
| 33 | if test "$required_version" != "$current_version" |
| 34 | nvm use --silent |
| 35 | end |
| 36 | end |
| 37 | end |
| 38 | |
| 39 | # 辅助函数:向上递归查找 .nvmrc 文件 |
| 40 | function _nvm_find_nvmrc |
| 41 | set -l current_dir (pwd) |
| 42 | while test "$current_dir" != "/" |
| 43 | if test -f "$current_dir/.nvmrc" |
| 44 | echo "$current_dir/.nvmrc" |
| 45 | return 0 |
| 46 | end |
| 47 | set current_dir (dirname $current_dir) |
| 48 | end |
| 49 | return 1 |
| 50 | end |
| 51 | |
| 52 | # 提醒别名 (alert 的 Fish 版本) |
| 53 | function alert |
| 54 | set -l exit_code $status |
| 55 | set -l last_command (history | head -n1 | sed -E 's/^\s*[0-9]+\s+//') |
| 56 | if test $exit_code -eq 0 |
| 57 | notify-send --urgency=low -i terminal "$last_command" "Command completed successfully" |
| 58 | else |
| 59 | notify-send --urgency=low -i error "$last_command" "Command failed with exit code $exit_code" |
| 60 | end |
| 61 | end |
| 62 | |
| 63 | # 提示符设置 (Fish 的提示符通过 fish_prompt 函数配置) |
| 64 | function fish_prompt |
| 65 | set -l last_status $status |
| 66 | |
| 67 | # 获取 chroot 信息 |
| 68 | set -l debian_chroot |
| 69 | if test -z "$debian_chroot" -a -r /etc/debian_chroot |
| 70 | set debian_chroot (cat /etc/debian_chroot) |
| 71 | end |
| 72 | |
| 73 | # 设置颜色 |
| 74 | set -l normal (set_color normal) |
| 75 | set -l green (set_color green) |
| 76 | set -l blue (set_color blue) |
| 77 | |
| 78 | # 构建提示符 |
| 79 | if set -q debian_chroot[1] |
| 80 | echo -n "($debian_chroot)" |
| 81 | end |
| 82 | |
| 83 | echo -n $green(whoami)@(hostname -s)$normal:$blue(prompt_pwd)$normal |
| 84 | echo -n '$ ' |
| 85 | end |
| 86 | |
| 87 | # 终端标题设置 |
| 88 | function fish_title |
| 89 | # 获取当前目录名 |
| 90 | set -q debian_chroot[1]; and set -l chroot "($debian_chroot)" |
| 91 | echo "$chroot"(whoami)@(hostname -s): (prompt_pwd) |
| 92 | end |
| 93 | |
| 94 | # 自动补全增强 (Fish 默认已经很强大了) |
| 95 | # 如果开启了 globstar 类似的功能,可以使用 |
| 96 | set -g fish_glob_star 1 # 启用 ** 匹配 |
| 97 | |
| 98 | |
| 99 | #fish theme |
| 100 | function prompt_full_pwd --description 'Print the current working directory, NOT shortened to fit the prompt' |
| 101 | if test "$PWD" != "$HOME" |
| 102 | printf "%s" (echo $PWD|sed -e 's|/private||' -e "s|^$HOME|~|") |
| 103 | else |
| 104 | echo '~' |
| 105 | end |
| 106 | end |
| 107 | |
| 108 | function fish_prompt |
| 109 | # Cache exit status |
| 110 | set -l last_status $status |
| 111 | |
| 112 | # Just calculate these once, to save a few cycles when displaying the prompt |
| 113 | if not set -q __fish_prompt_hostname |
| 114 | set -g __fish_prompt_hostname (hostname|cut -d . -f 1) |
| 115 | end |
| 116 | |
| 117 | if not set -q __fish_prompt_char |
| 118 | switch (id -u) |
| 119 | case 0 |
| 120 | set -g __fish_prompt_char '#' |
| 121 | case '*' |
| 122 | set -g __fish_prompt_char '$' |
| 123 | end |
| 124 | end |
| 125 | |
| 126 | # Setup colors |
| 127 | set -l bold (set_color -o) |
| 128 | set -l normal (set_color normal) |
| 129 | set -l black (set_color -o black) |
| 130 | set -l blue (set_color -o blue) |
| 131 | set -l brown (set_color -o brown) |
| 132 | set -l cyan (set_color -o cyan) |
| 133 | set -l green (set_color -o green) |
| 134 | set -l magenta (set_color -o magenta) |
| 135 | set -l purple (set_color -o purple) |
| 136 | set -l red (set_color -o red) |
| 137 | set -l white (set_color -o white) |
| 138 | set -l yellow (set_color -o yellow) |
| 139 | if tput setaf 1 &> /dev/null |
| 140 | set bold (tput bold) |
| 141 | set reset (tput sgr0) |
| 142 | # Solarized colors, taken from http://git.io/solarized-colors. |
| 143 | set black (tput setaf 0) |
| 144 | set blue (tput setaf 33) |
| 145 | set brown (tput setaf 166) |
| 146 | set cyan (tput setaf 37) |
| 147 | set green (tput setaf 64) |
| 148 | set magenta (tput setaf 61) |
| 149 | set purple (tput setaf 125) |
| 150 | set red (tput setaf 124) |
| 151 | set white (tput setaf 15) |
| 152 | set yellow (tput setaf 136) |
| 153 | end |
| 154 | |
| 155 | # Configure __fish_git_prompt |
| 156 | set -g __fish_git_prompt_show_informative_status true |
| 157 | set -g __fish_git_prompt_showcolorhints true |
| 158 | |
| 159 | set -l user_style $brown |
| 160 | if [ (id -u) -eq 0 ] |
| 161 | set user_style $red |
| 162 | end |
| 163 | |
| 164 | set -l host_style $yellow |
| 165 | if set -q SSH_TTY |
| 166 | set host_style $bold$red |
| 167 | end |
| 168 | |
| 169 | # Color prompt char red for non-zero exit status |
| 170 | set -l pcolor $normal |
| 171 | if [ $last_status -ne 0 ] |
| 172 | set pcolor $red |
| 173 | end |
| 174 | |
| 175 | set -l _date (printf '%s' (date "+%a %b %d")) |
| 176 | set -l _time (printf '%s' (date +%H:%M:%S)) |
| 177 | |
| 178 | # Top |
| 179 | echo -n "⋊>" $user_style$USER$normal at $host_style$__fish_prompt_hostname$normal in $bold$blue(prompt_full_pwd)$normal |
| 180 | __fish_git_prompt |
| 181 | echo -n "" since $green$_date $cyan$_time$normal |
| 182 | |
| 183 | echo |
| 184 | |
| 185 | # Bottom |
| 186 | echo -n $pcolor$__fish_prompt_char $normal |
| 187 | end |
| 188 | |
| 189 | function set_color_custom |
| 190 | set -U fish_color_normal normal |
| 191 | set -U fish_color_command 005fd7 purple |
| 192 | set -U fish_color_param 00afff cyan |
| 193 | set -U fish_color_redirection 005fd7 |
| 194 | set -U fish_color_comment 600 |
| 195 | set -U fish_color_error red --bold |
| 196 | set -U fish_color_escape cyan |
| 197 | set -U fish_color_operator cyan |
| 198 | set -U fish_color_end green |
| 199 | set -U fish_color_quote brown |
| 200 | set -U fish_color_autosuggestion 555 yellow |
| 201 | set -U fish_color_user green |
| 202 | set -U fish_color_valid_path --underline |
| 203 | set -U fish_color_cwd green |
| 204 | set -U fish_color_cwd_root red |
| 205 | set -U fish_color_match cyan |
| 206 | set -U fish_color_search_match --background=purple |
| 207 | set -U fish_color_selection --background=purple |
| 208 | set -U fish_pager_color_prefix cyan |
| 209 | set -U fish_pager_color_completion normal |
| 210 | set -U fish_pager_color_description 555 yellow |
| 211 | set -U fish_pager_color_progress cyan |
| 212 | set -U fish_color_history_current cyan |
| 213 | set -U fish_color_host normal |
| 214 | end |
santisify / config.fish
Last active 3 months ago
Revision 41fa5520657786103d902ff54426a6e6da068ff0