<commit_before>#|
  This file is a part of shelly project.
  Copyright (c) 2012 <NAME> (<EMAIL>)
|#

(in-package :cl-user)
(defpackage shelly.install
  (:use :cl)
  (:import-from :cl-fad
                :copy-file
                :file-exists-p)
  (:import-from :swank-backend
                :quit-lisp)
  (:import-from :shelly.impl
                :*current-lisp-name*
                :*current-lisp-path*
                :*eval-option*
                :save-core-image)
  (:import-from :shelly.util
                :shadowing-use-package))
(in-package :shelly.install)

(cl-annot:enable-annot-syntax)

@export
(defun install (&key quit-lisp)
  "Install Shelly into your environment under \"~/.shelly\"."
  #+quicklisp (ql:quickload :shelly)
  #-quicklisp (asdf:load-system :shelly)

  (let ((home-config-path
         (merge-pathnames ".shelly/" (user-homedir-pathname)))
        (shly-path
         (asdf:system-relative-pathname :shelly "bin/shly")))

    (ensure-directories-exist home-config-path)

    (with-open-file (out (merge-pathnames
                          (format nil "config.~A" *current-lisp-name*)
                          home-config-path)
                         :direction :output
                         :if-does-not-exist :create
                         :if-exists :supersede)
      (format out "# -*- mode: perl -*-

{
~:[~;~:*    binary_path => \"~A\",~]
}
"
              (or
               (asdf:getenv "LISP_BINARY")
               *current-lisp-path*)))

    (with-open-file (out (merge-pathnames "config" home-config-path)
                         :direction :output
                         :if-does-not-exist :create
                         :if-exists :supersede)
      (format out "# -*- mode: perl -*-

{
    default_lisp => \"~A\",
    version => \"~A\",
}
"
              *current-lisp-name*
              (slot-value (asdf:find-system :shelly)
                          'asdf:version)))

    (dolist (dir '("dumped-cores/" "bin/"))
      (ensure-directories-exist
       (merge-pathnames dir home-config-path)))

    (cond
      ((fad:file-exists-p shly-path)
       (fad:copy-file shly-path
        (merge-pathnames "bin/shly" home-config-path)
        :overwrite t)
       ;; XXX: must be more portable.
       (asdf:run-shell-command
        "chmod u+x ~A"
        (merge-pathnames "bin/shly" home-config-path)))
      (t
       (warn "Shelly script doesn't exist. Ignored.")))

    (dump-core :quit-lisp nil))

  (format t "~&
Successfully installed!
Add this to your shell rc file (\".bashrc\", \".zshrc\" and so on).

    PATH=$HOME/.shelly/bin:$PATH

")
  (when quit-lisp
    (quit-lisp))
  (values))

(defvar *dumped-core-path*
    (merge-pathnames (format nil "dumped-cores/~A.core"
                             *current-lisp-name*)
                     (merge-pathnames ".shelly/" (user-homedir-pathname))))

@export
(defun dump-core (&key (quit-lisp t))
  "Dump Lisp core image file for faster startup."
  (cond
    (quit-lisp
     #+quicklisp (ql:quickload :shelly)
     #-quicklisp (asdf:load-system :shelly)
     (shelly.util:shadowing-use-package :shelly)
     (save-core-image *dumped-core-path*))
    (T
     (asdf:run-shell-command "~A ~A '~A' ~A '~A' ~A '~S'"
      *current-lisp-path*
      *eval-option*
      "#+quicklisp (ql:quickload :shelly) #-quicklisp (asdf:load-system :shelly)"
      *eval-option*
      "(shelly.util:shadowing-use-package :shelly)"
      *eval-option*
      '(shelly.impl:save-core-image *dumped-core-path*)))))

@export
(defun rm-core ()
  "Remove saved core image file which created by `dump-core'."
  (handler-case
      (progn (delete-file *dumped-core-path*)
             (format t "~&Successfully deleted: ~A~%"
                     *dumped-core-path*))
    (file-error (c) (princ c)))

  (quit-lisp))
<commit_msg>(fixes #1) getenv won't be exported from ASDF v2.25.<commit_after>#|
  This file is a part of shelly project.
  Copyright (c) 2012 <NAME> (<EMAIL>)
|#

(in-package :cl-user)
(defpackage shelly.install
  (:use :cl)
  (:import-from :asdf
                :getenv)
  (:import-from :cl-fad
                :copy-file
                :file-exists-p)
  (:import-from :swank-backend
                :quit-lisp)
  (:import-from :shelly.impl
                :*current-lisp-name*
                :*current-lisp-path*
                :*eval-option*
                :save-core-image)
  (:import-from :shelly.util
                :shadowing-use-package))
(in-package :shelly.install)

(cl-annot:enable-annot-syntax)

@export
(defun install (&key quit-lisp)
  "Install Shelly into your environment under \"~/.shelly\"."
  #+quicklisp (ql:quickload :shelly)
  #-quicklisp (asdf:load-system :shelly)

  (let ((home-config-path
         (merge-pathnames ".shelly/" (user-homedir-pathname)))
        (shly-path
         (asdf:system-relative-pathname :shelly "bin/shly")))

    (ensure-directories-exist home-config-path)

    (with-open-file (out (merge-pathnames
                          (format nil "config.~A" *current-lisp-name*)
                          home-config-path)
                         :direction :output
                         :if-does-not-exist :create
                         :if-exists :supersede)
      (format out "# -*- mode: perl -*-

{
~:[~;~:*    binary_path => \"~A\",~]
}
"
              (or
               (getenv "LISP_BINARY")
               *current-lisp-path*)))

    (with-open-file (out (merge-pathnames "config" home-config-path)
                         :direction :output
                         :if-does-not-exist :create
                         :if-exists :supersede)
      (format out "# -*- mode: perl -*-

{
    default_lisp => \"~A\",
    version => \"~A\",
}
"
              *current-lisp-name*
              (slot-value (asdf:find-system :shelly)
                          'asdf:version)))

    (dolist (dir '("dumped-cores/" "bin/"))
      (ensure-directories-exist
       (merge-pathnames dir home-config-path)))

    (cond
      ((fad:file-exists-p shly-path)
       (fad:copy-file shly-path
        (merge-pathnames "bin/shly" home-config-path)
        :overwrite t)
       ;; XXX: must be more portable.
       (asdf:run-shell-command
        "chmod u+x ~A"
        (merge-pathnames "bin/shly" home-config-path)))
      (t
       (warn "Shelly script doesn't exist. Ignored.")))

    (dump-core :quit-lisp nil))

  (format t "~&
Successfully installed!
Add this to your shell rc file (\".bashrc\", \".zshrc\" and so on).

    PATH=$HOME/.shelly/bin:$PATH

")
  (when quit-lisp
    (quit-lisp))
  (values))

(defvar *dumped-core-path*
    (merge-pathnames (format nil "dumped-cores/~A.core"
                             *current-lisp-name*)
                     (merge-pathnames ".shelly/" (user-homedir-pathname))))

@export
(defun dump-core (&key (quit-lisp t))
  "Dump Lisp core image file for faster startup."
  (cond
    (quit-lisp
     #+quicklisp (ql:quickload :shelly)
     #-quicklisp (asdf:load-system :shelly)
     (shelly.util:shadowing-use-package :shelly)
     (save-core-image *dumped-core-path*))
    (T
     (asdf:run-shell-command "~A ~A '~A' ~A '~A' ~A '~S'"
      *current-lisp-path*
      *eval-option*
      "#+quicklisp (ql:quickload :shelly) #-quicklisp (asdf:load-system :shelly)"
      *eval-option*
      "(shelly.util:shadowing-use-package :shelly)"
      *eval-option*
      '(shelly.impl:save-core-image *dumped-core-path*)))))

@export
(defun rm-core ()
  "Remove saved core image file which created by `dump-core'."
  (handler-case
      (progn (delete-file *dumped-core-path*)
             (format t "~&Successfully deleted: ~A~%"
                     *dumped-core-path*))
    (file-error (c) (princ c)))

  (quit-lisp))

{'fraction_non_alphanumeric': 0.16028552887735237, 'fraction_numerical': 0.0015574302401038286, 'mean_word_length': 1.9356190476190476, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7510553', 'n_tokens_mistral': 2770, 'n_tokens_neox': 2641, 'n_words': 537}