Skip to content

Instantly share code, notes, and snippets.

@tomykaira
Created December 6, 2011 07:31
Show Gist options
  • Save tomykaira/1437200 to your computer and use it in GitHub Desktop.
Save tomykaira/1437200 to your computer and use it in GitHub Desktop.
bashmarks.el - share bashmarks shortcuts with emacs
;; -*- mode: Emacs-Lisp; coding: utf-8-unix -*-
;;; bashmarks.el - share bashmarks shortcuts with emacs
;; Copyright (C) tomykaira
;; Author: tomykaira <tomykaira@gmail.com>
;; Keywords:
;; This file 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 2, or (at your option)
;; any later version.
;; This file 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 GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Bashmarks: http://www.huyng.com/bashmarks-directory-bookmarks-for-the-shell/
;;; Code:
(defvar bm:sdirs "~/.sdirs"
"Location of .sdirs")
(defvar bm:open-dir-function 'find-file
"Function with which open the directory")
(defun bm:sdirs-to-map ()
(let (marks)
(with-temp-buffer
(insert-file sdirs)
(while (re-search-forward "export DIR_\\([^=]*\\)='\\([^']*\\)'" nil t)
(setq marks (cons (cons (match-string 1) (match-string 2)) marks))))
marks))
(defun bm:open-mark (marks abb)
(dolist (m marks)
(if (string= abb (car m))
(apply bm:open-dir-function (list (cdr m))))))
(defun bm:open-mark-interactively ()
(interactive)
(let ((marks (bm:sdirs-to-map)))
(bm:open-mark marks (completing-read "Shortcut?: " marks nil t))))
(provide 'bashmarks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment