| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
(provide 'em-basic) |
|---|
| 26 |
|
|---|
| 27 |
(eval-when-compile (require 'esh-maint)) |
|---|
| 28 |
|
|---|
| 29 |
(defgroup eshell-basic nil |
|---|
| 30 |
"The \"basic\" code provides a set of convenience functions which |
|---|
| 31 |
are traditionally considered shell builtins. Since all of the |
|---|
| 32 |
functionality provided by them is accessible through Lisp, they are |
|---|
| 33 |
not really builtins at all, but offer a command-oriented way to do the |
|---|
| 34 |
same thing." |
|---|
| 35 |
:tag "Basic shell commands" |
|---|
| 36 |
:group 'eshell-module) |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
(defcustom eshell-plain-echo-behavior nil |
|---|
| 52 |
"*If non-nil, `echo' tries to behave like an ordinary shell echo. |
|---|
| 53 |
This comes at some detriment to Lisp functionality. However, the Lisp |
|---|
| 54 |
equivalent of `echo' can always be achieved by using `identity'." |
|---|
| 55 |
:type 'boolean |
|---|
| 56 |
:group 'eshell-basic) |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
(require 'esh-opt) |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
(defun eshell-echo (args &optional output-newline) |
|---|
| 91 |
"Implementation code for a Lisp version of `echo'. |
|---|
| 92 |
It returns a formatted value that should be passed to `eshell-print' |
|---|
| 93 |
or `eshell-printn' for display." |
|---|
| 94 |
(if eshell-plain-echo-behavior |
|---|
| 95 |
(concat (apply 'eshell-flatten-and-stringify args) "\n") |
|---|
| 96 |
(let ((value |
|---|
| 97 |
(cond |
|---|
| 98 |
((= (length args) 0) "") |
|---|
| 99 |
((= (length args) 1) |
|---|
| 100 |
(car args)) |
|---|
| 101 |
(t |
|---|
| 102 |
(mapcar |
|---|
| 103 |
(function |
|---|
| 104 |
(lambda (arg) |
|---|
| 105 |
(if (stringp arg) |
|---|
| 106 |
(set-text-properties 0 (length arg) nil arg)) |
|---|
| 107 |
arg)) |
|---|
| 108 |
args))))) |
|---|
| 109 |
(if output-newline |
|---|
| 110 |
(cond |
|---|
| 111 |
((stringp value) |
|---|
| 112 |
(concat value "\n")) |
|---|
| 113 |
((listp value) |
|---|
| 114 |
(append value (list "\n"))) |
|---|
| 115 |
(t |
|---|
| 116 |
(concat (eshell-stringify value) "\n"))) |
|---|
| 117 |
value)))) |
|---|
| 118 |
|
|---|
| 119 |
(defun eshell/echo (&rest args) |
|---|
| 120 |
"Implementation of `echo'. See `eshell-plain-echo-behavior'." |
|---|
| 121 |
(eshell-eval-using-options |
|---|
| 122 |
"echo" args |
|---|
| 123 |
'((?n nil nil output-newline "terminate with a newline") |
|---|
| 124 |
(?h "help" nil nil "output this help screen") |
|---|
| 125 |
:preserve-args |
|---|
| 126 |
:usage "[-n] [object]") |
|---|
| 127 |
(eshell-echo args output-newline))) |
|---|
| 128 |
|
|---|
| 129 |
(defun eshell/printnl (&rest args) |
|---|
| 130 |
"Print out each of the argument, separated by newlines." |
|---|
| 131 |
(let ((elems (eshell-flatten-list args))) |
|---|
| 132 |
(while elems |
|---|
| 133 |
(eshell-printn (eshell-echo (list (car elems)))) |
|---|
| 134 |
(setq elems (cdr elems))))) |
|---|
| 135 |
|
|---|
| 136 |
(defun eshell/listify (&rest args) |
|---|
| 137 |
"Return the argument(s) as a single list." |
|---|
| 138 |
(if (> (length args) 1) |
|---|
| 139 |
args |
|---|
| 140 |
(if (listp (car args)) |
|---|
| 141 |
(car args) |
|---|
| 142 |
(list (car args))))) |
|---|
| 143 |
|
|---|
| 144 |
(defun eshell/umask (&rest args) |
|---|
| 145 |
"Shell-like implementation of `umask'." |
|---|
| 146 |
(eshell-eval-using-options |
|---|
| 147 |
"umask" args |
|---|
| 148 |
'((?S "symbolic" nil symbolic-p "display umask symbolically") |
|---|
| 149 |
(?h "help" nil nil "display this usage message") |
|---|
| 150 |
:usage "[-S] [mode]") |
|---|
| 151 |
(if (or (not args) symbolic-p) |
|---|
| 152 |
(let ((modstr |
|---|
| 153 |
(concat "000" |
|---|
| 154 |
(format "%o" |
|---|
| 155 |
(logand (lognot (default-file-modes)) |
|---|
| 156 |
511))))) |
|---|
| 157 |
(setq modstr (substring modstr (- (length modstr) 3))) |
|---|
| 158 |
(when symbolic-p |
|---|
| 159 |
(let ((mode (default-file-modes))) |
|---|
| 160 |
(setq modstr |
|---|
| 161 |
(format |
|---|
| 162 |
"u=%s,g=%s,o=%s" |
|---|
| 163 |
(concat (and (= (logand mode 64) 64) "r") |
|---|
| 164 |
(and (= (logand mode 128) 128) "w") |
|---|
| 165 |
(and (= (logand mode 256) 256) "x")) |
|---|
| 166 |
(concat (and (= (logand mode 8) 8) "r") |
|---|
| 167 |
(and (= (logand mode 16) 16) "w") |
|---|
| 168 |
(and (= (logand mode 32) 32) "x")) |
|---|
| 169 |
(concat (and (= (logand mode 1) 1) "r") |
|---|
| 170 |
(and (= (logand mode 2) 2) "w") |
|---|
| 171 |
(and (= (logand mode 4) 4) "x")))))) |
|---|
| 172 |
(eshell-printn modstr)) |
|---|
| 173 |
(setcar args (eshell-convert (car args))) |
|---|
| 174 |
(if (numberp (car args)) |
|---|
| 175 |
(set-default-file-modes |
|---|
| 176 |
(- 511 (car (read-from-string |
|---|
| 177 |
(concat "?\\" (number-to-string (car args))))))) |
|---|
| 178 |
(error "setting umask symbolically is not yet implemented")) |
|---|
| 179 |
(eshell-print |
|---|
| 180 |
"Warning: umask changed for all new files created by Emacs.\n")) |
|---|
| 181 |
nil)) |
|---|
| 182 |
|
|---|
| 183 |
(eval-when-compile |
|---|
| 184 |
(defvar print-func)) |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|