Some Useful Bash Variables

In a computing world that often seems increasingly captured by the “point and click” mindset, it’s useful, now and then, to be reminded of the power and value of the command line. I’m not a “I do everything in the terminal from the command line” guy but I do often find that certain tasks are more easily accomplished that way.

Over at zwischenzugs, Ian Miell illustrates that power with his post, Seven Surprising Bash Variables. If you’ve been using Bash for a while, you’re probably familiar with some of them but there’s likely some on his list that you haven’t seen. I was surprised to learn about the REPLY variable and how it can make getting interactive responses in the shell easier. Take a look at his post for the details and some other useful Bash variables.

If you like that post you might also enjoy his post on Bash options, Eight Obscure Bash Options You Might Want to Know About. Both posts are definitely worth a few minutes of your time. Unless you’re permanently stuck in point and click mode.

Posted in General | Tagged | Leave a comment

Magit in Spacemacs

Jack of Some is back with another video in his Absolute Minimum Series. This time, he takes a look at using Magit from within Spacemacs. Like his last video on Refactoring in Spacemacs, this one is applicable for all Emacs users whether or not you worship in the Church of Spacemacs, There are a couple of Spacemacsisms but they’re mainly the keystrokes to invoke Magit status.

Most of the action takes place in Magit which looks and works the same regardless of the Emacs installation you’re using. Jack covers all the “everyday” things that you need to do with Magit.

He starts off explaining how navigate on the Magit status page and bring up diffs for the files that have been changed. He continues with a demonstration of committing changes including how to commit just some of the parts of a changed file. Once he’s got his changes committed, he’s ready to push them upstream but, of course, he doesn’t want to push to the Master branch so he shows how to create and push to another branch instead.

His next topic is pulling and merging. He creates a repository and local copy that have conflicting changes. He uses that to show how to resolve merge conflicts using ediff. I particularly liked his exposition of that process.

Finally, he looks at git blame and stashing. Those are really simple operations that some tutorials make heavy going of but Jack shows how they’re simple and straightforward.

The video is 8 minutes, 25 seconds so it’s easy to watch it on a coffee break. I recommend it to all Magit users.

Posted in General | Tagged | Leave a comment

Collaboration in ed(1)

As some of you know, I satisfy my retro-computing itch by occasionally firing up ed for a simple editing task. In truth, I do it mainly to stay current with ed against the day that I need it. That and the fact that it’s fun even if I wouldn’t want to use it as my main editor.

This week, the proprietor of Programming Praxis didn’t have time to come up with a real programming exercise so he shared what he described as an insane example of collaboration using ed. Actually, it’s not really “collaboration” but a way of sending some lines in one ed session to another. There is, of course, no built-in way of doing that in ed but the originator of the idea came up with an amusing solution.

I’ll let you go over to Programming Praxis to see how it’s done. Just to make things clear, the idea is to send lines 15–21 from session a) to session b) and have them inserted after line 13 in session b). If you’re familiar with Vi/Vim, you’ll have no trouble understanding what’s going on. Don’t worry about the -p in the ed invocations; that’s just to set the prompt to make it easier to follow what happens during the “collaboration.” None of this has any import at all, of course, but it is an amusing diversion on a lazy Sunday afternoon.

Posted in General | Tagged | Leave a comment

A Nice AWK One-liner

How would you solve this problem?

Given a file of text lines, remove duplicate lines keeping the original order.

The first thing that springs to mind is using

sort | uniq

or perhaps

sort -u

but these solutions fail to maintain the original order.

Lazarus Lazaridis has a very nice solution that accomplishes the task with an AWK one-liner. I wrote about the power of AWK one-liners a couple of weeks ago so this is a nice coda. Lazaridis’ solution leverages AWK’s associative arrays so a similar solution is available in many other languages. Try, though, to implement it in, say, Python. It’s straightforward but it’s definitely not a one-liner.

Lazaridis’ post explains his solution in detail so it’s worth reading even if you aren’t an AWK user. He also explains how you can solve the problem with sort, although not in a trivial way.

Notice how the AWK solution leverages the two powerful features of AWK that I discussed in my AWK post: the implicit main loop and associative arrays. It’s amazing how many problems can be trivially solved by using those two features.

Posted in General | Tagged | Leave a comment

An Emacs Journey

Someone tweeted a link to a 6-month-old post by Murat Demirbas, a computer scientist at SUNY Buffalo. The post, My Emacs Journey, describes Demirbas’ use of Emacs and his embracing of Org mode. He’s been using Emacs for over 20 years and says that he has reached the stage where his Emacs knowledge is mostly held in his muscle memory. He says that if you ask him what the key sequence for some command is, he can’t tell you until he types it and observes what he typed. I experience something similar: if you give me a key sequence and ask me what it does, I’ll have to stop and think and possibly won’t know even though I use it all the time without conscious effort. As Demirbas says, the knowledge is held in my muscle memory.

He writes at length about how Org mode changed his workflow. Like me, he uses it for writing, task management, and even to organize his thinking. I liked how he uses Org for his writing. It reminded me of a technique I’d forgotten about. When he’s writing a paper and defines a term, he turns it into a radio-target so that every time he uses it in the sequel, the new use gets turned into a link back to the definition. That’s a natural thing to do but I always forget about it.

I spent a long time reading his post because he had several interesting links to other posts or information. Take a look at his post to see what I mean.

