   "^\\(.+?\\):\\([1-9][0-9]*\\):\\([1-9][0-9]*\\):"
   "A regexp pattern that parses `filename:line_num:column_num`")
 
+(defvar ag-search-finish-hook nil)
+
 (defun ag/finished-hook (buffer how-finished)
   "once finished, open the first file."
   (with-current-buffer buffer
-    (compile-goto-error)))
+    (compile-goto-error)
+    (run-hooks 'ag-search-finish-hook)))
 
 (define-compilation-mode ag-mode "SKIM-Ag"
   "Ag results compilation mode"

      (term-char-mode)
      (setq mode-line-format (format "   SK  %s" default-directory)))))

(defun sk/wrap-after-term-handle-exit (callback output-file)
  (defun handler (process-name msg)
    (let ((lines (if (file-readable-p output-file)
		     (read-lines output-file)
		   '()))
	  (pwd default-directory))
      (kill-buffer "*SKIM*")
      (jump-to-register :sk-windows)
      (let ((default-directory pwd))
	(funcall callback lines))
      (advice-remove 'term-handle-exit #'handler)))
  #'handler)


      (if lines lines '()))))

(defun sk/command (opts)
  (let* ((temp-input nil)
	 (optstr (alist-get 'option opts ""))
	 (interactive? (alist-get 'interactive opts nil))
	 (source (alist-get 'source opts))
	 (source (cond
		  ((and (not source) (getenv "SKIM_DEFAULT_COMMAND"))
		   (let ((temp-file (make-temp-file "sk")))
		     ;; append the default command
		     (setq temp-input temp-file)
		     (write-region (getenv "SKIM_DEFAULT_COMMAND") nil temp-file)
		     (concat "sh " temp-file " 2>/dev/null")))
		  ((and source (stringp) (string= source "none"))
