pbcopy, no cat
My friend Josh recently wrote about a common mistake using pbcopy, Apple’s pasteboard utility. ...
My friend Josh recently wrote about a common mistake using pbcopy, Apple’s pasteboard utility. ...
Note: This applies to Zsh, but the process would be similar for any terminal. In Zsh, if you type man cd, instead of a manual page you get an output containing this: See the built-in command description in the appropriate shell manual page. What’s going on here? Here’s a summary: Builtin commands are contained within the shell itself. When the name of a builtin command is used as the first word of a simple command (see Simple Commands), the shell executes the command directly, without invoking another program. Builtin commands are necessary to implement functionality impossible or inconvenient to obtain with separate utilities. –“Shell Builtin Commands”, https://www.gnu.org/ ...
Suppose you want to append to a file that’s write-protected and can only be edited via sudo. Is that possible? It is! A technique I discovered today is to use tee with sudo: $ cat file.txt | sudo tee -a /etc/hosts This lets me append the contents of file.txt to the write-protected /etc/hosts file by entering my password.
When you combine cat (concatenate) with > (output redirection), you can create and write to a file from the command line. $ cat > test.txt Hit enter after the file name, and your terminal will wait for input. End the file with CTRL + D. $ cat > test.txt one two three $ cat test.txt one two three >> works, too; appending to the file as expected.
Autojump is my tool of choice for navigating directories. If I enter the following into the terminal: $ j til Autojump will try to guess where I want to go among directories I’ve previously visited. It uses a database of directories and their relative rankings to do so. But there’s a problem! These day I only want to visit ~/oss/til. In the past I’ve visited ~/oss/hr-til and ~/oss/tilex hundreds of times. Autojump always sends me there first. I don’t want that! ...
The exit code of a command in a Unix-based system is an important and easy-to-miss piece of data. It isn’t printed to standard out; you have to go looking for it. I find it useful to inspect this information when debugging or considering chaining unfamiliar commands. ...
When I upgrade ASDF, I sometimes get an error like this when I try to run a command: /Users/jakeworth/.asdf/shims/jq: line 3: /usr/local/Cellar/asdf/0.9.0/libexec/bin/asdf: No such file or directory The issue is that I’ve upgraded ADSF to v0.10.2, but the jq shim doesn’t know that and can’t find it in a directory called “0.9.0”. This issue persists even after running asdf reshim. My solution is to force ASDF to rebuild shims directory by renaming it. A rename lets me get back to where I am now, in case I need to. ...
A lot of people start programming with shared dotfiles, copied from a team or online. I did. Maybe you’re ready to move on; how would you do that? ...
Something I took for granted at Hashrocket was the file that configures Exhuberant Ctags. Without configuration, recursive tag generation will tag many things and cause problems. overindex badly. Here’s how you configure Ctags to ignore things: /ctags.cnf (on MSDOS, MSWindows only) /etc/ctags.conf /usr/local/etc/ctags.conf $HOME/.ctags $HOME/ctags.cnf (on MSDOS, MSWindows only) .ctags ctags.cnf (on MSDOS, MSWindows only) If any of these configuration files exist, each will be expected to contain a set of default options which are read in the order listed when ctags starts, but before the CTAGS environment variable is read or any command line options are read. This makes it possible to set up site-wide, personal or project-level defaults. Here’s the head of my root .ctags, which even this far in is excluding a lot: ...
Any command you type out manually, or even tab-complete a few times, can be shortened. A common shortening technique is the terminal alias. Here are some tips that help me write better aliases and cut my terminal keystrokes. ...
Don’t miss my next essay
Hear from me immediately when I post: no ads, unsubscribe anytime.