Posted in General | Tagged , | Leave a comment

Adding Your YouTube Subscriptions to Elfeed

If you’ve been around Irreal for a while, you know that I’m a very happy user of elfeed for my RSS needs. It’s easy, fast, and, of course, I can read my feeds from within Emacs. Just the other day, I was wishing that there were some way of adding my YouTube subscriptions to elfeed. As things stand now, I have to check each of the channels everyday. Yes, I know that Google will send me a notification of new videos but I’ve stopped using Gmail for the obvious reasons and only check it once a month. I should probably just forward it to one of my active accounts.

Over at Codingquark, Dhavan Vaidya shows how to add those YouTube subscriptions to elfeed and download the videos. I briefly thought about doing this but I didn’t know that you could export your subscriptions from YouTube so I couldn’t figure out where to look for new videos. Vaidya has all that handled and it turns out to be very easy to set up.

All you need is youtube_dl and, of course, elfeed. Add a little bit of Elisp to your init.el, export your subscriptions from YouTube, and you’re set to go. I’m really happy about this; it’s one more function absorbed into Emacs.

Posted in General | Tagged | Leave a comment

Markdown in Org-mode

Org-mode seems to be gobbling up everything having to do with text generation. Here’s the latest example:

That’s pretty neat. Given that Org markup is superior to Markdown—sorry Markdown partisans, it is—it’s a bit hard to envision a non-contrived use case for the functionality but they surely exist. One example might be if you want to integrate some existing Markdown into an Org document. Doubtless folks with better imaginations can think of others.

It’s no wonder that Org envy is spreading to users of those other editors. There are already several ports to some of those editors as well as a standalone version. Of course, Org documents are plain text so you can trivially use any editor to write them but it’s Org’s integration with Emacs that provides the wonderful display, text wrangling capabilities, and, of course, (executable) Babel code blocks.

Posted in General | Tagged , | Leave a comment

A Development Environment

If you’re a software engineer, one of the most important aspects of your working life is your development environment. You’ve got to be comfortable with your editor, your debuggers, your OS, your desktop, and the other important pieces of your software stack.

Evgeny Budilovsky over at Meta-x86 has an interesting post describing his environment. His post focuses on the three main legs of that environment:

  1. His OS;
  2. His Desktop;
  3. His editor.

Budilovsky uses Nixos because he likes the way it lets him manage his configuration and software installation. Take a look at his post for more on that.

For his desktop, he uses Xmonad, which I’ve written about before. If you haven’t already, watch the demonstration video linked from that post to see how powerful Xmonad can be. Budilovsky says he likes it because it’s configurable with Haskell in a way that reminded him of Emacs.

Emacs is, of course, his editor. He likes the way it’s configurable and can be personalized. Between Emacs and Xmonad he can largely avoid using the mouse. Not everyone likes that idea, I suppose, but I consider it a real win.

If you’re living in the Linux world, be sure to take a look at Budilovsky’s post. His setup seems very nice and may appeal to you.

Posted in General | Tagged | Leave a comment

Refactoring in Spacemacs

Jack of Some is back with another video. This one is about using Spacemacs to refactor code. For someone who’s content with vanilla Emacs and has no plans to move to one of the other configurations, I’ve been writing a lot about Spacemacs lately. This is justified with today’s video because it taught me several things I didn’t know about iedit that apply no matter what flavor of Emacs you prefer.

Ever since abo-abo turned me on to it, I’ve been a heavy user of iedit. I almost always prefer it to query-replace or query-replace-regexp. It turns out, though, that it’s much more flexible than I imagined and Jack demonstrates that flexibility in his video. If you’re not a Spacemacs user, the keysequences are different, of course, but bringing up the doc-string will show you their vanilla Emacs counterparts.

As an example, when I was writing the post on Org gems, I decided to change ‘6’ to “six” in the text so I fired up iedit. Unfortunately, the ‘6’ in the list got changed too. It was easy to fix it up, of course, but I thought it was too bad there wasn’t a way of turning iedit off for some occurrences of the target symbol. After watching Jack’s video, I realized that there was a way of doing it and that it was all documented in the docstring.

If you’re an iedit user and are not aware of all of it’s functionality, be sure to watch the video and visit the documentation.

Posted in General | Tagged | Leave a comment

More Org Gems: Tables

Just after I published yesterday’s post on Org-mode Gems, I discovered that Cheong Yiufung has another post up with some more Org gems. This time he considers Org Table Gems. In this post he demonstrates three things about working with Org tables that you might not know:

  1. Operating on table regions.
  2. Converting a (semi-formatted) region to a table.
  3. Special markings to name rows, columns, and fields and to enable automatic recalculation.

As before, he has animations showing the gems in action. This time, however, he used mp4 instead of gif for the animation. That has certain advantages, I guess, but, for me at least, comes with a problem. I couldn’t figure out how to freeze the animation without having the video control bar cover the minibuffer. That’s a problem because I want to follow what he’s typing and sometimes it’s necessary to freeze the video to read a longer command.

That’s a small nit, of course, and Yiufung more than makes up for it with a little extra at the end. He shows how he used Dired to bulk convert his animations from webm format—which doesn’t work well with the Safari browser—to mp4. It’s a nice workflow and worth studying because the same ideas are portable to other bulk conversions or, really, any command line action on multiple files.

Posted in General | Tagged , | Leave a comment