class: center, middle # The command line A whirlwind tour of useful command-line tools and features that I use --- # Why the command line? * All developers have to use it * Might as well be productive in it * Reproducibility is a breeze in the terminal * It can be fun (no, really) ??? There will be some repeats from part 1, but only those that I still find useful --- # fzf **Description**: A general-purpose interactive fuzzy text finder **Good for**: A **way better** reverse search for your shell **How to use**: Press `ctrl` + `r` from your shell **How to install**: `brew install fzf && $(brew --prefix)/opt/fzf/install` ([link](https://github.com/junegunn/fzf#using-homebrew-or-linuxbrew)) **See also**: [fzf.vim](https://github.com/junegunn/fzf.vim), if you're into that sort of thing, [zsh unlimited history](https://unix.stackexchange.com/a/273929) --- # Shell line navigation **Description**: Shortcuts to more easily manipulate the current line **Good for**: Making (more) precision edits **How to use**: * `ctrl` + `a` (go to beginning of line) * `ctrl` + `e` (go to end of line) * `ctrl` + `w` (delete previous word) * `ctrl` + `u` (delete entire line) **How to install**: Built-in to the shell **See also**: [zsh shortcuts](https://cheatography.com/davidsouther/cheat-sheets/bash-zsh-shourtcuts/), [iTerm Natural Text Editing](https://apple.stackexchange.com/a/218639) ```sh # Modify zsh's word split regex so that we can erase just one part of a # directory. Eg: erasing ~/dotfiles/zsh takes three ctrl+w motions, instead of # just one. WORDCHARS=$WORDCHARS:s:/: ``` --- # pbcopy/pbpaste **Description**: Commands that copy or paste from the system clipboard **Good for**: If you're too lazy to use a mouse **How to use**: * `echo hello | pbcopy` * `pbpaste > contents.txt` **How to install**: Already installed on a mac. **See also**: [xclip](https://opensource.com/article/19/7/xclip) (the linux equivalent) --- # tmux **Description**: A terminal multiplexer **Good for**: Managing multiple shell instances **How to use**: `tmux` // `tmux attach` **How to install**: `brew install tmux` **See also**: [A Quick and Easy Guide to tmux](https://www.hamvocke.com/blog/a-quick-and-easy-guide-to-tmux/), alternatively, [iTerm Window Arrangements](https://webstudiya.com/develop-faster-with-iterm-profiles-and-window-arrangements/) --- # Spectacle app, Yabai **Description**: Programs for X window management **Good for**: Tiling graphical programs like you do your terminal ones **How to use**: Focus a window and use the tiling window shortcuts **How to install**: Download from [spectacleapp.com](https://spectacleapp.com), or follow the [Yabai README](https://github.com/koekeishiya/yabai). **See also**: [Yabai demo](https://www.youtube.com/watch?v=AdwhjIg_Xe4) ??? Okay, so these aren't command line tools, but they are general purpose productivity tools. --- # git flags **Description**: Optional flags to pass to git commands **Good for**: Finer control over git **How to use**: * `git [add/reset] -p` * `git branch -vva` * `git revert --no-commit` * `git diff --cached` * `git commit --verbose` **How to install**: Installed alongside `git` **See also**: [useful git aliases](https://www.durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/) --- # shell aliases **Description**: Built-in shell functions or commands **Good for**: Automating or shortening commands, without creating an external script **How to use**: * `alias` * `alias frb=cd ~/code/work/frb` * `alias gs=git status` **How to install**: Built-in to the shell **See also**: [zsh-z](https://github.com/agkozak/zsh-z) --- # curl/httpie **Description**: Make HTTP requests against a webpage **Good for**: Working with APIs **How to use**: `curl ipinfo.io` // `http ipinfo.io` **How to install**: `curl` already installed, `brew install httpie`. Can also be `pip install`ed **See also**: [httpie cheatsheet](https://devhints.io/httpie), [curl cheatsheet](https://devhints.io/curl) --- # jq **Description**: General purpose JSON processor **Good for**: Filtering/sifting through JSON payloads **How to use**: * `cat response.json | jq` * `cat response.json | jq '.stores[].name'` **How to install**: `brew install jq` **See also**: [jq tutorial](https://stedolan.github.io/jq/tutorial/) --- # visidata **Description**: Interactive utility for exploring data in a tabular form. **Good for**: **Understanding the structure of JSON payloads**. Quick analysis of csv and json files. Also works with postgres databases, sqlite, and urls (say whaaat?). ALSO MAP PLOTTING! **How to use**: * `vd employees.csv` * `cat stores.json | vd -f json` **How to install**: `brew install visidata` **See also**: [Lightning demo](https://www.youtube.com/watch?v=N1CBDTgGtOU), [An Introduction to VisiData](https://jsvine.github.io/intro-to-visidata/index.html) --- # ag **Description**: Replacement for `grep` **Good for**: Finding text in files or folders **How to use**: * `ag searchstring` * `cat largeFile.js | ag -w WORD_HERE` **How to install**: `brew install the_silver_searcher` **See also**: [ag](https://github.com/ggreer/the_silver_searcher), [ripgrep](https://github.com/BurntSushi/ripgrep), [the_platinum_searcher](https://github.com/monochromegane/the_platinum_searcher) --- # fd **Description**: Replacement for `find` **Good for**: Finding files of a certain name or type **How to use**: * `fd test` * `fd -p test` * `fd -e json` **How to install**: `brew install fd` **See also**: [github.com/sharkdp/fd](https://github.com/sharkdp/fd) --- # redirects, pipes, here strings, special files **Description**: The way in which the shell handles program interactions **Good for**: Chaining commands together, or saving output to a file **How to use**: * `>` * `<` * `|` * `<<<` * `/dev/std{in,out,err}` (0, 1, 2) * `/dev/null` * `mkfifo` **How to install**: Built-in to the shell **See also**: [everything is a file](https://www.howtogeek.com/117939/htg-explains-what-everything-is-a-file-means-on-linux/), [tee command](https://www.geeksforgeeks.org/tee-command-linux-example) --- # PostgreSQL **Description**: General purpose relational database **Good for**: Applications whose data is structured in nature **How to use**: * `createdb`/`dropdb` to create/drop database * `psql` to connect to a database * `pg_dump` to create a backup **How to install**: `brew install postgres` **See also**: [learn SQL in 5 mins](https://towardsdatascience.com/learn-beginner-sql-in-5-steps-in-5-minutes-c44c47fa39a1), [pgcli](https://www.pgcli.com/), [using JSON in Postgres](https://rollout.io/blog/unleash-the-power-of-storing-json-in-postgres/) --- # redis-cli / redis-server **Description**: key:value store used as a lightweight database/cache/message broker **Good for**: Exactly that **How to use**: * `redis-cli` * `redis-cli keys "*"` * `redis-cli -h test-redis.com` **How to install**: `brew install redis` **See also**: [redis quickstart](https://redis.io/topics/quickstart) --- # brew services **Description**: List brew-managed background services **Good for**: Automatically starting/stopping Redis, Postgres, Docker, etc... **How to use**: * `brew services` * `brew services [start,stop] redis` **How to install**: ~~brew install~~ kidding, it's installed with `brew` **See also**: --- # serve **Description**: Host static files/directories as a website **Good for**: Mimicking backend servers with files, hosting front-end apps locally, testing ssl certificates **How to use**: `serve .` **How to install**: `npm install serve` **See also**: `serve --help`, [mockserver](https://www.mock-server.com/), `python3 -m http.server` --- # bat **Description**: A drop-in replacement for `cat`, with extra eye candy **Good for**: Grokking a file without using a heavy editor to do so **How to use**: `bat NAME_OF_FILE` **How to install**: `brew install bat` **See also**: --- # pup **Description**: Parse/prettify html from the command line **Good for**: Making sense of hard-to-read HTML **How to use**: `curl some-website.com | pup --color` **How to install**: `brew install pup` **See also**: [pup usage](https://github.com/ericchiang/pup#examples) --- # Just for fun ```console $ pipes.sh $ cmatrix $ telnet towel.blinkenlights.nl ``` **Description**: The CLI isn't just for serious business **Good for**: ??? **How to use**: **How to install**: `brew install pipes-sh`, `brew install cmatrix` **See also**: [github.com/ligurio/awesome-ttygames](https://github.com/ligurio/awesome-ttygames), [sl](https://github.com/mtoyoda/sl), [gti](https://r-wos.org/hacks/gti)