Go Help

Go Run V2


The Go Run Chapter showed a basic External Tool for Running your code.   This is a much more complete script that does the following.

  1. Handles file and directory names with spaces (not a recommended practice).
  2. Can Run in real time with Display in a Popup Terminal or in Gedit New Tab or Bottom Pane.
  3. Can create a ‘.tmp’   file and Display in a Popup Window or in Gedit New Tab or Bottom Pane.


  1. Make sure that you have Zenity installed.  See the end of the Plugins Chapter.
  2. If you have a general ‘temp’ directory, set it as described in the introductory chapter.
  3. Open Gedit and Go to Tools>Manage External Tools.
  4. Choose Go Run, or create a new tool.
  5. Copy and Paste the script below into the code panel, overwriting the existing code.
  6. Make the other settings as documented in ‘Tool Settings’ in the script below.
  7. Set the OUTPUT switch below ‘Tool Settings’ in the script below.


# Go Run - Executes the Go program in the current Gedit tab
#          Assumes a Build output of $DOC.out
#  Manual - www.gohelp.wordpress.com - 'Gedit - An IDE for Go'
#   *Tool Settings: Save = nothing, Input = nothing, OutPut = see below
#           Set Tool Output to:
#OUTPUT=1   Bottom Pane or Create New Document - real time,    Display
#OUTPUT=2   Bottom Pane or Create New Document - save to file, Display
#OUTPUT=3   Bottom Pane - for error display    - real time,    Popup Terminal
#OUTPUT=4   Bottom Pane - for error display    - save to file, Popup Window
OUTPUT=3    # Set OUTPUT Switch


if   ! ( test -z "$MyTemp" ) # if MyTemp exists in environment
    TMPDIR="${DIR}"          # set TMPDIR to current document directory

GoRunFile="${DOC%%.go}.out"  # Strip '.go' and append ".out" to source file name

# Test for .out file exists

if  (test -s "${GoRunFile}") # TRUE if GoRunFile exists and is not empty
    case $OUTPUT in
        1) "${DIR}"/"${GoRunFile}"
        2) "${DIR}"/"${GoRunFile}" > "${TMPDIR}"/GoRunOut.tmp
           cat "${TMPDIR}"/GoRunOut.tmp
           rm  "${TMPDIR}"/GoRunOut.tmp
        3) TermCmd="\"${DIR}\""/"\"${GoRunFile}\""
           gnome-terminal --command "${TermCmd}" -t "Go Run ${TermCmd}" &
        4) "${DIR}"/"${GoRunFile}" > "${TMPDIR}"/GoRunOut.tmp

           nLines=`wc -l "${TMPDIR}"/GoRunOut.tmp|awk '{print $1}'`
           if [ "${nLines}" -gt 28 ]
           zHeight=$(( nLines * 25 ))

           longLine=`wc -L "${TMPDIR}"/GoRunOut.tmp|awk '{print $1}'`
           if [ "${longLine}" -gt 80 ]
           zWidth=$(( longLine * 9 ))

           zenity --text-info \
               --height=${zHeight} \
               --width=${zWidth} \
               --title="Go Run" \
               --filename="${TMPDIR}"/GoRunOut.tmp \ &

           sleep 2  # make sure new shell tasks have displayed, then exit
           rm  "${TMPDIR}"/GoRunOut.tmp
        *) echo "Please Set Go Run OUTPUT option"
	echo "Cannot Find \"${GoRunFile}\""


  1. Open Gedit and open a Go source file that outputs something.
  2. Go Build
  3. Press your Go Run shortcut key, or go to the menu and go to Tools>External Tools>Go Run.

You should see the output displayed on your choice of displays.  If it is a terminal, it will close when your program ends.

Create a free website or blog at WordPress.com.

%d bloggers like this: