Created
May 7, 2011 04:51
-
-
Save am0c/960214 to your computer and use it in GitHub Desktop.
perlbrew on eshell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; eshell init script which let | |
;; perlbrew to be enabled in emacs eshell environment | |
;; it is translated from $HOME/perl5/perlbrew/etc/bashrc | |
;; to elisp script | |
;; | |
;; am0c <[email protected]> http://twitter.com/am0c | |
;; | |
(require 'cl) | |
(defmacro get-home-path () '(getenv "HOME")) | |
(defmacro getenv-to-string (env) | |
`(or (getenv ,env) "")) | |
(defun get-path-list (&optional path) | |
(split-string (getenv-to-string (or path "PATH")) ":" t)) | |
(defun set-path-list (path-list &optional path) | |
(setenv (or path "PATH") (mapconcat 'identity path-list ":"))) | |
(defmacro for-each-line-for-file (var-and-file &rest statements) | |
"for each line for file" | |
`(when (file-readable-p ,(cadr var-and-file)) | |
(with-temp-buffer | |
(insert-file-contents ,(cadr var-and-file)) | |
(goto-char (point-min)) | |
(while (prog2 | |
((lambda (,(car var-and-file)) ,@statements) | |
(buffer-substring (point) (progn (end-of-line) (point)))) | |
(< (point) (point-max)) | |
(beginning-of-line 2)))))) | |
(defun source-perlbrew-init (fn) | |
(for-each-line-for-file | |
(line (concat (get-home-path) "/.perlbrew/init")) | |
(with-temp-buffer | |
(insert line) | |
(goto-char (point-min)) | |
(search-forward "export " nil t) | |
(when (= (point) 8) | |
(let* ((idx (search-forward "=")) | |
(val (buffer-substring idx (progn (end-of-line) (point)))) | |
(key (buffer-substring 8 (decf idx)))) | |
(funcall fn key val)))))) | |
(defun perlbrew-set-path () | |
(when (not (string= (getenv-to-string "PERLBREW_ROOT") "")) | |
(let ((path-w/o-perlbrew | |
(remove-if (lambda (path) | |
(equal 0 (string-match (getenv-to-string "PERLBREW_ROOT") path))) (get-path-list)))) | |
(set-path-list (append (get-path-list "PERLBREW_PATH") path-w/o-perlbrew))))) | |
(set-path-list | |
(append | |
(mapcar #'(lambda (path) (concat (get-home-path) path)) | |
'("/bin" "/local/android/android-sdk-linux_86/tools" | |
"/local/android/android-sdk-linux_86/platform-tools")) | |
(get-path-list))) | |
(source-perlbrew-init 'setenv) | |
(perlbrew-set-path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment