Posts Tagged “bash”

  • Shell Tricks: halp -- a universal help tool

    I have a lot of aliases and functions in my terminal, in addition to the plethora of UNIX commands. If I'm not sure what the source of a command is, getting info on it can require multiple tries. First a man` check, then a `type` or `alias` command to see if it's custom, then a `man -k to see if I misspelled something, and so on. I eventually decided to just write an automated way to sift through those possibilities.…

  • Shell Tricks: shorten every line of output

    Updated: Dr. Drang pointed out that the original functions were mostly working but flawed. I've updated this whole post.…

  • Shell Tricks: list files with most text matches

    Here's a Bash function for searching all text files in the current directory for a pattern, then listing the files containing matches in ascending order by number of matches. It's mostly a proof of concept, but a useful companion to a basic grep search.…

  • Quick reminders from Terminal

    Here's a script for creating simple delayed alerts from Terminal. It doesn't use system notifications, Calendar, or Reminders, just the sleep`, `afplay`, and `say commands (making it Mac-only), and optionally LaunchBar large text display.…

  • Shell Tricks: Quick line numbering

    It's often useful to quickly see line numbers when viewing source code files. The less` command and related tools can display with line numbers. There's also the `nl` command, but it doesn't number blank lines and tends to mess up formatting. There's are ways that are more flexible and better looking. Enter `grep` and `paste.…

  • Shell Tricks: convert file urls to UNIX paths

    Today's shell trick is for converting file:// urls into valid shell paths. This isn't a terribly common scenario, but I occasionally work with tools, especially in GUI applications, that output file urls and need to change something like:…

  • Shell Tricks: .inputrc binding fun

    If you've never explored Bash's ~/.inputrc file, there's a lot of customization you can do in there. From setting completion and Readline options to creating custom keybindings, you can greatly improve your command line efficiency with a little tweaking.…

  • A universal clipboard command for Bash

    I frequently use pbcopy` in the shell to get output to the OS X clipboard. I'm constantly using `[command] | pbcopy, and figured it would be worth making a little easier, so I wrote this little function this morning.…

  • Intrepid command line directory traversal

    I use Terminal (well, iTerm 2) for file management on my Mac more often than I use Finder. Typing out long path names is often more tedious than drilling through Finder folders, though. I have enough tag-based Spotlight (mdfind) tools worked out in Bash that traversal in the shell has most of the same conveniences, but still, some of those paths...…

  • A Bash function for finding your Bash functions

    As you may have noticed if you've followed this blog lately, I write a lot of Bash functions and aliases. I keep them in distinct files using a plugin system based on bash-it. It works really well, and makes upkeep simple. However, I very often lose track of exactly where I defined a function or alias after a few months go by.…

  • Shell tricks: sort a Bash array by length

    I'm certain there's a more elegant way to do this, but I couldn't find it. I needed to sort a Bash array of strings by the length of each element without getting too verbose. Here's what I came out with:…

  • Shell trick: printf rules

    This post is about a simple trick for printing a horizontal rule in the Terminal, but I would like to start by saying that the headline is not entirely an attempt at humor. I spent a long time working with the limitations of echo`, with its `-e` annoyances and `-n` inconsistencies between shells. Then I started using `printf more, and it's made string formatting and terminal output so much simpler. Check out the man page (and some more info on format strings)if you're not already familiar with…

  • Keybindings for multiple clipboards

    It's been a while since I brought up keybindings. If you haven't followed my obsession with them in the past, you can catch up on all the fun in older posts and by browsing through the massive KeyBindings project I've assembled. To summarize, KeyBindings on OS X can provide all kinds of text editing assistance that's available and consistent across every app you use.…

  • sizeup: tidy filesize information in Terminal

    alias sizes="du -sh * | sort -n" That outputs all of the file and folder sizes in the current directory, sorted by size, and lists them in human-readable format. Of course, I wanted to make it a more painful endeavor.…