From afce25cd650dfccdf70057691e2db6378242102b Mon Sep 17 00:00:00 2001 From: spacewander Date: Wed, 20 Jan 2016 11:39:25 +0800 Subject: [PATCH 1/2] use ps -f and awk to emulate pgrep There is no pgrep in git for windows --- bin/git-changelog | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/git-changelog b/bin/git-changelog index dc27a8b1d..bb01b7a9d 100755 --- a/bin/git-changelog +++ b/bin/git-changelog @@ -317,7 +317,20 @@ _exit() { stty sane; echo; echo "caught signal, shutting down" IFS=$'\n' - pid_list=( $(pgrep -P $$) ) + # The format of `ps` is different between Windows and other platforms, + # so we need to calculate the total column number(COL_NUM) of header first. + # Why don't we just use the last column? + # Because the body of CMD column may contain space and be treated as multiple fileds. + pid_list=( $(ps -f | + awk -v ppid=$$ 'NR == 1 { + COL_NUM = NF + } + $3 == ppid { + # filter out temp processes created in this subshell + if ($COL_NUM != "ps" && $COL_NUM != "awk" && $COL_NUM !~ "bash$") + print $2 + }') + ) IFS="$defaultIFS" local _pid From a192fe688ac65450602cba72850050889236476d Mon Sep 17 00:00:00 2001 From: spacewander Date: Wed, 20 Jan 2016 11:39:39 +0800 Subject: [PATCH 2/2] handle GIT_EDITOR which contains space --- bin/git-changelog | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/git-changelog b/bin/git-changelog index bb01b7a9d..80cecf96b 100755 --- a/bin/git-changelog +++ b/bin/git-changelog @@ -478,7 +478,10 @@ main() { rm -f "$tmpfile" else cp -f "$tmpfile" "$changelog" - [[ -n "$GIT_EDITOR" ]] && $GIT_EDITOR "$changelog" + # Use `eval` to handle GIT_EDITOR which contains space and options, + # like ""C:\Program Files (x86)\Notepad++\notepad++.exe" -multiInst ". + # Thanks @JanSchulz to inspire me this solution + [[ -n "$GIT_EDITOR" ]] && eval $GIT_EDITOR "$changelog" if [[ $? -ne 0 ]]; then _exit fi