UP | HOME

Linux Hints
Solutions to some problems in my open source software work flow

Table of Contents

Org-Mode Tips

Composing html mail in mu4e

Mu4e is a very powerful program for handling mail. It is easy to set up and writing email in plain text is straightforward. So far so good. But what if you want to compose emails that render well in gmail or Outlook? There's alway a fear that those reading your short truncated mails on their corporate mail clients may feel a little disconcerted after reading your unwashed words. Have no fear, there is a simple solution at hand.

Enter Org-mime

Org-mime is a simple to use library that will convert your badly dressed journeyman text into a corporate friendly html suit. It has a number of usefull functions.

For writing a simple email in Mu4e then do the following, First start your email package with C-x-m.

  1. After having written your mail the run org-mime-htmlize to convert the text to html that looks "normal" to the everyday world.

This covers about 90% of my mails. For more elaberate formatting there are a number of org-mime functions that are listed, but I could not get any of them to work. However, the following simple hack works perfectly

  1. Start a new org file to compose your mail
  2. To send the full org file as html then first select all the org file with C-x-h
  3. Then run org-mime-htmlize
  4. Then copy the new text
  5. Paste it into your message compose frame and send

If you want to have images within your text you need to check you have something like this in the completed org-file.

#+CAPTION:The Original Dido
#+ATTR_HTML: :width 300
file link

This is a working hack until org-mime and friends work properly. The only annoying thing is that you have to close the new htmlised org file without saving to preserve its original formating.

Screenshot_2020-10-24_17-50-36.png

Figure 1: Well formated email using the above hack

Org-Publish

Emacs Tips

Streamline Dired's Appearance

