|
|
@@ -16,7 +16,38 @@ set -gx PATH $HOME/.local/bin $PATH |
| 16 |
16 |
|
|
| 17 |
17 |
|
# nvm |
| 18 |
18 |
|
set --global nvm_data ~/.nvm |
| 19 |
|
- |
set -gx nvm_default_version v24.13.0 |
|
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 |
| 20 |
51 |
|
|
| 21 |
52 |
|
# 提醒别名 (alert 的 Fish 版本) |
| 22 |
53 |
|
function alert |
|
|
@@ -64,7 +95,120 @@ end |
| 64 |
95 |
|
# 如果开启了 globstar 类似的功能,可以使用 |
| 65 |
96 |
|
set -g fish_glob_star 1 # 启用 ** 匹配 |
| 66 |
97 |
|
|
| 67 |
|
- |
# 加载本地配置(如果存在) |
| 68 |
|
- |
if test -f ~/.config/fish/local.fish |
| 69 |
|
- |
source ~/.config/fish/local.fish |
|
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 |
| 70 |
214 |
|
end |