Skip to content
/ sol Public

A de-minifier (formatter, exploder, beautifier) for shell one-liners

License

Notifications You must be signed in to change notification settings

noperator/sol

Repository files navigation

sol

A de-minifier (formatter, exploder, beautifier) for shell one-liners.

ray

sol [ sohl ] noun

  1. a tool to help you inspect chained shell commands before you share a one-liner (or after you receive one)
    Before I ran sol, I had no idea what the h**k that one-liner I got from Oscar was supposed to do.
  2. (also soul) the spiritual part of humans regarded in its moral aspect
    You probably don't have a soul—or at least, not a good one—if you share a one-liner with me without cleaning it up with sol first.
  3. (rude slang) in a hopeless position or situation
    You're SOL if you think I'm going to try to read your one-liner without using sol.
  4. an old French coin equal to 12 deniers
    sol is an free open-source project, but I take dollars and even sols as tips.

Features

  • Choose which transformations you want (break on pipe, args, redirect, whatever)
  • "Peeks" into stringified commands (think xargs, parallel) and formats those, too
  • Shows you non-standard aliases, functions, files, etc. that you might not have in your shell environment
  • Breaks up long jq lines with jqfmt because—let's be honest—they're getting out of hand

Built with

Getting started

Install

go install -v github.com/noperator/sol/cmd/sol@latest

Usage

𝄢 sol -h
Usage of sol:
  -a	arguments
  -all
    	all
  -b	binary commands: &&, ||, |, |&
  -c	command substitution: $(), ``
  -e	inspect env to resolve command types
  -f string
    	file
  -j	jq
  -jqarr
    	arrays
  -jqobj
    	objects
  -jqop string
    	operators (comma-separated)
  -l	clauses: case, for, if, while
  -o	one line
  -p	process substitution: <(), >()
  -r	redirect: >, >>, <, <>, <&, >&, >|, <<, <<-, <<<, &>, &>>
  -s	shell strings: xargs, parallel
  -v	verbose

via CLI

Explode a complex one-liner directly on an interactive shell prompt. Great for iteratively editing a complex command.

cli

In the example above, I'm using bash in vi mode; I've bound @ to sol-func which calls sol with a few preset options.

sol-func() {
	local current_line="${READLINE_LINE}"
	READLINE_LINE=$(echo "$current_line" | sol -p -c -b -r -a -s -jqobj -jqarr -jqop comma)
	READLINE_POINT=${#READLINE_LINE}
}
bind -m vi-command -x '"@": sol-func'

via Vim

Invoke it directly within Vim using visual block mode, a custom keybinding, etc.

vim

via stdin

Alternatively, you can simply pipe a one-liner into standard input.

stdin

Back matter

See also

To-do

  • parallelize exec.Command calls in shellenv.go
  • log better
  • explicitly handle other shell environments besides bash
  • fail gracefully when command not found
  • auto-break on 80-char width, etc.
  • document API usage
  • add a test for shell environment inspection

License

This project is licensed under the MIT License.

About

A de-minifier (formatter, exploder, beautifier) for shell one-liners

Resources

License

Stars

Watchers

Forks

Languages