Skip to content

Instantly share code, notes, and snippets.

@burke
Created December 7, 2018 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burke/af8efcab5fbbda769dd0bbe69e9c2334 to your computer and use it in GitHub Desktop.
Save burke/af8efcab5fbbda769dd0bbe69e9c2334 to your computer and use it in GitHub Desktop.
;;; helm-dev.el --- dev cd - projectile/helm interface. -*- lexical-binding: t -*-
;; Version: 1.0.0
;; Package-Requires: ((helm "1.5") (cl-lib "0.5") (emacs "24.1"))
;;; Code:
(require 'cl-lib)
(require 'helm)
(require 'helm-utils)
(require 'helm-adaptive)
(defgroup helm-dev nil
"dev related Applications and libraries for Helm."
:group 'helm)
(defcustom helm-dev-actions (helm-make-actions
"dev cd"
(lambda (candidate)
(helm-dev-cd candidate)))
"Actions for helm-dev."
:group 'helm-dev
:type '(alist :key-type string :value-type function))
(defun helm-dev-build-project-list ()
(split-string (shell-command-to-string "/opt/dev/bin/dev cd --list")))
(defun helm-dev-string-chomp (string)
(let ((len (length string)))
(cond
((and (> len 0) (eql (aref string (- len 1)) ?\n))
(substring string 0 (- len 1)))
(t string))))
(defun helm-dev-activate-project (spec)
(let ((path (helm-dev-string-chomp (shell-command-to-string (concat "/opt/dev/bin/dev project-path " spec)))))
(message "activating dev project %s" path)
(projectile-add-known-project path)
(dired path)))
;;;###autoload
(defun helm-dev-cd ()
"Preconfigured `helm' for dev cd."
(interactive)
(let ((candidates (helm-dev-build-project-list)))
(helm :sources (helm-build-sync-source "devcd"
:candidates candidates
:action (lambda (candidate) (helm-dev-activate-project candidate)))
:buffer "*helm-devcd*")))
(provide 'helm-dev)
;; Local Variables:
;; byte-compile-warnings: (not cl-functions obsolete)
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:
;;; helm-dev.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment