[PATCH] contrib: add editmerge script for editor conflict prompts

Aaron Kushner akushner at fb.com
Thu Nov 21 12:33:53 CST 2013


On 11/15/13 1:23 PM, "Durham Goode" <durham at fb.com> wrote:


>+getlines() {
>+  grep -n "<<<<<<" $FILE | cut -f1 -d:
>+}

Consider 

  awk '/<<<<<</ {print NR}'

>the bottom though, since it's slow to run (0.15 seconds)
>+ED=$HGEDITOR
>+if [ "$ED" = "" ] ; then
>+  ED=$VISUAL
>+fi
>+if [ "$ED" = "" ] ; then
>+  ED=$EDITOR
>+fi
>+if [ "$ED" = "" ] ; then
>+  ED=$(hg showconfig ui.editor)
>+fi
>+if [ "$ED" = "" ] ; then
>+  echo "merge failed - unable to find editor"
>+  exit 1
>+fi


The shorter and more idiomatic bash way of the above is:

ED=${HGEDITOR:-$VISUAL}
ED=${ED:-$EDITOR}
ED=${ED:-$(hg showconfig ui.editor)}
ED=${ED:?"merge failed - unable to find editor"}



>+
>+if [ "$ED" = "emacs" ] || [ "$ED" = "nano" ] || [ "$ED" = "vim" ] ; then

Use double [[]] and the above becomes (don't need to quote the left side
(or right, really)):

If [[ $ED = "emacs || $ED = "nano" || $ED = "vim" ]]; then




More information about the Mercurial-devel mailing list