                                   (org-element-property :path link)))
         (org-element-property :path link)))))
 
-;; (defun narf--org-attachments-in-dir ()
-;;   (-map (lambda (f) (concat "./" (f-relative f)))
-;;         (append (f-entries org-download-image-dir)
-;;                 (unless (f-same?
-;;                          (expand-file-name org-download-image-dir)
-;;                          (expand-file-name org-download-image-dir org-directory))
-;;                   (f-entries (expand-file-name org-download-image-dir org-directory)))))
-;;   )
+(defun narf-org--attachment-real-to-display (real)
+  (propertize (f-filename real) 'face (if (file-exists-p real) 'helm-ff-file 'shadow)))
 
-(defun narf--org-attachment-real-to-display (real)
-  (format "[%s] %s"
-          (if (file-exists-p real) "X" "")
-          (f-filename real)))
+(defun narf-org--attachment-find (file)
+  (search-forward-regexp (format "[[\\(file:\\)?%s]]" file) nil t)
+  (ignore-errors
+      (save-excursion
+        (outline-previous-visible-heading 1)
+        (org-show-subtree))))
 
-;; TODO Add delete action
-;; TODO Goto link on select
-(defun narf-org-attachment-source ()
-  (helm-build-sync-source "Attachments"
-    :candidates (narf--org-attachments)
-    :real-to-display 'narf--org-attachment-real-to-display
-    :action (lambda (f) (narf-open-with nil (f-dirname f)))))
+(defun narf-org--attachment-reveal (file)
+  (narf-open-with nil (f-dirname file)))
 
-;; TODO Organize this better
-;;;###autoload
-(defun narf/org-attachment-list ()
-  (interactive)
-  (helm :sources (narf-org-attachment-source)))
+(defun narf-org--attachment-open (file)
+  (narf-open-with nil file))
 
-;; TODO
-;; (defun narf/org-attachment-cleanup (&optional file)
-;;   (interactive)
-;;   )
-
-;; TODO
-;; (defun narf/org-attachment-cleanup-all ()
-;;   (interactive)
-;;   (dolist (file org-agenda-files)
-;;     (narf/org-attachment-cleanup file)))
+(defun narf-org--attachment-delete (file)
+  (delete-file file)
+  (narf-org--attachment-find file)
+  (message "File deleted, now delete the link! (%s)" file))
 
 (provide 'defuns-org-attach)
 ;;; defuns-org-attach.el ends here

         (f-dirname (org-element-property :path context))
       org-download-image-dir))))

;;;###autoload
(defun narf--org-attachments ()
  (org-element-map (org-element-parse-buffer) 'link
    (lambda (link)
      (when (and (string= (org-element-property :type link) "file")

                                        (format-time-string org-download-timestamp)
                                        (file-name-extension link))) buffer-file-name
                                        (org-download--fullname link))))
      (unless new-path
        (user-error "No file was provided"))
      (cond ((string-match-p "^https?://" link)
             (url-copy-file link new-path))
            (t (copy-file link new-path)))
      (insert (format "[[./%s]]" (f-relative new-path default-directory))))))

;;;###autoload (autoload 'narf:org-attachment-list "defuns-org-attach" nil t)
(evil-define-command narf:org-attachment-list (&optional bang)
  (interactive "<!>")
  (if bang
      (narf:org-attachment-cleanup)
    (let ((attachments (narf-org--get-attachments)))
      (unless attachments
        (user-error "No attachments in this file"))
      (helm :sources
            (helm-build-sync-source "Attachments"
              :candidates attachments
              :real-to-display 'narf-org--attachment-real-to-display
              :action '(("Go to Attachment in Buffer" . narf-org--attachment-find)
                        ("Reveal Attachment in Finder" . narf-org--attachment-reveal)
                        ("Open Attachment" . narf-org--attachment-open)
                        ("Delete Attachment" . narf-org--attachment-delete)))))))

;; TODO Improve
;;;###autoload
(defun narf/org-attachment-reveal ()
  (interactive)
  (let ((context (org-element-context)))
    (narf-open-with
