Skip to content

Latest commit

 

History

History
131 lines (112 loc) · 5.83 KB

starter-kit-eshell.org

File metadata and controls

131 lines (112 loc) · 5.83 KB

Starter Kit Eshell

This is part of the Emacs Starter Kit.

My Starter Kit Eshell

Eshell is a great shell. Alias file here.

A table of input commands from here

SyntaxDescription
!!Repeats the last command
!lsRepeats the last command beginning with ls
!?lsRepeats the last command containing ls
!ls:nExtract the nth argument from the last command beginning with ls
!lsUsing pcomplete, show completion results matches ls
^old^newQuick substitution. Using the last command, replace old with new and run it again. Maybe buggy.
$_Returns the last parameter in the last executed command.

My default prompt function

Based on an answer from the Emacs wiki:

(defun empty-string? (str)
  "Test whether a string is empty"
  (string= "" str))

(defun remove-first-empty (lst)
  "Returns given list with first element removed if it was an empty string"
  (if (empty-string? (car lst))
      (cdr lst)
    lst))

(defun strip-space (str)
  "Returns the original string, minus any trailing spaces"
  (if (string= " " (substring str -1))
      (strip-space (substring str 0 -1))
    str))

(defun abbrev-user (str)
  "Change username to ~ in path name"
  (let ((un "/Users/FingerMan"
            ;; (mapconcat 'identity
            ;;            (list "/" "Users" (getenv "USER"))"/")
            ))
    (if (or (> (length un) (length str))
            (not (string= (substring str 0 (length un)) un)))
        str
      (concat "~"
              (substring str (length un) (length str))))))

(setq eshell-prompt-function
      (lambda()
        (concat ;; (getenv "USER") "@" (getenv "HOST") ":"
         ((lambda (p-lst vis-depth &optional dir-name-depth)
            "Given a list p-lst, will display full name (or optionally dir-name-depth characters) of the last vis-depth# directories in the path name, while the remaining directories at the front of the pathname will be abbreviated by their first letter "
            (if (> (length p-lst) vis-depth)
                (concat (mapconcat (lambda (elm)
                                     (unless (empty-string? elm)
                                       (substring elm 0 1)))
                                   (butlast p-lst vis-depth)
                                   "/")
                        "/"
                        (mapconcat (lambda (elm)
                                     (if (and dir-name-depth
                                              (> (length elm) dir-name-depth))
                                         (concat (strip-space (substring elm 0 dir-name-depth)) "..")
                                       elm))
                                   (last p-lst vis-depth)
                                   "/"))
              (mapconcat 'identity
                         p-lst
                         "/")))
          (split-string (abbrev-user (eshell/pwd)) "/") 2)
         (if (= (user-uid) 0) " # " "$ "))))

(setq eshell-prompt-regexp "^[^#$\n]*[#$] ")

My aliases

There are several ways to make aliases. Here are a couple for opening files via eshell. Some more tips here.

;;  (defalias 'emacs 'find-file)
  
  (defun eshell/emacs (file)
    (find-file file))
  
  (defun eshell/ff (file)
    (find-file file))

Starter Kit Eshell

(setq eshell-cmpl-cycle-completions nil
      eshell-save-history-on-exit t
      eshell-cmpl-dir-ignore "\\`\\(\\.\\.?\\|CVS\\|\\.svn\\|\\.git\\)/\\'")

(eval-after-load 'esh-opt
  '(progn
     (require 'em-cmpl)
     (require 'em-prompt)
     (require 'em-term)
     ;; TODO: for some reason requiring this here breaks it, but
     ;; requiring it after an eshell session is started works fine.
     ;; (require 'eshell-vc)
     (setenv "PAGER" "cat")
     ; (set-face-attribute 'eshell-prompt nil :foreground "turquoise1")
     (add-hook 'eshell-mode-hook ;; for some reason this needs to be a hook
               '(lambda () (define-key eshell-mode-map "\C-a" 'eshell-bol)))
     (add-to-list 'eshell-visual-commands "ssh")
     (add-to-list 'eshell-visual-commands "tail")
     (add-to-list 'eshell-command-completions-alist
                  '("gunzip" "gz\\'"))
     (add-to-list 'eshell-command-completions-alist
                  '("tar" "\\(\\.tar|\\.tgz\\|\\.tar\\.gz\\)\\'"))
     (add-to-list 'eshell-output-filter-functions 'eshell-handle-ansi-color)))

The eshell directory holds alias definitions and history information. It is much like a .bashrc file for those who are familiar with bash. This set the value of eshell-directory-name to point to the eshell directory in this directory. The alias file is pre-populated with some generally applicable aliases.

(setq eshell-directory-name (expand-file-name "./" (expand-file-name "eshell" dotfiles-dir)))