Tag Archives: change

x_x: The Dead Guy CLI

With barely a week left for this site, I’m beginning to trim away programs that I just probably won’t get to, by virtue of time or technical dilemmas. I’m also making a conscious effort to pick out titles that amuse me in one form or another, so I finish with happy memories. šŸ˜›

x_x, which I mentally refer to as “the Dead Guy CLI,” because the home page uses that as a subtitle, is a rather nifty tool that I’m surprised I haven’t seen covered elsewhere. Using a bland, dull, boring Excel spreadsheet borrowed from a corner of the Interweb, Dead Guy CLI transmogrifies it into this:

2015-04-21-6m47421-x_x

Well isn’t that clever.

Dead Guy CLI gives you a small measure of control over your output, by allowing you to specify a header row or allow for special encoding. It also works with CSV files, so you’re not strapped trying to convert back and forth to Excel, just to fiddle with x_x.

Aside from that though, Dead Guy CLI seems very simple. Of course, your spreadsheet may need some management if you expect it to fit into a certain dimension, but I am confident that as a skilled and capable member of the information age, you won’t throw a wobbly over a pear-shaped spreadsheet.

Keep x_x in mind when you’re thinking about things like csv2xls or xlhtml, since it may save you a step or prevent you from relying on graphical tools just to extract data from a spreadsheet. And of course, if you’re working with csv files, x_x could supplement what tabview or other tools can do.

For my own recordkeeping, Dead Guy CLI gets points for doing something obvious that I don’t recall seeing elsewhere. And also for the snarky name. I’m a fan of snarky names. šŸ˜ˆ

peat: Pete and Repeat are sitting on a fence. …

Here’s a simple python tool that jumps into action when a file changes: peat.

2015-02-25-6m47421-peat

peat is built to execute a command of your choosing, and requires only a list of files to watch as input. As you can see above, probably its most basic use is just to send a message to the screen to announce a change.

But it seems capable of executing almost anything as its target, so you could set it to clean up files, compile a code snippet and run it, or … something completely different.

The syntax to get peat running can be a small challenge; by default peat wants a list separated by whitespace. Check the flags if you want to feed it a list separated by newlines or blank spaces.

I should also mention that in Arch, peat wouldn’t run without calling specifically for python2. On the other hand, it seemed to run without any oddball dependencies or bizarre python libraries, so it may be that it will run well on a vanilla system with no added weight.

I feel like I should mention the long list of file event watchers that are available, so it may be that using python as the basis for a file watcher is still too cumbersome.

And given that their list of features is as wide and long as the list itself, the choice becomes a little more academic. peat is worth investigating if you are comfortable with python and if its advanced handling doesn’t intimidate you. But remember there are many others in the running.

commacd: Just so long as you know where you’re going

The home page for commacd insists that it is not a fast directory switcher, and so I’ll refrain from calling it that. It does make switching directories a lot faster though.

But I can see where the difference lies. Things like z or j or j2 or autojump or fasd all tried to apply their own algorithms to switching patterns. commacd, on the other hand, trusts you to know where you are and where you want to go, and then takes you there.

commacd, as you have inferred, ties the cd command to the comma sign. In that sense it works exactly the same.

kmandla@6m47421: ~$ , downloads/
/home/kmandla/downloads

kmandla@6m47421: ~/downloads$

But if I have a nested directory and I know where I want to go, commacd suddenly makes it much easier.

kmandla@6m47421: ~$ , /u/s/j
/usr/share/jack-audio-connection-kit

kmandla@6m47421: /usr/share/jack-audio-connection-kit$

On my system, the only path that has the initials u then s then j is /usr/share/jack-audio-connection-kit, and commacd wisely expands my request to match it, and moves me there.

If there’s any doubt, commacd asks for permission.

kmandla@6m47421: ~$ , /u/s/e
0	/usr/share/emacs/
1	/usr/share/enchant/
2	/usr/share/et/
: 2
/usr/share/et

