How to customize dired-compress-files-alist? - emacs

The original value of dired-compress-files-alist is:
(("\\.tar\\.gz\\'" . "tar -cf - %i | gzip -c9 > %o") ("\\.tar\\.bz2\\'" . "tar -cf - %i | bzip2 -c9 > %o") ("\\.tar\\.xz\\'" . "tar -cf - %i | xz -c9 > %o") ("\\.tar\\.zst\\'" . "tar -cf - %i | zstd -19 -o %o") ("\\.zip\\'" . "zip %o -r --filesync %i"))
I'd like to add command for .tgz files, so I add a line in .emacs:
(add-hook 'dired-mode
'(lambda ()
(setq dired-compress-files-alist
(cons '("\\.tgz\\'" . "tar -cf - %i | gzip -c9 > %o") dired-compress-files-alist))))
When Emacs starts, it reports error variable dired-compress-files-alist is not found. I found only when I run command `dired-do-compress-to', this variable will appear. So how to set this variable?

Just require standard library dired-aux in your init file at the outset (at least before you use Dired). That library defines variable dired-compress-files-alist.
(require 'dired-aux)
(Oh, and don't quote lambdas: just use (lambda...), not '(lambda...).)
(You can also use add-to-list or push instead of setq with cons etc., but that's just a question of style.)

Related

sh Script with copy and removing a part from filename

So i use a script that copy's specific files to specific folders based on there filenames. I would like to extend the script so that after the copy progress a part from the filename is removed. Here is an example The filename looks likes this Image_000058_19_12_2019_1920x1080.jpg and i like to remove the resolution (_1920x1080) part from it. Is there a way to add it to my Script (see below) Thanks to #fedxc for the script.
cd "$HOME/Downloads"
# for filename in *; do
find . -type f | while IFS= read filename; do # Look for files in all ~/Download sub-dirs
case "${filename,,*}" in # this syntax emits the value in lowercase: ${var,,*} (bash version 4)
*.part) : ;; # Excludes *.part files from being moved
move.sh) : ;;
# *test*) mv "$filename" "$HOME/TVshows/Glee/" ;; # Using move there is no need to {&& rm "$filename"}
*test*) scp "$filename" "imac#imac.local:/users/imac/Desktop/" && rm "$filename" ;;
*american*dad*) scp "$filename" "imac#imac.local:/users/imac/Movies/Series/American\ Dad/" && rm "$filename" ;;
*) echo "Don't know where to put $filename" ;;
esac
done```
I use variable operation for bash. Example:
export filename='Image_000058_19_12_2019_1920x1080.jpg' <----Setting name of filename
echo ${filename/_1920x1080/} <--Operation with bash variable.
Image_000058_19_12_2019.jpg <--Result of echo
Consult this page for more: Bash Guide

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}'

Quickly finding project files using Emacs EDE

I've recently started using EDE (via CEDET via ECB) in an attempt to get Emacs set up as a reasonable IDE for development on a largish C/C++/Python project.
Something that was a bit fiddly to get set up (as I'm an Emacs and Lisp novice) was rapid file finding. The solution I currently have is to set up a raw/blank project (one EDE doesn't need to know how to manage makefiles or builds for) like so in my .emacs file:
;; Enable EDE mode
(global-ede-mode 1)
;; EDE knows nothing of my project type, so use CSCope to inform it of the project
;; and its files
(setq ede-locate-setup-options
'(ede-locate-cscope
ede-locate-base))
;; This is probably a dubious shortcut allocation,
;; but it's what I'm using at the mo.
(global-set-key (kbd "C-f") 'ede-find-file)
;; Set up the project for EDE
(ede-cpp-root-project "LargeApp" :file "/workspace/me/LargeApp/SConstruct")
M-x ede-find-file used to not work at all, because EDE didn't know anything of the files in the project directory and sub-directories. Setting up the files in an EDE project would have taken ages (10000+ files), but luckily EDE understands CSCope output, so it was a matter of doing this in my project root directory using a little bash script (based on information linked from the main CScope project page):
#! /usr/bin/env bash
cd /workspace/me/LargeApp
find /workspace/me/LargeApp \
-type d -name '.git*' -prune -o \
-type d -name '.svn*' -prune -o \
-type d -name 'build' -prune -o \
-type d -name 'bin' -prune -o \
-type d -name 'lib' -prune -o \
-name '*.h' -print -o \
-name '*.hpp' -print -o \
-name '*.c' -print -o \
-name '*.cpp' -print -o \
-name '*.cc' -print -o \
-name '*.py' -print -o \
-name '*.lua' -print -o \
-name '*.xml' -print >./cscope.files
cscope -b -q -k
EDE then picks up the cscope.out in the project root folder, and kazam!, M-x ede-find-file works.
However, there are one major niggle I'm struggling to sort out:
I need to type the full, case sensitive file name.
This is less than ideal on a project this size, because you often only remember part of the filename, and not necessarily the case. It would be great if I could get it set up so I only have to type a case-insensitive substring of the filename, and then get an IDO buffer or similar I can tab through until I get the file I'm looking for.
I've resorted to using M-x cscope-find-this-file instead. It forces me to choose from likely filepath options in a buffer, but it does a reasonable job of getting me the right file quickly and isn't hampered by case-sensitivity. If I can get this hooked up into IDO, then it should do exactly what I want.
For Python, CScope/xcscope.el is good, but not perfect for navigating Python tags. So I've started using Elpy. M-x elpy-goto-definition works very well for Python files, and for the rest (C/C++) I'm using M-x cscope-find-this-symbol.

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*")))

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

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