Skip to content

Commit

Permalink
Create consult-ghq.el
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoya committed May 31, 2021
1 parent ade7332 commit aa8ae02
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions consult-ghq.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
;;; consult-ghq.el --- Ghq interface using consult -*- lexical-binding: t; -*-

;; Copyright (C) 2021 Tomoya Otake

;; Author: Tomoya Otake <tomoya.ton@gmail.com>
;; Version: 0.0.1
;; Homepage: https://github.com/tomoya/consult-ghq
;; Keywords: convenience, usability, consult, ghq
;; Package-Requires: ((emacs "26.1") (consult "0.8"))
;; License: GPL-3.0-or-later

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; This packaage provides qhq interface using Consult.
;;
;; Its main entry points are the commands `consult-ghq'.

;;; Code:

(require 'consult)

(defgroup consult-ghq nil
"Ghq interface using consult."
:prefix "consult-ghq-"
:group 'consult)

(defcustom consult-ghq-command
"ghq"
"*A ghq command."
:type 'string
:group 'consult-ghq)

(defun consult-ghq--list-candidates ()
"Return ghq list candidate."
(with-temp-buffer
(unless (zerop (apply #'call-process
consult-ghq-command nil t nil
'("list" "--full-path")))
(error "Failed: Cannot get ghq list candidates"))
(let ((paths))
(goto-char (point-min))
(while (not (eobp))
(push
(buffer-substring-no-properties
(line-beginning-position) (line-end-position))
paths)
(forward-line 1))
(reverse paths))))

;;;###autoload
(defun consult-ghq ()
"Find file from selected repo using ghq."
(interactive)
(let ((repo (consult--read (consult-ghq--list-candidates) :prompt "Find repo: ")))
(consult-find repo)))

(provide 'consult-ghq)

;;; consult-ghq.el ends here

0 comments on commit aa8ae02

Please sign in to comment.