kmandla@6m47421: /usr/share/et$

A double comma works in reverse, but in the same way as well.

kmandla@6m47421: /usr/share/et$ ,, s
/usr/share

kmandla@6m47421: /usr/share$

Since “share” is in my path and it starts with an s, commacd moved me there. If there is more than one part of my path that starts with that letter, I get moved to the uppermost folder.

kmandla@6m47421: /lib/kernel$ cd /usr/lib/modules/3.16.4-1-ARCH/kernel/net/llc/

kmandla@6m47421: .../3.16.4-1-ARCH/kernel/net/llc$ ,, l
/usr/lib

kmandla@6m47421: /usr/lib$ 

Triple commas are wilder, allowing you to jump anywhere within your tree, not just your path. For example. …

kmandla@6m47421: .../3.16.4-1-ARCH/kernel/net/llc$ ,,, sound
/usr/lib/modules/3.16.4-1-ARCH/kernel/sound

kmandla@6m47421: .../modules/3.16.4-1-ARCH/kernel/sound$ 

And that might be the best feature of commacd: jumping well beyond your $PWD to a folder that’s only tangential to where you are at a particular moment.

No more backtracking to a common branch and then tab-completing down to the folder you want. With a little guidance and the reassurance that you know where you are and where you want to go, commacd will just take you there.

There’s no real downside to commacd, except perhaps that you need to have an idea of where you’re going. If you’re just exploring the bowels of /usr/src or looking for an errant file, it won’t help you much to have that kind of flexibility in changing directories. You might be better with the traditional cd command.

commacd “installs” by sourcing with your .bashrc or .bash_profile, so there’s no compiling and no need for a second program. It keeps no logs, has no daemons and doesn’t care if you like sysvinit or systemd. šŸ˜‰ It’s wonderfully transparent and so light you won’t even know it’s there.

I like this one a lot, and it’s definitely worth trying out … just don’t call it a fast directory switcher. šŸ˜‰

html2ps: You thought it wasn’t possible

I made a big deal the other day about converting csv files to Excel files, and from there possibly even generating HTML files as a result. Here’s one that will reverse directions on you again, converting an HTML page into PostScript. And of course, it’s called html2ps.

2014-08-12-6m47421-html2ps-gsx

Nothing much to show, of course, but the end result is undeniable. And of course it’s only one step from there to …

2014-08-12-6m47421-html2ps-acroread

Acrobat Reader?! šŸ˜Æ Yuck! šŸ˜”

Sorry, I do that just because I know I’ll get an e-mail from a certain reader, reminding me that ‘Reader is evil, and there are dozens of free alternatives. It amuses me.

The point of this little soliloquy is to mention that you can dump HTML pages into PostScript files, and maintain most of the information, if not all the style. html2ps does it fairly effortlessly, and fairly quietly. Meaning your csv files can now be converted to Excel, then to HTML, and from there to PostScript.

And of course, from PostScript it’s just a quick hop to PDF format, or whatever your heart desires. Why do that? Well … because you can! :mrgreen:

As a console application, html2ps doesn’t rank very high, since it has little offer in a way of interaction except through option flags and error messages. I don’t hold any ill-will for that, but I will repeat my preference for applications that use space and color and some sort of interface.

I guess programs are like people. Some don’t care to say too much, while others will take up as much as you’ll give them. šŸ˜‰

csv2xls: Back to the harmless and mundane

After yesterday’s foray into the dark and sinister worlds of password cracking and torrent searching šŸ™„ , today we’ll play the innocent and take a glance at csv2xls.

2014-08-09-6m47421-csv2xls-01 2014-08-09-l3-b7175-csv2xls-02

What could be more upright and resepectable than converting a plain old csv-formatted address list into an Excel spreadsheet? And I mean that with all seriousness. šŸ˜

