Thu, 13 Jun 2013
Last we were discussing the structure and design of your own CLI-centric blog platform, we had some crude methods of starting and resuming posts before publishing.
Today, let’s explore a little more into setting up a bloging-friendly environment because we need to either make the experience of blogging easy or we’ll grow tired of the hassle and lose interest.
We can reasonably anticipate that we won’t want to beleaguered with repetitious typing of HTML bits. If we’re going to apply paragraph tags, hyperlinks, codeblocks, etc. with any frequency, that task is best to be simplified. Using Vim as our preferred editor, we will use Tim Pope’s brilliant plug-ins ‘surround’ and ‘repeat’, combined with abbreviations to take away the tedium.
The plug-ins just need dropped into your Vim plugin directory (~/.vim/plugin/
). The directory may not exist if you don’t have any plug-ins yet. That’s no problem, though. Let’s grab the plugins:
cd ~/.vim/
wget "http://www.vim.org/scripts/download_script.php?src_id=19287" -O surround.zip
wget "http://www.vim.org/scripts/download_script.php?src_id=19285" -O repeat.zip
Expand the archives into the appropriate directories:
unzip surround.zip
unzip repeat.zip
Ta-da! Your Vim is now configured to quickly wrap (surround) in any variety of markup. When working on a blog, you might use <p>
tags a lot by putting your cursor amid the paragraph and typing yss<p>
. The plug-in will wrap it with opening and closing paragraph tags. Move to your next paragraph and then press .
to repeat.
That out of the way, let’s take advantage of Vim’s abbreviations for some customization. In our .vimrc
file, we can define a few characters that Vim will expand according to their definition. For example, you might use:
ab <gclb> <code class="prettyprint lang-bsh linenums:1">
Then, any time you type <gclb>
and bress <enter>, you’ll get:
<code class="prettyprint lang-bsh linenums:1">
The next time that we take a look at blogitecture, we will focus on making the posts convenient to manage from our CLI.
Tags: abbreviations, blogitecture, repeat.vim, surround.vim, Vim
Permalink: 20130613.blogitechture.continued
Sun, 09 Jun 2013
In an effort to promote practical privacy measures, when I send people links to search engines, I choose ixquick. However, my personal settings submit my search terms via POST data rather than GET, meaning that the search terms aren’t in the URL.
Recently, I’ve found myself hand-crafting links for people and then I paste the link into a new tab, to make sure I didn’t fat-finger anything. Not a problem per se, but the technique leaves room for a bit more efficiency. So I’ve taken the ‘A Search Box on Your Website’ tool offered by ixquick and slightly modified the code it offers, to use GET variables, in a new tab where I can then copy the URL and provide the link to others.
You can test, or use, it here — I may add it (or a variant that just provides you the link) to the navigation bar above. First, though, I’m going to mention the need to the outstanding minds at ixquick because it would make a LOT more sense on their page than on mine.
Tags: ixquick, search
Permalink: 20130609.ixquick.search
Thu, 06 Jun 2013
Recently, an author I admire and time-honored spinner of the Interwebs, Tony Lawrence emphasized the value of using man pagesmanual pagesDocumentation available from the command line.
> man ls as a sanity check before getting carried away with powerful commands. I didn’t know about this one but he has written about a situation in which killall
could produce some shocking, and potentially quite unpleasant, results.
Personally, I often quickly check man pages to be certain that I am using the correct flags or, as in the above case, anticipating results that bear some resemblance to what is actually likely to happen. Yet, it seems many people flock toward SERPSearch Engine Results Page A tasteful replacement for mentioning any particular search-engine by name.
Also useful as a verb:
“I dunno. You’ll have to SERP it.”s for this information.
Perhaps the most compelling reason to head for the web is leaving the cursor amid the line you’re working on, without disturbing the command. SERPing the command however, could easily lead you to information about a variant that is more common than the one available to you. More importantly, the information retrieved from the search engine is almost certainly written by someone who did read the man page — and may even come with the admonishment that you RTFMRead The F#!$!*#’n Manual as a testament to the importance of developing this habit.
This can be made easier with just a few CLI shortcuts.
<CTRL+u>
to cut what you have typed so far and <CTRL+y>
to paste it back.
That is, you press <CTRL+u>
and the line will be cleared, so you can then type man {command}
and read the documentation. Don’t hesitate to jot quick notes of which flags you intend to use, if needed. Then exit the man page, press <CTRL+y>
and finish typing right where you left off.
This is another good use for screen
or tmux
but let’s face it. There are times when you don’t want the overhead of opening another window for a quick look-up and even instances when these tools aren’t available.
A few other tips to make life easier when building complex commands:
Use the command fc
to open up an editor in which you can build your complex command and, optionally, even save it as a shell script for future reuse.
Repeat the last word from the previous command (often a filename) with <ALT+.>
or use an item from the last command by position, in reverse order:
> ls -lahtr *archive*
<ALT+1+.>
: *archive*
<ALT+2+.>
: -lahtr
<ALT+3+.>
: ls
You can also use Word Designators to use items from history, such as adding sudo
to the last command typed by:
sudo !!
This allows for tricks like replacing bits of a previous command:
!:s/misspelled/corrected/
Lastly, if you need a command that was typed earlier, you can search history by pressing <CTRL+r>
and start typing an identifying portion of the command.
(Note: I have used these in Zsh and Bash, specifically. They can, however, be missing or overwritten — if a feature you want isn’t working, you can bind keys in a configuration file. Don’t just write it off, once you’ve solved the problem it will never again be an intimidating one.)
Happy hacking!
Tags: Bash, CLI, fc, GNU-Screen, man, shortcuts, tmux, word-designators, Zsh
Permalink: 20130606.managing.to.use.man.pages
Thu, 30 May 2013
In this writer’s opinion, it is vitally important that we take reasonable measures now to help insure anonymity, lest we create a situation where privacy no longer exists, and the simple want of, becomes suspicious.
Here’s how to configure your browser to automatically use a search engine that respects your privacy.
Chrome:
- Click Settings.
- Click “Set pages” in the “On startup” section.
- Enter
https://ixquick.com/eng/
in the “Add a new page” text field.
- Click OK.
- Click “Manage search engines…”
- At the bottom of the “Search Engines” dialog, click in the “Add a new search engine” field.
- Enter
ixquick
ixquick.com
https://ixquick.com/do/search?lui=english&language=english&cat=web&query=%s
- Click “Make Default”.
- Click “Done”.
Firefox:
- Click the Tools Menu.
- Click Options.
- Click the General tab.
- In “When Firefox Starts” dropdown, select “Show my home page”.
- Enter
https://ixquick.com/eng/
in the “Home Page” text field.
- Click one of the English options here.
- Check box for “Start using it right away.”
- Click “Add”.
Opera:
- Click “Manage Search Engines
- Click “Add”
- Enter
Name: ixquick
Keyword: x
Address: https://ixquick.com/do/search?lui=english&language=english&cat=web&query=%s
- Check “Use as default search engine”
- Click “OK”
Internet Explorer:
_ ___ _ __ ___ _ _____ ___
| | / _ \| |\ \ / / | | |_ _|__ \
| | | | | | | \ \ /\ / /| | | | | | / /
| |__| |_| | |__\ V V / | |_| | | | |_|
|_____\___/|_____\_/\_/ \___/ |_| (_)
(This is not a good strategy for privacy.)
Congratulations!
\o/
You are now one step closer to not having every motion on the Internet recorded.
This is a relatively small measure, though. You can improve your resistance to prying eyes (e.g., browser fingerprinting) by using the Torbrowser Bundle, or even better, Tails, and routing your web usage through Tor, i2p, or FreeNet.
If you would like more on subjects like anonymyzing, privacy and security then drop me a line via email or Bitmessage me: BM-2D9tDkYEJSTnEkGDKf7xYA5rUj2ihETxVR
Tags: \o/, anonymous, Chrome, Firefox, FreeNet, i2p, ixquick, LOLWUT, Opera, privacy, security, Tails, Tor, TorBrowser, TorBrowser-Bundle
Permalink: 20130530.hey.you.get.offa.my.data
Mon, 13 May 2013
Documentation for this one seems a bit hard to come by but it is one of the things I love about Zsh.
I’ve seen many .bashrc
files that have things like:
alias www='cd /var/www'
alias music='cd /home/j0rg3/music'
And that’s a perfectly sensible way to make life a little easier, especially if the paths are very long.
In Zsh, however, we can use the hash
command and the shortcut we get from it works fully as the path. Other words, using the version above, if we want to edit ‘index.html’ in the ‘www’ directory, we would have to issue the shortcut to get there and then edit the file, in two steps:
> www
> vim index.html
The improved version in .zshrc
would look like:
hash www=/var/www
hash -d www=/var/www
Then, at any time, you can use tilde (~) and your shortcut in place of path.
> vim ~www/index.html
Even better, it integrates with Zsh’s robust completions so you can, for example, type cd ~www/
and then use the tab key to cycle through subdirectories and files.
On this system, I’m using something like this:
(.zshrc
)
hash posts=/home/j0rg3/weblog/posts
hash -d posts=/home/j0rg3/weblog/posts
Then we can make a function to create a new post, to paste into .zshrc
. Since we want to be able to edit and save, without partial posts becoming visible, while we are working, we’ll use an extra .tmp
extension at the end:
post() { vim ~posts/`date +%Y-%m`/`date +%Y%m%d`.$1.txt.tmp }
[ In-line date
command unfamiliar? See earlier
explanation ]
But, surely there is going to be a point when we need to save a post and finish it later. For now, let’s assume that only a single post will be in limbo at any time. We definitely don’t want to have to remember the exact name of the post — and we don’t want to have hunt it down every time.
We can make those things easier like this:
alias resume="vim `find ~posts/ -name '*.txt.tmp'`"
Now, we can just enter
resume
and the system will go find the post we were working on and open it up for us to finish.
The file will need the extension renamed from
.txt.tmp
to only
.txt
to publish the post but, for the sake of brevity, we’ll think about that (and having multiple posts in editing) on another day.
Tags: blogitecture, CLI, find, hash, Zsh
Permalink: 20130513.zsh.and.hash
Tue, 07 May 2013
Thanks for visiting my little spot on the web. This is a Blosxom ‘blog which, for those who don’t know, is a CGI written in Perl using the file-system (rather than a database).
To the CLI-addicted, this is an awesome little product. Accepting, of course, that you’re going to get under the hood if you’re going to make it the product you want. After some modules and hacking, I’m pleased with the result.
My posts are just text files, meaning I start a new one like:
vim ~posts/`date +%Y%m%d`.brief.subject.txt
Note: the back-ticks (`) tell the system that you want to execute the command between ticks, and dynamically insert its output into the command.
In this case, the command date
with these parameters:
- (+) we’re going to specify a format
- (%Y) four-digit year
- (%m) two-digit month
- (%d) two-digit day
That means the command above will use Vim to edit a text file named ‘20130507.brief.subject.txt’ in the directory I have assigned to the hash
of ‘posts’.
(using hash
this way is a function of Zsh that I’ll cover in another post)
In my CLI-oriented ‘blog, I can sprinkle in my own HTML or use common notation like wrapping a word in underscores to have it
underlined, forward-slashes for
italics and asterisks for
bold.
Toss in a line that identifies tags and, since Perl is the beast of Regex, we pick up the tags and make them links, meta-tags, etc.
Things here are likely to change a lot at first, while I twiddle with CSS and hack away at making a Blosxom that perfectly fits my tastes — so don’t be too alarmed if you visit and things look a tad wonky. It just means that I’m tinkering.
Once the saw-horses have been tucked away, I’m going to take the various notes I’ve made during my years in IT and write them out, in a very simple breakdown, aimed at sharing these with people who know little about how to negotiate the command line. The assumption here is that you have an interest in *nix/BSD. If you’ve that and the CLI is not a major part of your computing experience, it probably will be at some point. If you’re working on systems remotely, graphical interfaces often just impede you.
Once you’ve started working on remote machines, the rest is inevitable. You can either remember how to do everything two ways, through a graphical interface and CLI — or just start using the CLI for everything.
So let’s take a little journey through the kinds of things that make me love the CLI.
Tags: blogitecture, Blosxom, BSD, CGI, CLI, firstpost, hash, Perl, Vim, Zsh
Permalink: 20130507.greetings