[+] Fish (#7)

This commit is contained in:
2026-05-06 12:56:55 -04:00
committed by GitHub
parent f1bba8b7a5
commit 5a70fba83b
21 changed files with 1217 additions and 276 deletions
+138
View File
@@ -0,0 +1,138 @@
# 好用的简写
if has xdg-open
alias open xdg-open
end
alias ll 'ls -l'
alias l ll
alias llg 'll --git --git-repos'
alias lla 'ls -la'
alias grep 'grep --color=auto'
alias rm 'rm -ir'
alias mkdirs 'mkdir -p'
alias ip 'ip -c -h -p'
alias ipa 'ip -br a'
function ports --description 'Show listening ports'
if has ss
ss -tulpn
else
netstat -tulpn | grep LISTEN
end
end
function suports --description 'Show listening ports with root privileges when needed'
if has ss
__fishrc_as_root ss -tulpn
else
__fishrc_as_root netstat -tulpn | grep LISTEN
end
end
function findtxt --description 'Search for text under /'
if test (count $argv) -eq 0
echo 'Usage: findtxt <pattern>'
return 1
end
set -l pattern (string join ' ' -- $argv)
if has rg
rg -n --no-messages -- "$pattern" /
else
grep -IHrnws -s -e "$pattern" /
end
end
alias clr reset
alias please sudo
if test "$IS_SANDBOX" = 1
alias codex 'codex --dangerously-bypass-approvals-and-sandbox'
alias claude 'claude --dangerously-skip-permissions'
end
alias du 'du -h'
alias ffmpeg 'ffmpeg -hide_banner'
alias ffprobe 'ffprobe -hide_banner'
function ts --description 'Run tailscale with root privileges when needed'
__fishrc_as_root tailscale $argv
end
alias ts-install 'curl -fsSL https://tailscale.com/install.sh | sh'
alias visucode 'env EDITOR="code --wait" sudoedit'
alias cpu-temp s-tui
function gpu-temp --description 'Watch GPU temperatures with gpustat'
while sleep 1
clear
gpustat
end
end
function ipv4 --description 'Show public IPv4 from Cloudflare trace'
curl https://1.0.0.1/cdn-cgi/trace -4 | grep ip
end
function ipv6 --description 'Show public IPv6 from Cloudflare trace'
curl 'https://[2606:4700:4700::1111]/cdn-cgi/trace' -6 | grep ip
end
function compress-json --description 'Zstd-compress JSON files below the current directory'
find . -name '*.json' -print0 | parallel --jobs 80% -0 zstd -z -19 -v -f --rm '{}'
end
function dotclean --description 'Remove macOS metadata files below the current directory'
find . \( -name '.DS_Store' -o -name '._*' \) -delete -print
end
alias clean-empty-dir 'find . -type d -empty -delete -print'
function mkfs.fat32 --description 'Format FAT32 with root privileges when needed'
__fishrc_as_root mkfs.fat -F 32 $argv
end
# Rsync aliases by 依云, for synching (keep hard links, ACL, atime, xattr, etc)
# Deletes files in destination that are not in source
alias xcp "rsync -aviHAXKhS --one-file-system --partial --info=progress2 --atimes --open-noatime --delete --exclude='*~' --exclude=__pycache__"
alias xcpz 'xcp --compress-choice=zstd --compress-level=3 --checksum-choice=xxh3'
alias xmv 'xcp --remove-source-files'
alias xmvz 'xcpz --remove-source-files'
# Rsync aliases by Azalea, for file transfer (do not keep hard links, ACL, atime, etc.)
# Will not delete files in destination that are not in source
alias rcp "rsync -avihS --partial --info=progress2 --exclude='*~' --exclude=__pycache__"
alias rcpz 'rcp --compress --compress-level=3 --checksum-choice=xxh3'
alias rmv 'rcp --remove-source-files'
alias rmvz 'rcpz --remove-source-files'
alias tmuxs 'tmux new-session -s'
alias tmuxr 'tmux attach-session -t'
alias tmuxl 'tmux list-sessions'
alias catt 'echo 🐱'
alias old-update-ssh-keys 'curl -L https://github.com/Hykilpikonna.keys > ~/.ssh/authorized_keys'
alias colors "color '&000&111&222&333&444&555&666&777&888&999&aaa&bbb&ccc&ddd&eee&fff'"
alias tar-kill-progress 'watch -n 60 killall tar -SIGUSR1'
alias valgrin 'valgrind --leak-check=full --show-leak-kinds=all --leak-resolution=med --track-origins=yes --vgdb=no'
# Automatic sudo aliases.
if test (id -u) -ne 0
alias sctl 'sudo systemctl'
alias sctlu 'systemctl --user'
alias jctl 'sudo journalctl'
alias jctlu 'journalctl --user-unit'
alias ufw 'sudo ufw'
alias nginx 'sudo nginx'
alias certbot 'sudo certbot'
alias apt 'sudo apt'
alias dpkg 'sudo dpkg'
else
alias sctl systemctl
alias sctlu 'systemctl --user'
alias jctl journalctl
alias jctlu 'journalctl --user-unit'
end
+62
View File
@@ -0,0 +1,62 @@
# Config sync, matching the zsh setup for Linux-relevant files.
set -g __fishrc_config_prefix '&7[&3fishrc&7]'
function __fishrc_check_config --description 'Ensure a config path is a symlink to this repo'
set -l file $argv[1]
set -l sync $argv[2]
if test -z "$file"; or test -z "$sync"
return 1
end
if not test -L "$file"
if has color
color "$__fishrc_config_prefix &c$file is not a symlink, creating symlink"
else
echo "$file is not a symlink, creating symlink"
end
if test -f "$file"; or test -d "$file"
echo "> Original file $file exists."
echo '> Diff:'
diff "$file" "$sync"
set -l bak "$file.bak"
echo "> Moving $file to $bak..."
mv "$file" "$bak"
end
echo "> Creating symlink from $sync to $file..."
mkdir -p (dirname "$file")
ln -sf "$sync" "$file"
if has color
color "$__fishrc_config_prefix &aDone!"
end
end
end
function __fishrc_check_inject --description 'Append a config line if it is missing'
set -l file $argv[1]
set -l config $argv[2]
grep -Fxq "$config" "$file"; or begin
echo "$config" >>"$file"
has color; and color "$__fishrc_config_prefix &aLines injected for $file"
end
end
set -gx CFGSYNC "$ZSHRC_ROOT/config-sync"
if status is-interactive
__fishrc_check_config "$HOME/.ssh/config" "$CFGSYNC/ssh-config"
__fishrc_check_config "$HOME/.ssh/rc" "$CFGSYNC/ssh-rc"
chmod +x "$CFGSYNC/ssh-rc"
__fishrc_check_config "$HOME/.nanorc" "$CFGSYNC/nanorc"
__fishrc_check_config "$HOME/.condarc" "$CFGSYNC/.condarc"
__fishrc_check_config "$HOME/.java/.userPrefs/com/cburch/logisim/prefs.xml" "$CFGSYNC/.java/.userPrefs/com/cburch/logisim/prefs.xml"
__fishrc_check_config "$HOME/.config/micro" "$CFGSYNC/.config/micro"
__fishrc_check_config "$HOME/.config/mako" "$CFGSYNC/.config/mako"
__fishrc_check_config "$HOME/.config/kitty" "$CFGSYNC/.config/kitty"
__fishrc_check_config "$HOME/.config/tmux" "$CFGSYNC/.config/tmux"
__fishrc_check_config "$HOME/.ipython/profile_default/startup/ipython_init.py" "$CFGSYNC/ipython_init.py"
__fishrc_check_config "$HOME/.local/share/fcitx5/rime" "$CFGSYNC/.config/ibus/rime"
__fishrc_check_config "$HOME/.local/share/fcitx5/themes" "$CFGSYNC/.config/fcitx5/themes"
end
+39
View File
@@ -0,0 +1,39 @@
set -gx LANG en_US.UTF-8
set -gx LC_ALL en_US.UTF-8
function has --description 'Return success if a command exists'
test (count $argv) -gt 0; and command -sq -- $argv[1]
end
function __fishrc_as_root --description 'Run a command through sudo only when not root'
if test (id -u) -eq 0
command $argv
else
sudo $argv
end
end
function __fishrc_prepend_path --description 'Prepend directories to PATH if they exist'
for dir in $argv
if test -d "$dir"
if type -q fish_add_path
fish_add_path -g -p "$dir"
else if not contains -- "$dir" $PATH
set -gx PATH "$dir" $PATH
end
end
end
end
__fishrc_prepend_path \
"$SCR/bin" \
"$HOME/.local/bin" \
"$HOME/.cargo/bin"
if test (uname -s) = Linux; and test (uname -m) = x86_64
__fishrc_prepend_path "$SCR/bin/linux-x64"
end
if not contains -- . $PATH
set -gx PATH $PATH .
end
+22
View File
@@ -0,0 +1,22 @@
# Docker setup.
if has docker-compose
alias dc docker-compose
else
alias dc 'docker compose'
end
if test (id -u) -ne 0
alias docker 'sudo docker'
alias docker-compose 'sudo docker-compose'
end
alias docker-ip "docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}'"
alias dockers "docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'"
function docker-compose-path --description 'Show docker compose working directory for a container'
if test (count $argv) -eq 0
echo 'Usage: docker-compose-path <container-name>'
return 1
end
docker inspect "$argv[1]" | grep 'com.docker.compose.project.working_dir'
end
+14
View File
@@ -0,0 +1,14 @@
if has thefuck
thefuck --alias | source
end
# Reuse the existing zsh updater if zsh is installed. It runs in the background
# and preserves the repository's current update semantics without duplicating it.
if status is-interactive; and has zsh; and not set -q FISHRC_UPDATE_DISABLED
set -l __fishrc_update_path (string join : "$SCR/bin" $PATH)
env SCR="$SCR" ZSHRC_UPDATE_ASYNC_CHILD=1 PATH="$__fishrc_update_path" zsh -f "$SCR/includes/init/update.sh" >/dev/null 2>&1 &
end
if test -f "$HOME/extra.rc.fish"
source "$HOME/extra.rc.fish"
end
+125
View File
@@ -0,0 +1,125 @@
function mkcd --description 'Create a directory and cd into it'
if test (count $argv) -eq 0
echo 'Usage: mkcd <directory>'
return 1
end
mkdir -p "$argv[1]"; and cd "$argv[1]"
end
function set-java --description 'Set JAVA_HOME and PATH to an installed JDK version'
if test (count $argv) -eq 0
echo 'Usage: set-java <version>'
return 1
end
set -l java_home
if test -d /usr/lib/jvm
set java_home (find /usr/lib/jvm -maxdepth 1 -type d -name "*$argv[1]*" -name '*jdk*' | head -n 1)
end
if test -z "$java_home"
echo "Error: Java version $argv[1] not found in /usr/lib/jvm"
return 1
end
set -gx JAVA_HOME "$java_home"
__fishrc_prepend_path "$JAVA_HOME/bin"
end
function upload-daisy --description 'Upload a file to daisy-ddns'
set -l file (string join ' ' -- $argv)
curl -u azalea -F "path=@$file" 'https://daisy-ddns.hydev.org/upload?path=/'
end
function ttmp --description 'Go to /tmp/tmp'
mkdir -p /tmp/tmp; and cd /tmp/tmp
end
if has micro
set -gx EDITOR micro
else if has nano
set -gx EDITOR nano
end
# Use the stable SSH agent socket maintained by ~/.ssh/rc inside SSH/tmux sessions.
if test -n "$SSH_TTY"; or test -n "$SSH_CONNECTION"
if test -n "$SSH_AUTH_SOCK"; and test "$SSH_AUTH_SOCK" != "$HOME/.ssh/current_agent.sock"; and test -S "$SSH_AUTH_SOCK"
mkdir -p "$HOME/.ssh"
ln -sf "$SSH_AUTH_SOCK" "$HOME/.ssh/current_agent.sock"
end
if test -S "$HOME/.ssh/current_agent.sock"
set -gx SSH_AUTH_SOCK "$HOME/.ssh/current_agent.sock"
end
end
if not set -q GRADLE; and has gradle
set -gx GRADLE (command -s gradle)
end
function gradle --description 'Use ./gradlew when present, otherwise system gradle'
if test -f ./gradlew
./gradlew $argv
else if set -q GRADLE; and test -n "$GRADLE"
$GRADLE $argv
else
echo 'Neither gradle nor ./gradlew is found, please install it and restart fish.'
return 1
end
end
function 7z --description 'Block the dangerous 7z d command'
if test (count $argv) -gt 0; and test "$argv[1]" = d
echo "7z d is blocked. It does not stand for decompress, it stands for delete."
else
command 7z $argv
end
end
function reset-permissions-dangerous --description 'Reset file and directory permissions below the current directory'
__fishrc_as_root find . -type d -exec chmod 755 '{}' ';'
__fishrc_as_root find . -type f -exec chmod 644 '{}' ';'
end
function lisp --description 'Run a lisp file through roswell'
ros run --load "$argv[1]" --quit
end
function adblan --description 'Connect adb over LAN on port 16523'
adb connect "$argv[1]:16523"
end
alias adblan-start 'adb tcpip 16523'
function addline --description 'Add a line to a file if it does not already exist'
if test (count $argv) -lt 2
echo 'Usage: addline <file> <line>'
return 1
end
grep -qxF "$argv[2]" "$argv[1]"; or echo "$argv[2]" >>"$argv[1]"
end
function spushd --description 'Silent pushd'
pushd $argv >/dev/null; or return 1
end
function spopd --description 'Silent popd'
popd $argv >/dev/null; or return 1
end
function modern-replace --description 'Alias a command to a modern replacement when installed'
set -l orig_cmd $argv[1]
set -l new_cmd $argv[2]
set -l orig_cmd_with_args $argv[3]
set -l new_cmd_with_args $argv[4]
test -n "$orig_cmd_with_args"; or set orig_cmd_with_args $orig_cmd
test -n "$new_cmd_with_args"; or set new_cmd_with_args $new_cmd
if has "$new_cmd"
alias "$orig_cmd" "$new_cmd_with_args"
else
alias "$orig_cmd" "$orig_cmd_with_args"
end
end
+152
View File
@@ -0,0 +1,152 @@
# Git helpers.
function commit --description 'git commit wrapper'
if test (count $argv) -eq 0
git commit
else
git commit -m (string join ' ' -- $argv)
end
end
function commitall --description 'git add . and commit'
git add .
commit $argv
end
alias commita commitall
function compush --description 'commitall and push'
commitall $argv
git push
end
function git-ida --description 'Set git identity from git-id-list'
if test (count $argv) -eq 0
echo 'Usage: git-ida <identity>'
return 1
end
set -l identity (git-id-list get "$argv[1]")
git-id $identity[1] $identity[2]
end
function git-id --description 'Set git identity for this shell'
set -gx GIT_USER "$argv[1]"
set -gx GIT_EMAIL "$argv[2]"
git-id-prompt
end
function git-id-prompt --description 'Refresh git identity prompt segment'
if test -z "$GIT_USER"; and test -z "$GIT_EMAIL"
set -g __fishrc_git_id_segment ''
else
set -g __fishrc_git_id_segment "Git ID: $GIT_USER | $GIT_EMAIL "
end
end
function git --description 'git wrapper with per-shell identity override'
if test -z "$GIT_USER"
command git $argv
else
command git -c "user.name=$GIT_USER" -c "user.email=$GIT_EMAIL" -c commit.gpgsign=false $argv
end
end
function git-require-clean --description 'Require a clean git worktree'
command git rev-parse --is-inside-work-tree >/dev/null 2>&1; or return 1
set -l status_lines (command git status --porcelain 2>/dev/null)
if test (count $status_lines) -ne 0
echo 'Workspace is not clean.'
command git status --short
return 1
end
end
function git-main-branch --description 'Print the repository main branch name'
set -l remote_head (command git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null)
if test -n "$remote_head"
string replace -r '^origin/' '' -- "$remote_head"
return 0
end
for branch in main master trunk develop
if command git show-ref --verify --quiet refs/heads/$branch
printf '%s\n' "$branch"
return 0
end
if command git show-ref --verify --quiet refs/remotes/origin/$branch
printf '%s\n' "$branch"
return 0
end
end
echo 'Could not determine main branch.' >&2
return 1
end
function git-update-main --description 'Checkout and fast-forward the main branch'
set -l main_branch $argv[1]
if test -z "$main_branch"
set main_branch (git-main-branch); or return 1
end
command git checkout "$main_branch"; or return 1
command git pull --ff-only
end
function br --description 'Switch to an existing branch, or create one from updated main'
if test (count $argv) -ne 1
echo 'Usage: br <branch-name>'
return 1
end
set -l branch "$argv[1]"
git-require-clean; or return 1
if command git show-ref --verify --quiet "refs/heads/$branch"; or command git show-ref --verify --quiet "refs/remotes/origin/$branch"
command git checkout "$branch"
return $status
end
set -l main_branch (git-main-branch); or return 1
git-update-main "$main_branch"; or return 1
command git checkout -b "$branch"
end
function bru --description 'Update the current branch by rebasing it on updated main'
set -l current_branch (command git symbolic-ref --quiet --short HEAD 2>/dev/null)
if test -z "$current_branch"
echo 'Could not determine current branch.'
return 1
end
git-require-clean; or return 1
set -l main_branch (git-main-branch); or return 1
if test "$current_branch" = "$main_branch"
echo "Already on $main_branch."
return 1
end
git-update-main "$main_branch"; or return 1
command git checkout "$current_branch"; or return 1
command git rebase "$main_branch"
end
function git-env --description 'Alias common git subcommands into the shell'
set -l git_commands add bisect branch checkout clone commit diff fetch grep init log merge pull push rebase reset restore show stash tag
for cmd in $git_commands
alias "$cmd" "git $cmd"
end
alias grm 'git rm'
alias gmv 'git mv'
alias st 'git status'
end
function git-unenv --description 'Remove aliases created by git-env'
set -l git_commands add bisect branch checkout clone commit diff fetch grep init log merge pull push rebase reset restore show stash tag grm gmv st
for cmd in $git_commands
functions -q "$cmd"; and functions -e "$cmd"
end
end
git-id-prompt
+19
View File
@@ -0,0 +1,19 @@
# Modern unix replacements.
modern-replace ls eza 'ls -h --color=auto' eza
modern-replace df duf 'df -h' duf
modern-replace cat bat cat bat
modern-replace man tldr man tldr
modern-replace top btop top btop
modern-replace nano micro nano micro
modern-replace curl curlie curl curlie
modern-replace pacman paru 'pacman --color always' 'paru --color always'
modern-replace vi nvim vi nvim
modern-replace vim nvim vim nvim
modern-replace code visual-studio-code-electron code visual-studio-code-electron
if not has docker; and has podman
alias docker podman
if has podman-compose
alias docker-compose podman-compose
end
end
+73
View File
@@ -0,0 +1,73 @@
# Application aliases.
alias va-restart 'sctl restart va'
alias va-log-all 'jctl -u va --output cat'
alias va-log 'va-log-all -f'
alias jctlog 'jctl --output cat -f -u'
# Arch Linux setup.
if has pacman
if test (id -u) -eq 0
alias upgrade 'pacman -Syu'
else
alias upgrade 'sudo pacman -Syu'
end
alias install 'pacman -Sy'
alias uninstall 'pacman -Rsn'
alias list-unused 'pacman -Qdtq'
end
if test -f /etc/arch-release
__fishrc_prepend_path "$HOME/.local/share/JetBrains/Toolbox/scripts"
alias gpg-init "echo hi | gpg --status-fd=2 -bsau E289FAC0DA92DD2B"
alias ibus-init 'ibus-daemon -drxR'
alias autoremove 'yay -c'
function clean-cache --description 'Clean common package manager caches'
has yay; and yay -Sc --noconfirm
has pacman; and __fishrc_as_root pacman -Sc --noconfirm
has pacman; and __fishrc_as_root rm -rf /var/cache/pacman
has paru; and rm -rf "$HOME/.cache/paru"
has yarn; and yarn cache clean
has conda; and conda clean -a
has pip; and pip cache remove '*'
end
if test -f "$ZSHRC_ROOT/plugins/find-the-command/usr/share/doc/find-the-command/ftc.fish"
source "$ZSHRC_ROOT/plugins/find-the-command/usr/share/doc/find-the-command/ftc.fish"
end
end
# Mamba and Python environment setup.
alias mamba-install 'curl -L micro.mamba.pm/install.sh | bash'
set -q MAMBA_ROOT_PREFIX; or set -gx MAMBA_ROOT_PREFIX "$HOME/.conda"
function mamba-init --description 'Initialize micromamba for fish'
set -l mamba_exe (command -s micromamba)
if test -z "$mamba_exe"
echo 'Failed to initialize mamba: micromamba not found.'
return 1
end
$mamba_exe shell hook --shell fish --root-prefix "$HOME/micromamba" | source
set -l ret $pipestatus[1]
if test $ret -ne 0
echo "Failed to initialize mamba: Return code $ret."
echo "Note: this uses '--root-prefix' for mamba 2.0+. Upgrade with mamba-install if needed."
return $ret
end
end
if has micromamba
mamba-init
if not has conda
alias conda mamba
end
end
if has pyenv
pyenv init - fish | source
__fishrc_prepend_path (pyenv root)/shims
end
alias mamba micromamba
+241
View File
@@ -0,0 +1,241 @@
alias prompt "$SCR/helpers/prompt.py"
function pcolor --description 'Colorize text using the repository prompt helper'
"$SCR/helpers/prompt.py" (string join ' ' -- $argv) color
end
function prompt-reset --description 'Reset fish prompt state used by this rc'
set -g __fishrc_proxy_segment ''
git-id-prompt
end
function __fishrc_prompt_pr_state --description 'Set GitHub PR prompt state for a branch'
set -l branch $argv[1]
test -n "$branch"; or return 1
command -sq gh; or return 1
set -l repo_key (command git rev-parse --show-toplevel 2>/dev/null)
if test -z "$repo_key"
set repo_key (command jj root --ignore-working-copy 2>/dev/null)
end
set -l cache_key "$repo_key:$branch"
set -l now (date +%s)
if test "$__fishrc_prompt_pr_cache_key" = "$cache_key"
if string match -qr '^[0-9]+$' -- "$__fishrc_prompt_pr_cache_time"
set -l cache_age (math "$now - $__fishrc_prompt_pr_cache_time" 2>/dev/null)
if string match -qr '^[0-9]+$' -- "$cache_age"
if test "$cache_age" -lt 300
set -l cached_pr $__fishrc_prompt_pr_cache_value
test "$cached_pr[1]" != __none; or return 1
if test -z "$cached_pr[2]"
set cached_pr[2] green
end
set -g __fishrc_vcs_pr_number "$cached_pr[1]"
set -g __fishrc_vcs_pr_color "$cached_pr[2]"
return 0
end
end
end
end
set -l pr_line
if command -sq timeout
set pr_line (command timeout 1s gh pr list --head "$branch" --state all --limit 20 --json number,state,updatedAt --jq 'map(select(.state == "OPEN" or .state == "MERGED")) | sort_by(.updatedAt) | reverse | .[0] | select(.number != null) | .number, .state' 2>/dev/null)
else
set pr_line (command gh pr list --head "$branch" --state all --limit 20 --json number,state,updatedAt --jq 'map(select(.state == "OPEN" or .state == "MERGED")) | sort_by(.updatedAt) | reverse | .[0] | select(.number != null) | .number, .state' 2>/dev/null)
end
set -l pr_number (string trim -- "$pr_line[1]")
set -l pr_state (string trim -- "$pr_line[2]")
set -l pr_color green
if test "$pr_state" = MERGED
set pr_color purple
end
set -g __fishrc_prompt_pr_cache_key "$cache_key"
set -g __fishrc_prompt_pr_cache_time "$now"
if not string match -qr '^[0-9]+$' -- "$pr_number"
set -g __fishrc_prompt_pr_cache_value __none
return 1
end
set -g __fishrc_prompt_pr_cache_value "$pr_number" "$pr_color"
set -g __fishrc_vcs_pr_number "$pr_number"
set -g __fishrc_vcs_pr_color "$pr_color"
end
function __fishrc_git_unpushed_count --description 'Print commits ahead of the git upstream or remotes'
set -l upstream (command git rev-parse --abbrev-ref --symbolic-full-name '@{upstream}' 2>/dev/null)
if test -n "$upstream"
command git rev-list --count "$upstream"..HEAD 2>/dev/null
return
end
command git rev-list --count HEAD --not --remotes 2>/dev/null
end
function __fishrc_git_prompt_state --description 'Set compact git repository state for the prompt'
command -sq git; or return 1
command git rev-parse --is-inside-work-tree >/dev/null 2>&1; or return 1
set -l branch (command git symbolic-ref --quiet --short HEAD 2>/dev/null)
set -l pr_branch "$branch"
if test -z "$branch"
set branch (command git rev-parse --short HEAD 2>/dev/null)
end
test -n "$branch"; or return 1
set -l git_status (command git status --porcelain=v1 --branch 2>/dev/null)
set -l flags
set -l changed 0
set -l header $git_status[1]
set -l behind (string match -r 'behind [0-9]+' -- "$header" | string replace 'behind ' 'v')
set -l ahead_count (__fishrc_git_unpushed_count)
if string match -qr '^[0-9]+$' -- "$ahead_count"
if test "$ahead_count" -gt 0
set -a flags ^$ahead_count
set changed 1
end
end
test -n "$behind"; and set -a flags $behind
for line in $git_status[2..-1]
set changed 1
set -l index (string sub -s 1 -l 1 -- "$line")
set -l worktree (string sub -s 2 -l 1 -- "$line")
switch "$line"
case 'UU*' 'AA*' 'DD*' 'AU*' 'UA*' 'DU*' 'UD*'
contains x $flags; or set -a flags x
continue
case '??*'
contains '?' $flags; or set -a flags '?'
continue
end
if test "$index" != ' '
contains + $flags; or set -a flags +
end
if test "$worktree" != ' '
contains '!' $flags; or set -a flags '!'
end
end
set -l segment "git:$branch"
if test (count $flags) -gt 0
set segment "$segment "(string join '' -- $flags)
end
set -g __fishrc_vcs_segment "$segment"
set -g __fishrc_vcs_color 777777
if test "$changed" -eq 1
set -g __fishrc_vcs_color yellow
end
__fishrc_prompt_pr_state "$pr_branch"
return 0
end
function __fishrc_jj_prompt_state --description 'Set compact jj workspace state for the prompt'
command -sq jj; or return 1
command jj root --ignore-working-copy >/dev/null 2>&1; or return 1
set -l info (command jj log --no-graph --ignore-working-copy --color=never -r @ --template 'separate(" ", change_id.shortest(8), bookmarks.join("|"), if(conflict, "x")) ++ "\n"' 2>/dev/null)
test -n "$info"; or return 1
set -g __fishrc_vcs_segment "jj:$info"
set -g __fishrc_vcs_color 777777
set -l diff_summary (command jj diff --summary --ignore-working-copy 2>/dev/null)
if test -n "$diff_summary"
set -g __fishrc_vcs_color yellow
end
set -l pr_branch (command jj log --no-graph --ignore-working-copy --color=never -r 'bookmarks() & @' --template 'bookmarks.join("\n") ++ "\n"' 2>/dev/null)[1]
set pr_branch (string replace -r '\*$' '' -- "$pr_branch")
__fishrc_prompt_pr_state "$pr_branch"
return 0
end
function __fishrc_vcs_prompt_state --description 'Set prompt VCS segment state'
set -g __fishrc_vcs_segment ''
set -g __fishrc_vcs_color 777777
set -g __fishrc_vcs_pr_number ''
set -g __fishrc_vcs_pr_color green
__fishrc_jj_prompt_state; or __fishrc_git_prompt_state
end
function fish_prompt --description 'Repository fish prompt'
set -l host (prompt_hostname)
set host (string replace -r '^HyDEV-' '' -- "$host")
printf '\n'
if test "$host" = HyDEV
set_color magenta
printf '%s ' (date '+%a %m-%d %H:%M')
else
set_color 55CDFC
printf '%s ' (date '+%a')
set_color F7A8B8
printf '%s' (date '+%m-')
set_color FFFFFF
printf '%s ' (date '+%d')
set_color F7A8B8
printf '%s' (date '+%H:')
set_color 55CDFC
printf '%s ' (date '+%M')
end
set_color blue
if test "$host" = HyDEV
set_color 55CDFC
printf H
set_color F7A8B8
printf y
set_color FFFFFF
printf D
set_color F7A8B8
printf E
set_color 55CDFC
printf 'V '
else
printf '%s ' "$host"
end
set_color yellow
if test -n "$__fishrc_git_id_segment"
printf '%s' "$__fishrc_git_id_segment"
else
printf '%s ' "$USER"
end
set_color brgreen
printf '%s' "$__fishrc_proxy_segment"
set_color normal
printf '%s' (prompt_pwd)
__fishrc_vcs_prompt_state
if test -n "$__fishrc_vcs_segment"
printf ' '
set_color $__fishrc_vcs_color
printf '[%s' "$__fishrc_vcs_segment"
if test -n "$__fishrc_vcs_pr_number"
printf ' '
set_color $__fishrc_vcs_pr_color
printf '#%s' "$__fishrc_vcs_pr_number"
set_color $__fishrc_vcs_color
end
printf ']'
set_color normal
end
printf '\n> '
end
+63
View File
@@ -0,0 +1,63 @@
set -g __fishrc_proxy_segment ''
set -g __fishrc_git_id_segment ''
function setproxy --description 'Set common proxy environment variables'
set -l addr 127.0.0.1
set -l port 7890
test (count $argv) -ge 1; and set addr $argv[1]
test (count $argv) -ge 2; and set port $argv[2]
set -l full "$addr:$port"
set -gx https_proxy "http://$full"
set -gx http_proxy "http://$full"
set -gx all_proxy "http://$full"
set -gx HTTPS_PROXY "http://$full"
set -gx HTTP_PROXY "http://$full"
set -gx ALL_PROXY "http://$full"
set -g __fishrc_proxy_segment "proxy $full "
if has color
color "&aUsing proxy! $full&r"
else
echo "Using proxy! $full"
end
end
function ssh --description 'Use xterm-256color when connecting from kitty'
if test "$TERM" = xterm-kitty
env TERM=xterm-256color command ssh $argv
else
command ssh $argv
end
end
if status is-interactive; and test -z "$TMUX"; and test -n "$SSH_TTY"; and has tmux
tmux attach-session -t ssh_tmux; or tmux new-session -s ssh_tmux
end
function subtitle --description 'Generate subtitles with auto_subtitle'
env CUDA_VISIBLE_DEVICES=1 auto_subtitle --srt_only True --model large "$argv[1]"
end
function upload --description 'Upload a file to HyDEV daisy'
if test (count $argv) -eq 0
echo 'Usage: upload <file>'
return 1
end
if not set -q UP_PASSWORD; or test -z "$UP_PASSWORD"
echo 'Error: Password not set, please export UP_PASSWORD=xxx'
return 1
end
set -l file $argv[1]
set -l server_url 'https://daisy.hydev.org/upload?path=/'
set -l up_username azalea
if test -f "$file"
curl -u "$up_username:$UP_PASSWORD" -F "path=@$file" "$server_url"
else
echo 'Error: File not found.'
return 1
end
end