• Tech Tips

    Monitoring APFS Drive Decryption Progress

    I recently decided to [permanently] decrypt an APFS volume via Finder (Right click the drive, choose Decrypt).

    There wasn’t any indication that it was actually working. After some web searches, I pieced together a one-liner to monitor the progress of the decryption operation. This will refresh every 60 seconds. If your setup is anything like mine this will be an exceptionally slow operation.

  • Development,  Tech Tips

    Triggers in iTerm – Watching For Specific Strings

    I was recently performing a git-add in patch mode (  git add -p ) as I normally do, and realized there were a few lines I needed to make sure I didn’t commit. These lines were sandwiched between other lines that I did want to commit, and there were hundreds of changes, so it was hard to spot them. I wondered if iTerm2 had a way of highlighting or alerting when a specific word shows up in the terminal. To my surprise I found a “Triggers” section under the “Profiles » Advanced” tab in the settings for the app. iTerm2 really can do everything!

  • Tech Tips

    Delete Last Command from Bash History

    If you’re like me, on occasion you accidentally (or sometimes purposefully) include a password in a command. Until recently I would execute history , find the offending command’s number, then do a history -d NUMBER . It is kind of a pain.

    The following deletes the last item in your bash history:

    You can create an alias for this, type it manually (umm, no thanks), or, as is the case for me, create a Keyboard Maestro macro for it. Here’s what my macro looks like:

    img20141208190438

  • Tech Tips

    Autocomplete in iTerm2

    This is a really quick tip that could save you tons of time in iTerm2. If you use any auto-completion you know how important it is to your workflow. Personally, I rely heavily on omni and generic completion in Vim.

    In Vim CTRL-N is the key combination I use after I start typing a word that I know exists somewhere else in the buffer. It pops open a menu where I can choose the match I want. For example, if I have a function called “agileadam_foo”, I can quickly retype that string by typing part of the string (e.g., agi) followed by CTRL-N. If it’s the only match it’ll complete the string, otherwise I can choose which string I want, or type another letter or two and try again. It all happens very quickly, and is almost always faster than typing the string in its entirety.

    You can achieve the same functionality in iTerm2 without any special configuration. The built-in key combination is CMD-; (command + semicolon). Here’s the description of the feature from iTerm’s Highlights for New Users guide:

    Any text that exists in a tab or its scrollback buffer can be autocompleted in that tab. To use autocomplete, type the beginning of a word and then press cmd-;. An autocomplete window opens showing the top 20 choices for words beginning what what you have entered. The list can be filtered by typing a subsequence. The filter can be reset by pressing backspace. If you make a selection and press return, it will be entered for you. If you make a selection and press tab, your autocomplete will be extended with the selection.

    I had a [not-so-] brilliant idea of mapping, in the Keys preference pane for the app,  CTRL-N to Select Menu Item… » Open Autocomplete… so that it mimics Vim. Unfortunately, as you might have guessed, it overrode the CTRL-N mapping in Vim. I guess I’ll stick to the default CMD-; for now.

  • Tech Tips

    Determining Your Most Used Commands in Terminal

    I’m always looking to automate things using Alfred, Keyboard Maestro, Text Expander, and Python. I was curious which terminal commands I use most often, so I did some experimenting. Basically I wanted to know how many times I’ve executed each unique command ( ssh myserverx or ssh myservery, not just ssh). I started by piping the output of history to  sort (to group), then to  uniq (to count), then back to sort (to sort by the number of occurrences).

    Unfortunately, the result contained the same number of lines as the original history output. I figured this was because each line had a unique integer prefix (the line number in the history output). As it turns out, ~/.bash_history (where history gets its records) doesn’t contain line numbers. I simply changed the source and it worked like a charm:
  • Development

    Applescript to Interact with iTerm2

    iTerm2 has decent support for Applescript. You can work with sessions, profiles, tabs, and more through Applescript. I only have one example, but it’s something I use in the real-world, so maybe it’ll help someone else.

    The following script will open a new tab for every server in the list, and execute a command on that server. Let’s say a new version of Drush is available. I’d use this script to log into every server (we have no less than 15 servers) and check which version of Drush the server is running. I could then quickly update if needed, and I’m already logged in to do so.

  • Tech Tips

    “755”-style permissions with ‘ls’

    After a quick Google search for “ls permissions octal” I found a very handy alias to put in my .bashrc. Not only is it handy to see the OCTAL value of the permissions for each file/dir, it will undoubtedly help you more quickly recognize/interpret the normal ls -al output.

     Example usage:
    You can also type (or paste) this slightly different version into terminal:
  • Development

    Automatically Stage All Deleted Files (Git)

    Tab-completion is a really nice thing that we often take for granted. While working with Git I’ve found that it becomes inconvenient to stage (add for inclusion in the next commit) removed files using git rm path/to/my/file.php. Tab completion doesn’t work on paths that no longer exist, so you have to manually type the path to the deleted item. The following snippet automatically stages ALL removed files.

    git ls-files -d -z | xargs -0 git rm --cached --quiet
  • Development

    Automatically Change Links from Absolute to Relative

    In this example I’m showing one way to quickly convert all a href and img src paths from absolute to relative. It’s quite a time saver, but I suggest committing your latest changes before trying anything here! If you aren’t using a version control system, make a backup somewhere… please! Note: Both of these commands are one-liners.

    In the examples/results below, I tried to target most situations. You should see subtle differences between each example.