Saturday, March 5

yo dawg

You can use backticks on the Vim command line to interpolate the output of a shell command into the command (just like in Bash). For example, I just did this to edit a script I use for taking screenshots:

:e `which grab-sel`

As you know, Bob, which(1) gives you the the absolute path to a command. In this case, grab-sel is just a Bash script in /home/brennen/bin/.

This comes in handy with pmwhich, a script I wrote to spit out the absolute path of the version of a Perl module your user would see when doing a use Module:

:e `pmwhich Text::Markdown::Discount`

Looking at it again for the first time in ages, I suppose that script could be a little risky, since it does use the module in question, which could mean all kinds of random code gets executed. I suppose this is a risk I’m willing to take with a janky one-off utility, insofar as I’m probably already running the code anyway by the time I need to use it. Nevertheless, beware that it could get you owned by someone who already has the privileges to drop a malicious Perl module somewhere on your system. (And probably, because everything is hard, in other ways I’m not giving due consideration.)

tags: topics/perl, topics/vim

p1k3 / 2016 / 3 / 5