Dired is a great file manager but it can look a little unwieldy . If you have just installed a fantastic new theme for your Emacs and think that Dired looks like an unwashed monster bathing in a pristine forrest stream, then tip is for you. To make Dired just list the Directory names and omit the file permissions insert the following code. To get a preview before you do press (. This only works in the current directory. If you want that look permanently this is what you need.

(add-hook 'dired-mode-hook
      (lambda ()
	(dired-hide-details-mode)
	(dired-sort-toggle-or-edit)))

Tramp needs two // to work outside your Home directory.

I wanted to use one of the many org-publish templates available (for example this one ) in order to publish my website directly from Emacs to my hosting site. Emacs uses an integrated package called Tramp to connect to the Web and move files around remotely. Although that's actually a very limited description of what Tramp can do, for my purposes that's all I needed. I tried for far too long to get Tramp to work by searching into the far corners of the Emacs world but I failed to move a single file from my computer to the server. What kept happening was that I got the message that I had created a file named something like "ssh:user@server:/" and that was it. I was never asked for a password and there were no hopeful sounding messages about "connecting to," or "server handshake".Tramp was not making any connections outside my PC. I could use ssh within an Emacs shell but not get Tramp to connect. I read that it could be something to do with my prompt. It wasn't. An unfriendly server? No, not that either. In the end I resigned myself to failure and assumed that Tramp was simply not working on my system and gave up trying to use it. Then I read somewhere that in order to use Tramp outside your Home directory you need to write two slashes // before the server address. So it should look something like this:

//ssh:username@ssh.username: (dont forget the last colon)

This means that in your innit.el file where the org-publish section is, the publishing directory should be called something similar to this:

:publishing-directory "//ssh:user@host:~/html/notebook/"

Notice the extra slash at the beginning? That's where the magic is.

And that was it. I am a little embarrassed about how long it took me to discover I needed that extra slash but I suppose I learned quite a lot about Tramp attempting to find out. Once I used that extra / Tramp did it's stuff and everything worked as expected. I am now a big Tramp fan and for editing files remotely it is offers a lot more power than my previous remote editor of choice, Midnight Commander.

In the Org documentation it's hinted that Tramp is slow and that it may be easier to use rsync to move the files up to your server. In the end this is what I have ended up doing. Rsync is very fast and to make it easy to use I put a shortcut in my bash.rc to get the job done. Problem solved.

Using Dired as a Remote File Manager

For many years I used Midnight Commander as my remote file manager. Carrying out basic file operations is very straight forward with MC. Copy , rename, delete and move all work as expected. The two panel manager makes it particularly easy to view both a host file system and a remote. It's then just a question of putting in the simple commands to carry out the basic operations. You can also use drop down menus. MC is the best non-Emacs file manager there is, but it lacks the editing functions of Emacs for working inside remote files.

If you want to utilise the power of Emacs to work on a remote system and try and mimic MC's two panel appearance then here are some suggestions on how to do that:

Connecting

Connect to your remote server by using C-x C-f and then putting in your server address . On my system I put in the following

//ssh:username@ssh.one.com:

Navigation

Once Tramp connects a Dired buffer appears and you can navigate using Dired's commands. Working on files located on the remote server is just the same as working on files on the host. It feels like the files are on your hard disk. Because the interface is so familiar I think it's also more productive to edit remote files this way.

Two Panel effect

It's very easy to mimic MC's two panel view by opening another window in Emacs with C-x-3 and then moving between the pseudo-panels with C-x-o or as a last resort:clicking. Opening a file on your host works as expected. C x C-f asks for a file name and you will have to input the full path with something like

/home/david/filename

Moving files

I found moving files from the remote to host to be very easy. Mark your files in Dired with the "m" option and then press C for copy. You will be asked for the location and putting in the full path is enough.

It was a little more complicated with moving files from the host to the remote. This was due entirely to the use or otherwise of extra / at the beginning and end of the path. In my case I needed only one slash / at the beginning and one at the end. So after selecting the file with "m" and bringing up the copy params in the mini-buffer with "C" , this path worked and the file was copied over.

/ssh:username@ssh.one.com:/www/directory/

Now I can move files between servers and use the power of Emacs for editing, all from within Emacs itself.

Set up a password free login over SSH between machine A and server B

If you don't already have a public key then you need to make one. If you do then you can think off it as a type of digital id that allows servers you are allowed access to accept your login credentials on trust. If you have such a key use the ssh-copy command to the sever you want access to. To generate a public key on machine A put in the following command:

ssh-keygen -t rsa  to create a public key

Then you should get messages something like this-

Generating public/private rsa key pair.
Enter file in which to save the key (/home/david/.ssh/id_rsa): [Press enter key]
Created directory '/home/david/.ssh'.
Enter passphrase (empty for no passphrase): [Press enter key or create a password to protect the key]
Enter same passphrase again: [Press enter key]
Your identification has been saved in /home/david/.ssh/id_rsa.
Your public key has been saved in /home/david/.ssh/id_rsa.pub.
The key fingerprint is:

So far so good. Time to copy the key to server B

ssh-copy-id -i ~/.ssh/id_rsa.pub user@server

The machine should then politely ask you to login again to server B. Do it , and enjoy your password free connection.

Get the weather for your area from the command line

I have used a number of command line weather services and programs over the years but this service is by far the best. Its really quite outstanding.

Its a simple command:

curl wttr.in/yourtownname

Which produces a beautifully presented 3 day forcast.

Screenshot-weather.png

Figure 2: My city has weather!

Adding a file or folder to your PATH

You have written a great script or downloaded a usefull program. You want to start it from the command line from any point in your directory structure. Duh! You forgot to put said program/script in your PATH. Here's a quick reminder what you need to do.

  • First make sure you can execute your script:
chmod 755  yourscript

You can list all folders in your PATH with

echo $PATH

Either add your script to one of these directories, most likely /bin, or make a new directory and add it to PATH with:

export PATH=$PATH:yourscriptdirectory

And thats it. Now you can start your script direct from the command line from anywhere on your

Author: balticman

Email: david@geffle.se

Created: 2022-02-14 Mon 15:00