ohmyksh/extensions/got.ksh

66 lines
1.3 KiB
Bash
Raw Normal View History

2020-07-29 08:01:27 -06:00
#!/bin/ksh
# Thanks to jrick for this one:
# https://gist.github.com/jrick/d47e1be98609401e86ba0bd6bfbfc8fe
function got-push {
local r
2020-09-15 12:33:51 -06:00
r=$(set -e; got info | awk '$1 ~ "^repository:" {print $2}')
[ -z "$r" ] && return 1
(cd "$r" && git push "$@")
2020-07-29 08:01:27 -06:00
}
2020-08-06 07:08:02 -06:00
2020-08-24 08:54:37 -06:00
function got-sync {
2020-10-02 08:13:07 -06:00
local _remote _info _branch
2020-08-24 08:54:37 -06:00
_remote=$1
2020-10-02 08:13:07 -06:00
_info="$(got info)"
_branch="$(echo "$_info" | awk '/branch reference:/ {l = split($NF, a, "/"); print a[l]}')"
[ -z $_remote ] && _remote="origin"
[ -z $_branch ] && _branch="main"
got fetch "$_remote" && got update -b "$_remote/$_branch" && \
got rebase $_branch
2020-08-24 08:54:37 -06:00
}
2020-09-29 08:47:38 -06:00
function got-clean {
local _opt
_opt=$1
for f in $(got status | grep ^? | awk '{print $2}'); do
case "$_opt" in
-f)
rm -vf "$f"
;;
-i)
rm -vi "$f"
;;
*)
echo "Use -f or -i to actually remove files."
2020-09-29 08:47:38 -06:00
echo "rm $f"
;;
esac
done
}
function got-commit-v {
local _width _session _args
_args="$@"
tmux split-window -p 60
tmux select-pane -t 2
tmux send-keys "got diff $_args | less" C-m
tmux select-pane -t 1
tmux send-keys "clear" C-m
tmux send-keys "got commit $_args"
}
2020-08-16 07:58:33 -06:00
function __got_ps1 {
local _format _branch _status
_format=$1
_branch=$(got branch 2>/dev/null | grep -v conf_set_now)
_status=$?
if [ $_status == 0 ]; then
printf "$_format" $_branch
fi
}