mirror of
https://github.com/wfxr/forgit.git
synced 2026-09-10 07:16:23 -04:00
The backwards-compatibility block that exports unexported FORGIT_ config variables ran `set | awk | grep` plus a `set -x | grep` for every variable, forking multiple external processes on every interactive fish startup. Replace the pipeline with fish's built-in `set -n`/`set -xn` and `string match`, which run in-process. Behavior is unchanged: unexported FORGIT_ variables are still detected, warned about, and exported; nothing is emitted when all variables are already exported. Co-authored-by: AllanZyne <AllanZyne@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
81 lines
4.2 KiB
Fish
81 lines
4.2 KiB
Fish
# MIT (c) Chris Apple
|
|
|
|
set -l install_dir (dirname (status dirname))
|
|
set -x FORGIT_INSTALL_DIR "$install_dir/conf.d"
|
|
set -x FORGIT "$FORGIT_INSTALL_DIR/bin/git-forgit"
|
|
if not test -e "$FORGIT"
|
|
set -x FORGIT_INSTALL_DIR "$install_dir/vendor_conf.d"
|
|
set -x FORGIT "$FORGIT_INSTALL_DIR/bin/git-forgit"
|
|
end
|
|
|
|
function forgit::warn
|
|
printf "%b[Warn]%b %s\n" '\e[0;33m' '\e[0m' "$argv" >&2
|
|
end
|
|
|
|
# backwards compatibility:
|
|
# export all user-defined FORGIT variables to make them available in git-forgit
|
|
set unexported_vars 0
|
|
for var in (set -n | string match -er '^FORGIT_')
|
|
if not set -xn | string match -qr "^$var\$"
|
|
if test $unexported_vars = 0
|
|
forgit::warn "Config options have to be exported in future versions of forgit."
|
|
forgit::warn "Please update your config accordingly:"
|
|
end
|
|
forgit::warn " set -x $var \"$$var\""
|
|
set unexported_vars (math $unexported_vars + 1)
|
|
set -x $var $$var
|
|
end
|
|
end
|
|
|
|
# alias `git-forgit` to the full-path of the command
|
|
alias git-forgit "$FORGIT"
|
|
|
|
function forgit::worktree
|
|
if test (count $argv) -ne 0
|
|
git-forgit worktree $argv
|
|
return $status
|
|
end
|
|
set -l tree (git-forgit worktree)
|
|
test -d "$tree"; and cd "$tree"
|
|
end
|
|
|
|
function forgit::worktree::add
|
|
set -l tree (git-forgit worktree_add $argv)
|
|
or return $status
|
|
test -d "$tree"; or return 0
|
|
cd "$tree"; or return 1
|
|
end
|
|
|
|
# register abbreviations
|
|
if test -z "$FORGIT_NO_ALIASES"
|
|
abbr -a -- (string collect $forgit_add; or string collect "ga") git-forgit add
|
|
abbr -a -- (string collect $forgit_reset_head; or string collect "grh") git-forgit reset_head
|
|
abbr -a -- (string collect $forgit_restore; or string collect "grs") git-forgit restore
|
|
abbr -a -- (string collect $forgit_log; or string collect "glo") git-forgit log
|
|
abbr -a -- (string collect $forgit_reflog; or string collect "grl") git-forgit reflog
|
|
abbr -a -- (string collect $forgit_diff; or string collect "gd") git-forgit diff
|
|
abbr -a -- (string collect $forgit_show; or string collect "gso") git-forgit show
|
|
abbr -a -- (string collect $forgit_ignore; or string collect "gi") git-forgit ignore
|
|
abbr -a -- (string collect $forgit_attributes; or string collect "gat") git-forgit attributes
|
|
abbr -a -- (string collect $forgit_checkout_file; or string collect "gcf") git-forgit checkout_file
|
|
abbr -a -- (string collect $forgit_checkout_file_from_commit; or string collect "gcff") git-forgit checkout_file_from_commit
|
|
abbr -a -- (string collect $forgit_checkout_branch; or string collect "gcb") git-forgit checkout_branch
|
|
abbr -a -- (string collect $forgit_switch_branch; or string collect "gsw") git-forgit switch_branch
|
|
abbr -a -- (string collect $forgit_branch_delete; or string collect "gbd") git-forgit branch_delete
|
|
abbr -a -- (string collect $forgit_clean; or string collect "gclean") git-forgit clean
|
|
abbr -a -- (string collect $forgit_stash_show; or string collect "gss") git-forgit stash_show
|
|
abbr -a -- (string collect $forgit_stash_push; or string collect "gsp") git-forgit stash_push
|
|
abbr -a -- (string collect $forgit_cherry_pick; or string collect "gcp") git-forgit cherry_pick_from_branch
|
|
abbr -a -- (string collect $forgit_rebase; or string collect "grb") git-forgit rebase
|
|
abbr -a -- (string collect $forgit_fixup; or string collect "gfu") git-forgit fixup
|
|
abbr -a -- (string collect $forgit_squash; or string collect "gsq") git-forgit squash
|
|
abbr -a -- (string collect $forgit_reword; or string collect "grw") git-forgit reword
|
|
abbr -a -- (string collect $forgit_checkout_commit; or string collect "gco") git-forgit checkout_commit
|
|
abbr -a -- (string collect $forgit_revert_commit; or string collect "grc") git-forgit revert_commit
|
|
abbr -a -- (string collect $forgit_blame; or string collect "gbl") git-forgit blame
|
|
abbr -a -- (string collect $forgit_checkout_tag; or string collect "gct") git-forgit checkout_tag
|
|
abbr -a -- (string collect $forgit_worktree; or string collect "gwt") forgit::worktree
|
|
abbr -a -- (string collect $forgit_worktree_add; or string collect "gwa") forgit::worktree::add
|
|
abbr -a -- (string collect $forgit_worktree_delete; or string collect "gwd") git-forgit worktree_delete
|
|
end
|