As you can see above, csv2xls did a precise job of converting my database into a spreadsheet, accessible by LibreOffice and likely Excel too … but I don’t own a copy of that, so I can’t be 100 percent sure. šŸ˜‰

I’m tempted to stop there and say, “Yup, it works. Let’s move on.” But I see a couple of options in the man page that might be worth pursuing.

For one thing, my spreadsheet was only 100 names long. That’s no monster, and I doubt that csv2xls worked very hard to convert it. By default csv2xls will dump one csv file into one xls file, but the -l option will break it off after a certain number of lines. Successive entries are put into numbered files, ad infinitum, ad astra.

I can see the usefulness in that, but I can’t actually see a case where I personally would need it. Unless I churn out a 1000-line csv file and break it apart by hundreds, just to amuse you. O_o

One other curious and related note: If your csv file has a header line, csv2xls will keep that header across line-split files if you use the -H flag. So you needn’t worry that your grade sheet or customer invoice will lose its header row across files.

And I suppose I should mention that the default delimiter for csv2xls is … a semicolon. šŸ˜• Remember to use the -d flag if your comma-separated values are actually (gasp!) separated with commas. šŸ™„

I’ll leave it at that. csv2xls does a good job, I encountered no errors, and it has enough options to make it useful beyond the obvious. If only it didn’t talk so much. … šŸ˜‰

P.S.: If you’re looking to go the opposite direction, check here or here. Hey, now you can convert your csv files to HTML. … šŸ˜Æ šŸ˜Ž

z and z: A tale of two z’s

Remember my little rant from a few weeks ago, the one about single-character application names? If you don’t it’s just as well. I usually regret my rants. That one was no exception.

The point comes through though, since I have two z’s to report — this one and this one.

2014-07-05-6m47421-z-01 2014-07-05-6m47421-z-02

The z on the left is an intuitive compression-decompression tool. By all rights it should sense whether a file should be compressed or decompressed, and come up with the right results. If you remember atool or dtrx or unp, think of it as one of those, with enough smarts to do the opposite, if need be.

I did run into a few problems with z — the z on the left, that is. Compression seemed to sputter in the Arch version, while it looked for something called compress at /usr/bin/. It wasn’t finding it, and so half of what it could do, it couldn’t.

The z on the right is another fast directory switching tool. It’s by the same author as j and j2, and seems to follow the same pattern.

If you place the z.sh script somewhere in your $PATH, and change the $_Z_CMD variable to just “z”, then you should start building a database of recently visited directories. From there you can jump straight to a particular one by prefixing it — or part of it — with just “z”.

In theory, of course, and there is more to it than just that. It works acceptably well, although personally I’m not much of a fan of fast-directory-switcher-gizmos, and so a lot of it is probably lost on me.

So there are the two z’s, and I’d like to just take one last second to remind everyone out there who is working on building The Next Great Killer App, The Program That Will Change Life As We Know It, The Application That Consumed The Entire Universe In One Slobbery Gulp, to please — please — think rationally for just the briefest moment, and give your program a name that’s longer than just one stupid letter. šŸ˜”

wendy: Under wendy’s watchful eye

I know we just saw watchfile.sh the other day, but I can’t account for the whims of alphabetical order.

2014-06-22-6m47421-wendy

tsar11 sent a link three or four months ago to a reddit post about wendy, which monitors files (or directories, for that matter) for changes, and then executes a command as a response.

As you see there, it could be something as simple as a message on screen, or it could be as complex as an order to recompile a program.

wendy can discriminate between file modification, file creation and file deletion, which is handy. If I had told it to spawn a warning only when a file was created, that gif probably would have been shorter. šŸ™„

wendy also knows enough to keep quiet when told, or to poll at distinct intervals. All nice touches.

I don’t have any complaints about wendy. It seems to handle more complex cases than watchfile.sh, works better than fsniper did (for me), and seems to work at least as well as entr.

