I want to replace `ls` with `ls -l` in eshell - emacs

I use eshell-parse-command 'ls -l' and I got this:
(progn (eshell-trap-errors
(eshell-named-command "ls" (list "-l"))))
Then I write a alias in my .emacs file:
(defalias 'ls
(progn ...))
But I doesn't work. I don't know why.

Add following code to your configuration file.
(require 'em-alias)
(add-to-list 'eshell-command-aliases-list (list "ls" "ls -l"))

The easiest way to add alias to eshell is:
Open eshell,
alias alias-name definition
Eshell will automatically write it into ~/emacs.d/eshell/alias (don't edit it yourself).
For example:
alias sau sudo aptitude update
Then you can type sau to launch sudo aptitude update.
Type alias (in eshll, of course) will list all the alias you've defined.
Some useful alias:
Map find-file to ff, then you can open a file in emacs with ff file:
alias ff 'find-file $1'
Map dired to d:
alias d 'dired $1'
Resources:
Mastering Eshell
http://www.masteringemacs.org/article/complete-guide-mastering-eshell

Related

How to copy Zsh aliases to Eshell

I'm trying to copy using the command provided in here. That is,
alias | sed -E "s/^alias ([^=]+)='(.*)'$/alias \1 \2 \$*/g; s/'\\\''/'/g;" >~/.emacs.d/eshell/alias
This worked with Bash, I was using Emacs-Starter-Kit; but not working with Zsh -- not working means it copied things but to no effect.
[As a side note]
It seems like, I don't have few Eshell default variables i.e. eshell-read-aliases-list, and eshell-aliases-file. So, I even don't know where should my Eshell alias file reside.
Got it working after setting
(setq eshell-directory-name (expand-file-name "./" (expand-file-name "eshell" prelude-personal-dir)))
in post.el (my personal .el file for post-processing) under prelude/personal
... and modified the given bash command to
alias | awk '{print "alias "$0}' | sed -E "s/^alias ([^=]+)='(.*)'$/alias \1 \2 \$*/g; s/'\\\''/'/g;" > ~/.emacs.d/personal/eshell/alias
... and appended that to .zshrc.
Found that alias command, in zsh, prints aliases without prefix alias<space>, unlike bash. Therefore this part
| awk '{print "alias "$0}'

objdump from inside emacs

Assuming I have my working folder as ~/X/ and the binaries after compiling are in ~/X/bin/
I usually first get the objdump like so:
objdump -D ~/X/bin/bin1 > bin1.list
then emacs bin1.list&
How is it possible to assign a function in .emacs to open a temporary buffer in Emacs and execute objdump -D in on the binary in it directly?
Sure, by default the command M-! (shell-command) outputs shell output to a default output buffer.
M-! objdump -D /bin/ls
If you want to change the name of the output buffer, you can invoke shell-command through some elisp:
(shell-command "objdump -D /bin/ls" "ls.dump")
or
C-x C-w (write-file) - to write the shell output buffer to a file
Edit:
Example which grabs file at point if available, or prompts the user
(defun my-objdump-file (&optional file)
(interactive)
(unless file
(setq file (expand-file-name (or (thing-at-point 'filename)
(read-file-name "File: ")))))
(when file
(shell-command (concat "objdump -D "
file)
"*Objdump Output*")))

The root's password is exposed in eshell

I have defined the following alias in eshell:
$ alias
alias ff find-file $1
alias l ls -l $*
alias ll ls -l $*
alias sudo *sudo $*
When i run "sudo **" and input the root's password, the password is displayed completely.
Regards!
Chances are, the regexp that is being used to look for the password prompt isn't set up properly for your situation.
Try the following:
(require 'comint)
(setq comint-password-prompt-regexp
"\\(\\([Vv]erify\\|[Oo]ld \\|[Nn]ew \\|'s \\|login \\|\
Kerberos \\|CVS \\|UNIX \\| SMB \\|^\\)\
\\([Pp]assword\\|Verify\\\\|密码)\\( (again)\\)?\\|\
pass phrase\\|\\(Enter\\|Repeat\\|Bad\\) passphrase\\)\
\\(?:, try again\\)?\\(?: for [^:]+\\)?:\\s *\\'")
Note: I just took the value for comint-password-prompt-regexp and added the characters you said were your prompt.

How do I provide a command-line option to emacsclient?

I start emacsclient using:
emacsclient -a "" -c
This opens a frame connected to the emacs daemon, and starts the daemon if it's not already started. Great, this works fine.
However, I like opening my emacs frames maximized. With emacs, I would use -mm. However, that doesn't work with emacsclient. How do I make this work?
(It seems I could make something work by adding a shell file like so: emacsclient -a "myshell.sh" -c, where the shell file is: emacs -mm, but I haven't been able to make that work - the server doesn't stay up.)
You can add the following line to .emacs, so that Emacs can be started with the window maximized. See http://www.gnu.org/software/emacs/manual/html_node/elisp/Size-Parameters.html#Size-Parameters for details.
(add-to-list 'default-frame-alist '(fullscreen . maximized))
Emacs client accepts -F option, where you can specify frame parameters, so the above example would be:
emacsclient -c -a "" -F "((fullscreen . maximized))"
Let's say you want to run emacsclient fullscreen, which was my case.
man emacsclient shows emacsclient has -F option:
-F, --frame-parameters=ALIST
set the parameters of a newly-created frame.
In Emacs Manual, which is an info file, section (emacs) emacsclient Options has more information. Specifically for this question (elisp) Size Parameters mentions fullscreen parameter. To run emacsclient fullscreen, you need to supply an alist, with one element being (fullscreen . fullboth) like that:
emacsclient -c -F "((fullscreen . fullboth))"
emacsclient provides the --eval (-e for short) command line option for executing arbitrary Emacs Lisp code, so you can visit a file and call suspend-frame from the command line like so:
emacsclient -a "" -c --eval "(progn (find-file \"/tmp/my-file\") (suspend-frame))"
You could put this in a script, e.g:
#!/bin/bash
emacsclient -a "" -c --eval "(progn (find-file \"$1\") (suspend-frame))"

lgrep and rgrep in Emacs

I am having problems with the greps in Emacs.
a) grep doesnt seem to understand the .[ch] for searching .c and .h files. This is a default option provided by Emacs with the lgrep command. The example is searching for the word "global" in .c/.h files.
grep -i -nH "global" *.[ch]
grep: *.[ch]: No such file or directory
Grep exited abnormally with code 2 at Mon Feb 16 19:34:36
Is this format not valid?
b) Using rgrep I get the following error:
find . "(" -path "*/CVS" -o -path "*/.svn" -o -path "*/{arch}" -o -path "*/.hg" -o -path "*/_darcs" -o -path "*/.git" -o -path "*/.bzr" ")" -prune -o -type f "(" -iname "*.[ch]" ")" -print0 | xargs -0 -e grep -i -nH "global"
FIND: Wrong parameter format
Grep finished (matches found) at Mon Feb 16 19:37:10
I am using Emacs 22.3.1 on Windows XP with the GNU W32 Utils (grep, find, xargs etc.). Grep v2.5.3 and find v4.2.20.
What am I missing?
UPDATE:
Too bad one can't accept multiple answers...since the solution to my problems are spread out.
grep -i -nH "global" *.c *.h
This solves the first problem. Thanks luapyad!
(setq find-program "c:\\path\\to\\gnuw32\\find.exe")
emacs was indeed using the Windows find.exe. Forcing the gnu32 find fixed the second problem. Thanks scottfrazer.
However, I still like ack best.
I found out that using:
(setq find-program "\"C:/path/to/GnuWin32/bin/find.exe\"")
(setq grep-program "\"C:/path/to/GnuWin32/bin/grep.exe\"")
Works better in windows, since you could have a space laying around the path and will screw up eventually.
Notice I used the two programs in my .emacs file.
Hope it's of some help to some other programmer in need ;)
Well, there is always Ack and Ack.el
For a) it looks like there are simply no .c or .h files in the current directory.
For b) Windows is trying to use its own find instead of the one from the GNU W32 Utils. Try:
(setq find-program "c:\\path\\to\\gnuw32\\find.exe")
Adam Rosenfield comment is worth expanding into an answer:
grep -r --include=\*.[ch] --exclude=\*{CVS,.svn,arch} -i -nH
To make the example given in this question work, use this:
grep -i -nH --include=\*.[ch] "global" *
It is also helpful to set the variable grep-command providing defaults to M-x grep:
(setq grep-command "grep -i -nH --include=\*.[ch] ")
Also here are some other useful command line parameters to grep:
-n print the line number
-s suppress error messages
-r recursive
I think the general problem is the windows cmd "shell" behaves very differently to a unix shell in respect to filename expansion regexps and wildcards.
To answer your (a) above try using:
grep -i -nH "global" *.c *.h
(You will still get an "invalid argument" if no *.c's or *.h's exist).
Or you can use command line option --include=\*.[ch] to make windows grep do "proper" filename pattern matching (see grep --help for other options)
I usually just use M-x grep and alter the command line args when prompted if I need to. But I just tried running M-x lgrep and got the same thing as you. It simply means that no files match *.[ch] in the current directory. You can customize the default options to include -r and search recursively through child directories as well:
M-x customize-group RET grep RET
Search for lgrep in that buffer to find/edit the Grep Template.
As far as M-x rgrep goes, I suspect it has something to do with the Windows version of find not liking the default options. That command works fine for me on Linux. Search for rgrep in that same customize buffer and tweak those options until the Windows find is happy.
Sorry I can't be more help with the Windows options, but I'm not familiar with them.