UGC returns as a function

This commit is contained in:
Mylloon 2023-10-09 17:56:56 +02:00
parent cce91f9917
commit 6a6131acaf
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,53 @@
function ugc --description "Update git fork."
# Declare our arguments
argparse h/help c/current -- $argv
or return
# Get function name
set current_name $(status current-function)
set upstream_remote upstream
# Check if no arguments were provided, or if the first argument is '--help'
if set -ql _flag_help
echo -e "Usage: $current_name"
echo -e " $current_name [-h|--help] - Show this help message"
echo -e " $current_name \t\t - Update master branch from '$upstream_remote' remote"
echo -e " $current_name [-c|--current] - Update current branch from '$upstream_remote' remote"
return 0
end
# Check if we are in a git repository
git status >/dev/null
if not test $status -eq 0
echo "$current_name: not in a git repository" 1>&2
return 1
end
# Check if upstream exists
if not contains upstream (git remote)
echo "$current_name: not '$upstream_remote' remote" 1>&2
echo "$current_name: use: git remote add $upstream_remote <URL>" 1>&2
return 1
end
# Check what is the default branch
set origin_remote origin
set default_branch (git remote show $origin_remote | sed -n '/HEAD/s/.*: //p')
set current_branch (git rev-parse --abbrev-ref HEAD)
if not set -ql _flag_current
# Change to default branch
git switch $default_branch
end
# Merge upstream
git fetch $upstream_remote
git pull $upstream_remote $default_branch
git push $origin_remote $default_branch
if not set -ql _flag_current
# Return to the branch we were before if we changed
git switch $current_branch
end
end

View file

@ -50,6 +50,7 @@ sync-dotconfig:
@$(WGET) $(REPO_SRC)/.config/fish/functions/makeaway.fish -O $(HOME)/.config/fish/functions/makeaway.fish
@$(WGET) $(REPO_SRC)/.config/fish/functions/ssh-export.fish -O $(HOME)/.config/fish/functions/ssh-export.fish
@$(WGET) $(REPO_SRC)/.config/fish/functions/ssh-import.fish -O $(HOME)/.config/fish/functions/ssh-import.fish
@$(WGET) $(REPO_SRC)/.config/fish/functions/ugc.fish -O $(HOME)/.config/fish/functions/ugc.fish
@$(WGET) $(REPO_SRC)/.config/fish/conf.d/abbr.fish -O $(HOME)/.config/fish/conf.d/abbr.fish
@$(WGET) $(REPO_SRC)/.config/fish/conf.d/alias.fish -O $(HOME)/.config/fish/conf.d/alias.fish