wendy’s home page shows edits within the past few months, so if you find there’s a feature it lacks (for one, I’d like to see the option to discriminate actions based on either modification, deletion or creation), the author is probably listening.

In the mean time, your homework will be to daisy-chain all four of these together and see what kind of ruckus erupts as a result. šŸ˜ˆ

watchfile.sh: Perhaps the best thus far

It’s been a while since fsniper, and even longer since entr. Here’s watchfile.sh, which also watches files for changes, and then executes a command.

It’s a little difficult to show, so you might have to use your imagination. There are several ways to cue it; in my test runs, this:

./watchfile.sh test.txt cat test.txt

was enough to refresh the screen with my edits, when I saved test.txt back to disk from another terminal window.

That’s not the only way to use watchfile.sh, and the help flags will give you ideas on other methods. For example, you can monitor the output of a second command, and when that changes, execute a third command.

I like watchfile.sh a lot better than either fsniper or entr. fsniper was a bit more complex, and in the end, didn’t quite work. entr, on the other hand, worked fine, but expected to receive updates through a pipe, which is a tiny bit clunky.

But watchfile.sh is very straightforward and very flexible, and does what it promises. And I like that the task is reduced to an easily dissected script, rather than complex code.

So my advice, if you have to pick one of the three, is to go with watchfile.sh. Unless of course, you have another method you prefer. šŸ˜‰

regionset: This I can attest to

It’s funny to think, but I had my first experiences with regionset about six years ago. And believe it or not, I’m still a little bitter.

Not because of regionset, but because of the entire swirling morass around DVD region codes.

kmandla@lv-r1fz6: ~$ regionset -h
regionset version 0.2 -- reads/sets region code on DVD drives
Usage: regionset [device]
       where default device is /dev/dvd

For someone like me, who sometimes lives in a country beyond their “home” region, and with a small collection of DVDs from several regions, it’s absolutely asinine to prevent cross-region use.

And considering it’s tripped me up more than once, and friends to an even greater degree, it’s equally asinine to expect anyone to actually buy the same disc again just to watch a film on a machine of a different region. Or worse, buy a new player to watch specific regions.

All of which is really just a syndrome of the larger industry myopia that has been around since the late 1980s, at least. It took forever for the music industry to realize the potential in online music sales, and now it’s completely eclipsed the traditional album model.

How long before the movie industry wakes up? Like I could care. Truth be told, there’s no reason for me, as a multi-region customer, to bother buying their product any longer. Six years ago, I was better off downloading a pirated copy than dumping more money into a corrupted sales model. I daresay that hasn’t changed.

But I wander from the purpose of this post. If, in this day and age, you find you can’t use a particular DVD, and you’re fairly certain it’s because of region settings, I can attest to regionset as a potential solution.

If I recall correctly, you only get to change the region five times before the drive is fixed upon the last setting. After that, it won’t let you change it again.

After that, if you’re still not sure what region you want, then I think you really should move away from DVDs. šŸ˜•

popd and pushd: The original fast directory switching

I’ve run across more than one fast directory switcher in the past 15 months, most notably fasd and j and j2. What you might not know is that the bash shell comes with a primitive fast directory switcher … of a sort.

popd and pushd are built-in commands in bash (and zsh, I believe) that work with a manageable stack of directories that you can bounce between. And since it’s been a while since we actually dug in to one of these tools, it’s probably a good time for an in-depth look at pushd and popd.

Compared with fasd et al., pushd/popd may take a little getting used to. Here’s a simple example:

kmandla@lv-r1fz6: ~$ pushd /usr/share/
/usr/share ~

kmandla@lv-r1fz6: /usr/share$

When I use pushd and a directory, I bounce straight to that location, and the path is put into the directory stack. pushd by itself effectively swaps entry Nos. 0 and 1. Either way, pushd‘s output is the current directory stack, from left to right, zero on up.

I can check what’s in the stack and the order with dirs (I like dirs -v, personally).

