using variables on the command line

Following on from my last example of copying a SSH public key to a remote computer, this is something I need to do when setting up a new computer. Setting up private/public keys for SSH just make logging in that little bit smoother.

When you need to rerun the command, you need to load it up, edit it and resubmit it. Unfortunately (although it’s probably possible) I don’t know an easy way to bring up a previous command and edit it in-line so that I can send it again without actually sending the command again before doing so.

Instead, Load a variable into the command line and change it next time.

-- 11:03:01 -- MBP:~ madivad$ ssh minixbmc
Password:
Last login: Mon Apr 25 18:23:18 2016
minixbmc:~ madivad$ exit
logout
Connection to minixbmc closed.
-- 11:03:17 -- MBP:~ madivad$ remote=minixbmc
-- 11:03:26 -- MBP:~ madivad$  history | grep remote
  439  remote=he1000
  440  cat ~/.ssh/id_rsa.pub | ssh madivad@$remote "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
  502  remote=minixbmc
-- 11:03:34 -- MBP:~ madivad$ !440
cat ~/.ssh/id_rsa.pub | ssh madivad@$remote "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Password:
-- 11:03:40 -- MBP:~ madivad$ ssh minixbmc
Last login: Tue Apr 26 11:03:12 2016 from mbp.fritz.box
minixbmc:~ madivad$

For example, in the above session, for simple commands, I would being the history file up, reissue line 440, then edit, then issue it again. In this situation, it would have the effect of loading the key again, and that’s not what I want to do.

  • Breaking it down, I logged into the remote machine and realised a password was needed,
  • I logged out,
  • I set the “remote” variable,
  • looked for the relevant history command (I knew it had the word “remote” on it),
  • I re-issued that line, and
  • then tested the login.
  • No password was needed, the command was a success.

This could be done with other things as well where you’re always changing one element on the line (or multiple elements, and use multiple variables).

For a more simple and silly example, let’s create a quick update and install script for ubuntu:

upstall=’htop multiwatch’
sudo apt update && sudo apt install $upstall

Instead of typing the whole line next time, I can just type the new apps to install in the “upstall” variable and reissue the command (in this case, using arrow up a couple of times, or grabbing the index from the history file).

