finding file
This commit is contained in:
parent
240af31f53
commit
b028e2d836
|
@ -91,3 +91,52 @@ Scrolling through the output and searching for results that can be copied to the
|
|||
(magit-status (pop args) nil)
|
||||
(eshell/echo)) ;; The echo command suppresses output
|
||||
#+END_SRC
|
||||
** Find File
|
||||
We should have an "f" alias for searching the current directory for a file, and
|
||||
a "ef" for editing that file.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defun eshell/f (filename &optional dir try-count)
|
||||
"Searches for files matching FILENAME in either DIR or the
|
||||
current directory. Just a typical wrapper around the standard
|
||||
`find' executable.
|
||||
|
||||
Since any wildcards in FILENAME need to be escaped, this wraps the shell command.
|
||||
|
||||
If not results were found, it calls the `find' executable up to
|
||||
two more times, wrapping the FILENAME pattern in wildcat
|
||||
matches. This seems to be more helpful to me."
|
||||
(let* ((cmd (concat
|
||||
(executable-find "find")
|
||||
" " (or dir ".")
|
||||
" -not -path '*/.git*'"
|
||||
" -and -not -path '*node_modules*'"
|
||||
" -and -not -path '*classes*'"
|
||||
" -and "
|
||||
" -type f -and "
|
||||
"-iname '" filename "'"))
|
||||
(results (shell-command-to-string cmd)))
|
||||
|
||||
(if (not (s-blank-str? results))
|
||||
results
|
||||
(cond
|
||||
((or (null try-count) (= 0 try-count))
|
||||
(eshell/f (concat filename "*") dir 1))
|
||||
((or (null try-count) (= 1 try-count))
|
||||
(eshell/f (concat "*" filename) dir 2))
|
||||
(t "")))))
|
||||
|
||||
(defun eshell/ef (filename &optional dir)
|
||||
"Searches for the first matching filename and loads it into a
|
||||
file to edit."
|
||||
(let* ((files (eshell/f filename dir))
|
||||
(file (car (s-split "\n" files))))
|
||||
(find-file file)))
|
||||
#+END_SRC
|
||||
Typing =find= in Eshell runs the =find= function, which doesn’t do what I expect
|
||||
, and creating an alias is ineffective in overriding it, so a function will do:
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defun eshell/find (&rest args)
|
||||
"Wrapper around the ‘find’ executable."
|
||||
(let ((cmd (concat "find " (string-join args))))
|
||||
(shell-command-to-string cmd)))
|
||||
#+END_SRC
|
||||
|
|
Loading…
Reference in New Issue