kmandla@lv-r1fz6: /usr/share$ dirs -v
 0  /usr/share
 1  ~

kmandla@lv-r1fz6: /usr/share$

The stack works LIFO, meaning last-in-first-out: The last (or newest) item added to the the stack is the first one used.

Zero (or the leftmost entry) is your current directory; you can cd to a new location without interfering with the stack. I can also add another destination if I like.

kmandla@lv-r1fz6: /usr/share$ pushd /lib/kernel
/lib/kernel /usr/share ~

kmandla@lv-r1fz6: /lib/kernel$

Now I have three in the stack. If I want to bounce back to a previous directory, I use popd to “pop” out the zero entry and jump to No. 1 in the stack.

kmandla@lv-r1fz6: /lib/kernel$ popd
/usr/share ~

kmandla@lv-r1fz6: /usr/share$

Note that I jumped back to /usr/share, and that /lib/kernel was removed from the list. The whole stack shuffles up one space.

If I had a lot of directories in the stack, I could successively popd through them until I arrived back where I began, and the stack would be empty.

kmandla@lv-r1fz6: /home$ dirs -v
 0  /home
 1  /boot
 2  /lib/kernel
 3  /usr/share
 4  ~

kmandla@lv-r1fz6: /home$ popd
/boot /lib/kernel /usr/share ~

kmandla@lv-r1fz6: /boot$ popd
/lib/kernel /usr/share ~

kmandla@lv-r1fz6: /lib/kernel$ popd
/usr/share ~

kmandla@lv-r1fz6: /usr/share$ popd
~

kmandla@lv-r1fz6: ~$

It’s not ideal if you have a series of directories you want to keep, and it’s hard to imagine how it works if you’re trying to visualize it like “bookmarks.” It’s not really like that at all.

In fact, it might be easier to think of it like a stack of plates: You can “push” a plate onto the top of the stack, and then “pop” out whatever is on top.

And aside from pushing and popping, there are some rudimentary management tricks. You can use dirs -c to clear the stack, -l lists them longhand and -p prints them in plain form. Using a plus or minus displays the number of entries from the left or right in the stack, respectively. Remember again that the leftmost is No. 0, and they increment as you move to the right.

popd and pushd work differently with the plus or minus; popd “pops” out the Nth entry from the left with minus, and from the right with a plus. pushd rotates the stack a certain number of steps to the left or right, with plus or minus.

kmandla@lv-r1fz6: /home$ dirs -v
 0  /home
 1  /boot
 2  /lib/kernel
 3  /usr/share
 4  ~

kmandla@lv-r1fz6: /home$ pushd +1
/boot /lib/kernel /usr/share ~ /home

kmandla@lv-r1fz6: /boot$ pushd +2
/usr/share ~ /home /boot /lib/kernel

kmandla@lv-r1fz6: /usr/share$ pushd -2
/home /boot /lib/kernel /usr/share ~

kmandla@lv-r1fz6: /home$ pushd -1
/usr/share ~ /home /boot /lib/kernel

kmandla@lv-r1fz6: /usr/share$ dirs -v
 0  /usr/share
 1  ~
 2  /home
 3  /boot
 4  /lib/kernel

kmandla@lv-r1fz6: /usr/share$

Note that each time, the list was shuffled and the current working directory changed.

Final tip: If it annoys you that popd always dumps an entry off your stack, start relying on pushd +N, which will just cycle you through the list. And remember: pushd by itself just swaps Nos. 0 and 1 in the stack, effectively bouncing you between two directories. šŸ˜Ž Aha! You can thank me later. šŸ˜‰

“Modern” fast directory switchers might have more conventional features, but for sheer lightness and convenience, pushd, popd and dirs are reliable and useful. Not bad, for software that dates back to 1976. šŸ˜Æ

If you want more guidance, try the bash reference manual, or enter help with any of pushd, popd or dirs. The learning curve is not too steep, but it may take some getting used to.

Enjoy. šŸ˜‰