Shell Utilities to Maximize Productivity

If you are a developer, you probably spend a decent chunk of time interacting with a terminal Shell. Today We'll look at 6 different tools ...

Reading Time
5 min (~855 words)
Tags
Shell
Productivity
Date
8/27/2019
Shell Utilities to Maximize Productivity

If you are a developer, you probably spend a decent chunk of time interacting with a terminal Shell. Today We'll look at 6 different tools that will make your work that much easier!

1. Ripgrep
#

GitHub - BurntSushi/ripgrep: ripgrep recursively searches directories for a regex pattern while respecting your gitignore
GitHub - BurntSushi/ripgrep: ripgrep recursively searches directories for a regex pattern while respecting your gitignore

ripgrep recursively searches directories for a regex pattern while respecting your gitignore - GitHub - BurntSushi/ripgrep: ripgrep recursively searches directories for a regex pattern while respec...

https://github.com/BurntSushi/ripgrep

You've probably used grep before – it's one of the most ubiquitous tools in any devs toolbelt, and it gets the job done.

But what if there was something even better? Ripgrep is purpose-built for searching over large amounts of files recursively. It knows how to read your .gitignore file and automatically skips hidden files/directories as well as binary files.

Ripgrep is supported on all major operating systems! There are binaries available for every release. it's also 2-5 times faster than other searching tools – they have benchmarks listed on their github repo.

Enough about Ripgrep, let's give it a whirl:

1# Recursively search the current directory for a regex pattern:
2rg pattern
3
4# Search for pattern including all .gitignored and hidden files:
5rg -uu pattern
6
7# Search for a pattern only in a certain filetype (e.g., html, css, etc.):
8rg -t filetype pattern
9
10# Search for a pattern only in a subset of directories:
11rg pattern set_of_subdirs
12
13# Search for a pattern in files matching a glob (e.g., `README.*`):
14rg pattern -g glob
15
16# Only list matched files -- useful when piping to other commands:
17rg --files-with-matches pattern
18
19# Show lines that do not match the given pattern:
20rg --invert-match pattern

2. Bat
#

GitHub - sharkdp/bat: A cat(1) clone with wings.
GitHub - sharkdp/bat: A cat(1) clone with wings.

A cat(1) clone with wings. Contribute to sharkdp/bat development by creating an account on GitHub.

https://github.com/sharkdp/bat

A cat clone with syntax highlighting and Git integration.

bat supports syntax highlighting for a large number of programming and markup languages such as markdown bat is  git aware, and can show modified lines as well

Bat also has a super nice feature where if the output is too large for the screen, it will smartly pipe its output to your default pager (probably less unless you changed this yourself)

1# Print the contents of a file to the standard output:
2bat file
3
4# Concatenate several files into the target file:
5bat file1 file2 > target_file
6
7# Append several files into the target file:
8bat file1 file2 >> target_file
9
10# Number all output lines:
11bat -n file
12
13# Syntax highlight a json file:
14bat --language json file.json
15
16# Display all supported languages:
17bat --list-languages

3. Exa
#

Website

exa is a modern replacement for the command-line program ls that ships with *nix operating systems.

exa has more features and better defaults – It uses color to distinguish files and metadata. It understands symlinks, extended attributes, and Git. And it’s small, fast, and contained within a single binary.

exa -glam --group-directories-first

exa is a nice drop-in replacement for the default ls command. I've set an alias for it

alias ls="exa -glam --group-directories-first"

4. JQ
#

GitHub - stedolan/jq: Command-line JSON processor
GitHub - stedolan/jq: Command-line JSON processor

Command-line JSON processor. Contribute to stedolan/jq development by creating an account on GitHub.

https://github.com/stedolan/jq

jq is like sed for JSON data - you can use it to slice, filter, map and transform structured data with the same ease that sedawkgrep and friends let you play with text in the shell.

1# list all of the commands under the 'scripts' key in package.json
2jq '.scripts' package.json
3
4# Output a JSON file, in pretty-print format:
5jq . file.json
6
7# Output all elements from arrays (or all key-value pairs from objects) in a JSON file:
8jq '.[]' file.json
9
10# Read JSON objects from a file into an array, and output it (inverse of `jq .[]`):
11jq --slurp . file.json
12
13# Output the first element in a JSON file:
14jq '.[0]' file.json
15
16# Output the value of a given key of the first element in a JSON text from `stdin`:
17cat file.json | jq '.[0].key_name'
18
19# Output the value of a given key of each element in a JSON text from `stdin`:
20cat file.json | jq 'map(.key_name)'
21
22# Combine multiple filters:
23cat file.json | jq 'unique | sort | reverse'
24
25# Output the value of a given key to a string (and disable JSON output):
26cat file.json | jq --raw-output '"some text: \(.key_name)"'

5. FZF
#

GitHub - junegunn/fzf: A command-line fuzzy finder
GitHub - junegunn/fzf: A command-line fuzzy finder

:cherry_blossom: A command-line fuzzy finder. Contribute to junegunn/fzf development by creating an account on GitHub.

https://github.com/junegunn/fzf

fzf is a general-purpose fuzzy finder for your terminal shell.

It can be used with any list; files, command history, processes, hostnames, bookmarks, git commits, etc.

FZF is Portable and has no dependencies, is Blazingly fast and provides a flexible layout. It also has some really great features out of the box such as Vim/Neovim plugins, key bindings and fuzzy auto-complete.

By default FZF runs in 'full-screen' mode, but you can pass flags to resize and change the layout

1# handy function to search for a file, with a nice preview window!
2select_file() {
3  given_file="$1"
4  fzf --preview="cat {}" --preview-window=right:70%:wrap --query="$given_file"
5}
6
7# open a fuzzy searched file with vim
8vim $(select_file)
9
10# Start finder on all files from arbitrary locations:
11find path/to/search -type f | fzf
12
13# Start finder on running processes:
14ps aux | fzf
15
16# Select multiple files with `Shift + Tab` and write to a file:
17find path/to/search_files -type f | fzf -m > filename
18
19# Start finder with a given query:
20fzf -q "query"
21
22# Start finder on entries that start with core and end with either go, rb, or py:
23fzf -q "^core go$ | rb$ | py$"
24
25# Start finder on entries that not match pyc and match exactly travis:
26fzf -q "!pyc 'travis"

Hopefully you find some of these shell tools as useful as I do, please leave a comment and share the article if you found it useful!