$ sudo apt update && sudo apt install $upstall
[sudo] password for madivad:
Hit:1 http://au.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://au.archive.ubuntu.com/ubuntu xenial-updates InRelease [92.2 kB]
Hit:3 http://au.archive.ubuntu.com/ubuntu xenial-backports InRelease
Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [92.2 kB]
Fetched 184 kB in 1s (101 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
byobu is already the newest version (5.106-0ubuntu1).
htop is already the newest version (2.0.1-1).
multiwatch is already the newest version (1.0.0-rc1+really1.0.0-1).
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.

If I then later want do another update and install something else, I can re-set the “upstall” variable and arrow up or grab it out of history.

11:53:44 madivad@he1000:~$ upstall=jq
12:03:44 madivad@he1000:~$ sudo apt update && sudo apt install $upstall
Hit:1 http://au.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://au.archive.ubuntu.com/ubuntu xenial-updates InRelease [92.2 kB]
Hit:3 http://au.archive.ubuntu.com/ubuntu xenial-backports InRelease
Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [92.2 kB]
Fetched 184 kB in 2s (91.0 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
jq is already the newest version (1.5+dfsg-1).
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
I'm a simple man, I like simplicity. And although there are probably better ways to do this, for the time being, this is how I'm getting the job done. It works well for me, but I'm open to any suggestions and/or improvements.

As I said, not the best example, but hopefully you get the idea.

Adding to the Favourites Sidebar

drag and drop folder to osx favourite sidebarWhen that happens, there are two other options:

  • File > Add to Sidebar
  • Keyboard shortcuts

Sometimes the File menu option is not available, but the keyboard shortcut CTRL + CMD + T is usually right to go.

You could try dragging a subfolder into place and then ESCAPEing out of it. This will usually open up the past the re-add the folder you couldn’t add a moment ago.

reference: http://apple.stackexchange.com/questions/139305/how-can-i-add-new-folders-to-the-favorites-in-the-finder-sidebar/226776#226776

Installing Macports and md5deep on OSX

When it comes to installing packages and you have to make a decision between MacPorts or Homebrew I first went and visited their home pages (linked previously) and couldn’t make a decision based on what I saw to go either way. I didn’t want to install both, so I googled a bit more. I suggest you do the same since I don’t want people doing something JUST because I said so, go make your own decision :P

Having said that, I based my decision primarily on these points:

  1. the number of packages available in MacPorts (almost 25K) vs Homebrew’s (3K)
  2. the ease of Apache/PHP updates
  3. I’m comfortable with the command line and file/system permissions

Why do I want to install macports?

Because I’m a dunce at compiling, configuring, making stuff myself. And I’ve wanted md5deep for too long.

Now to install all I typed was:

sudo port install md5deep

and it was done.

It really was that simple.

Freeze rows/columns in OSX’s Numbers spreadsheet

You can’t easily freeze rows or columns in the “Excel sense” in Numbers–Apple’s version of a spreadsheet.

But what you can do is create header rows and header columns (the default grey ones) that ARE frozen.

In Numbers:
>> open the document inspector
>> table inspector (3rd option for me, looks like a yellow table)

There are three “headers” and “footers” drop downs. At the bottom of the first two is an option to FREEZE that element. This only applies to header and footer rows/columns, but that should about solve the problem. It’s not as nice as excel’s approach (which in my opinion is a little ‘cleaner’), but it works.

accented characters in osx

selectable accents for the letter 'a'
selectable accents

UPDATE: I upgraded my OS X to Mountain Lion recently and I am not sure if it is as a result of the upgrade, or some other setting change I may have made, but now if I hold down a letter key for a short period, I get a tool-tip style box (right) that then allows me to select the appropriate accent. This doesn’t work for all letters, but it does make it more convenient.

I had a need to be able to print accented characters on certain letters, mainly being vowels, but potentially others as well. Most character sets have a limited set of accents, and most of them only apply to certain letters, and others don’t have the accents I want.

For example I want to print 5 main types of accents, being:

à á ā â ǎ

another example

x̀ x́ x̄ x̂ x̌

I’m using a macbook pro and pages in OSX, although this applies to any application, this is how I did it:

Open up System Preferences >> Personal >> Language and Text >> Input Sources

Once there, add a new keyboard, in this case I added “US Extended”.

Now to add some accents, I need to type the accent first, and then the character, but this only works for some letters (I suppose those that can be normally accented), but as you can see above, I have accented the letter ‘x’. So achieve this you must type the letter first and then [option]+[shift]+[code]. Not too hard, the five I need are:

  • a bar over the letter – ā – [option]+a then type the letter
  • a ‘v’ over the letter – ǎ – [option]+v then the letter
  • a ‘^’ over the letter – â – [option]+^ then the letter
  • a ‘`’ over the letter – à – [option]+` then the letter, and finally
  • a ‘ ́’ over the letter – á – [option]+e then the letter

^ <– is [shift]+6
` <– is the back tick, or key with the tilde (~) on it
́ <– is the quote mark key with single and double quotes [‘,”]

It was that simple :-)

note: I am learning the thai language and it is a very tonal language and inflections on letters are necessary to determine the tone of the word, hence I need this ability. These 5 marks above fit the bill perfectly, although the bar one really isn’t needed, but at least now I have the option of including it, or not including it.

Originally found here: http://tlt.its.psu.edu/suggestions/…

I wish I could just sync checked photos from iPhoto

iPhoto icon
iPhoto

An open letter to Apple; “Please let me sync just checked photos to my devices”

I have just posted this to Apple’s feedback section as a feature request. I know this is not probably something we will see, but at least I’m not just publishing this, I’m complaining in the right channels.

I love iPhoto, I really do. But it has some flaws. I work around most of them. But the most unforgiving flaw (as someone who takes a LOT of photos), is that there is no easy way to synchronise JUST the photos you want. You HAVE to create albums and smart albums, or use ratings. Even faces are no good, because it sync’s ALL faces of any selected person.

What iPhoto NEEDS is a checkbox list view (as in iTunes) where you can select any album, event, face or place, but only those checked items (within those lists) will be syncd. The way it is now, you must create an event for the photos, then create an album from the event that has JUST the photos you want. A lot of event/album/photo duplication (even if it is just an alias).

When I’m on the iPhone I want certain photos available. I want more available on the iPad, but I want everything available on the computer.

Can we please have a better way of managing these?

Thanks