A de-minifier (formatter, exploder, beautifier) for shell one-liners.
sol [ sohl ] noun
- a tool to help you inspect chained shell commands before you share a one-liner (or after you receive one)
Before I ransol
, I had no idea what the h**k that one-liner I got from Oscar was supposed to do. - (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 withsol
first. - (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 usingsol
. - an old French coin equal to 12 deniers
sol
is an free open-source project, but I take dollars and even sols as tips.
- 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
go install -v github.com/noperator/sol/cmd/sol@latest
𝄢 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
Explode a complex one-liner directly on an interactive shell prompt. Great for iteratively editing a complex command.
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'
Invoke it directly within Vim using visual block mode, a custom keybinding, etc.
Alternatively, you can simply pipe a one-liner into standard input.
- parallelize
exec.Command
calls inshellenv.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
This project is licensed under the MIT License.