Last active
April 2, 2024 05:23
-
-
Save kenchou/4562f36bc30039b2f5ad744b5e82f487 to your computer and use it in GitHub Desktop.
进入git仓库目录自动执行 onefetch 显示统计信息。使用 fish 事件实现。来源 https://github.com/o2sh/onefetch/wiki/getting-started
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.config/fish/events/ | |
# 改变目录事件 | |
function __on_pwd_changed --on-variable PWD | |
check_directory_for_new_repository | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.config/fish/functions/ | |
function check_directory_for_new_repository | |
set current_repository (git rev-parse --show-toplevel 2> /dev/null) | |
if [ "$current_repository" ] && \ | |
[ "$current_repository" != "$last_repository" ] | |
# 防止进入 git init 但没有任何提交的新仓库报错 | |
onefetch || true | |
end | |
set -gx last_repository $current_repository | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.config/fish/conf.d/ 自动加载事件配置 | |
# 因为 fish 事件处理器函数并不会 autoload | |
set fish_events_dir ~/.config/fish/events | |
if test -d $fish_events_dir | |
for file in $fish_events_dir/*.fish | |
source $file | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment