Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 84 additions & 9 deletions lib/git-hub
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ run-command() {
get-opts "$@"
assert-env

local cleanup_msg_file
callable-or-source "$command" ||
error "unknown 'git hub' command '$command'"
"command:$command" "$@"
Expand All @@ -115,6 +116,10 @@ run-command() {
say "${msg_ok:-"'git hub $command' command successful"}"
fi
fi
# successful, delete the tmp file
if [[ -n "$cleanup_msg_file" ]]; then
rm -f $GIT_HUB_MSG_FILE
fi
else
local status_msg="msg_$status_code"
if [[ -n ${!status_msg} ]]; then
Expand Down Expand Up @@ -1323,16 +1328,88 @@ prompt-to-run-setup() {
#------------------------------------------------------------------------------
# Reusable helper functions:
#------------------------------------------------------------------------------
editor-title-body() {
rm -f "$GIT_HUB_MSG_FILE"

echo "$1" > "$GIT_HUB_MSG_FILE"
init-msg-file() {
cleanup_msg_file=1
local commandline="$command"
[[ -n $command_arguments ]] && commandline="$commandline $command_arguments"
local body="$1
#
# Command: $commandline"
if [[ -f $GIT_HUB_MSG_FILE ]]; then
local last_line=`tail -1 $GIT_HUB_MSG_FILE`
if [[ $last_line =~ ^#[[:space:]]Command:[[:space:]](.*) ]]; then
local last_cmd="git hub ${BASH_REMATCH[1]}"
local date
if osx; then
local epoch=`stat -f "%m" $GIT_HUB_MSG_FILE`
date=`date -r $epoch`
else
date=`date -r $GIT_HUB_MSG_FILE`
fi
local prompt="(r)euse, (s)how, (d)elete, (a)bort?"
echo "
Found existing $GIT_HUB_MSG_FILE from:

command: '$last_cmd'
date: $date
"
while true
do
echo -n "$prompt "
local action
read action

case $action in

r)
# remove all comment lines
sed -i -e '/^#.*$/d' $GIT_HUB_MSG_FILE
echo "$body" | sed -e '/^$/d' >> "$GIT_HUB_MSG_FILE"
break
;;
d)
rm -f "$GIT_HUB_MSG_FILE"
echo "$body" > "$GIT_HUB_MSG_FILE"
break
;;
s)
echo
head $GIT_HUB_MSG_FILE | grep -v '^#'
echo
;;
*)
exit 0 # or 1?
;;

esac
done

else
echo "$body" > "$GIT_HUB_MSG_FILE"
fi
else
echo "$body" > "$GIT_HUB_MSG_FILE"
fi

}

delete-empty-msg-file() {
local content=`grep -v '^#' $GIT_HUB_MSG_FILE | grep -v '^$'`
if [[ -z "$content" ]]; then
rm $GIT_HUB_MSG_FILE
fi
}

editor-title-body() {
init-msg-file "$1"

$GIT_HUB_EDITOR "$GIT_HUB_MSG_FILE"
local line
body=''
title="$(head -n1 "$GIT_HUB_MSG_FILE")"
if [[ ! $title =~ [^[:space:]] || $title =~ ^\# ]]; then
delete-empty-msg-file
abort "no title provided"
fi
line="$(head -n2 "$GIT_HUB_MSG_FILE" | tail -n1)"
Expand All @@ -1351,9 +1428,7 @@ editor-title-body() {
}

editor-comment() {
rm -f "$GIT_HUB_MSG_FILE"

echo "$1" > "$GIT_HUB_MSG_FILE"
init-msg-file "$1"

$GIT_HUB_EDITOR "$GIT_HUB_MSG_FILE"
local line
Expand All @@ -1364,16 +1439,15 @@ editor-comment() {
[[ $line =~ ^\# ]] && break
body+="$line"$'\n'
done < "$GIT_HUB_MSG_FILE"
delete-empty-msg-file
IFS="$ifs"
}

editor-comment-state() {
rm -f "$GIT_HUB_MSG_FILE"
init-msg-file "$1"

comment= title= state= assignee= milestone=

echo "$1" > "$GIT_HUB_MSG_FILE"

$GIT_HUB_EDITOR "$GIT_HUB_MSG_FILE"
local line started=false

Expand Down Expand Up @@ -1402,6 +1476,7 @@ editor-comment-state() {
IFS="$ifs"

if [[ ! $title =~ [^[:space:]] ]]; then
delete-empty-msg-file
abort "no title provided."
fi
}
Expand Down