You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just found skim and I love it -- I've long wanted a tool that lets me very quickly iterate on interactive command line filters, to eliminate steps in the "run command, look at output in pager, quit pager, move cursor to right place in the command, re-run" loop, and skim's interactive mode provides that.
I have a shell function that I use to run jq from sk:
functionskjq {
sk --tac --ansi --regex --query . --multi --interactive --cmd '{}' \
--bind 'enter:select-all+accept,ctrl-y:select-all+execute-silent(for line in {+}; do echo $line; done | pbcopy)+deselect-all' \
--cmd-history=${HOME}/.sk_history --cmd-history-size=100000 \
--cmd-query "cat $1 | jq --raw-output --color-output '.'"
}
--tac is because sk seems to naturally reverse the order of its input (?)
--ansi is to allow colors
--regex --query . is because I don't want to remove any lines from the input -- I'm (ab)using the line selection buffer as a preview of the jq output
--multi is so when I accept or whatever, it can print out the entire line selection buffer
--interactive --cmd '{}' enters interactive mode and just runs whatever command is in the command query
--bind ... sets up a bind for enter that selects all and accepts, similar for C-y
--cmd-history* command query history (skim seems to not know how to expand ~ to my home directory, that's a separate issue)
--cmd-query "..." this is the meat, where I specify the initial jq invocation. It's pretty much just jq ..
This is an amazing experience, but I find myself referring to the line selection buffer and typing the name of some JSON key, and it often disappears while I'm typing (because my in-progress jq query or command is nonsensical).
Suggestion
Could you add an option that disables refreshing of the line selection buffer when the new command query exits with non-zero status? jq has an --exit-status option that makes it exit with status 1 in some cases.
The wrapping shell that invokes the command query could be sh -O pipefail -c ... instead of sh -c ... to make this more robust to noticing failures. I don't know how cross-shell pipefail is, but you could try invoking it with -O pipefail and fall back to omitting it if that fails.
The text was updated successfully, but these errors were encountered:
Background
I just found
skim
and I love it -- I've long wanted a tool that lets me very quickly iterate on interactive command line filters, to eliminate steps in the "run command, look at output in pager, quit pager, move cursor to right place in the command, re-run" loop, andskim
's interactive mode provides that.I have a shell function that I use to run
jq
fromsk
:--tac
is because sk seems to naturally reverse the order of its input (?)--ansi
is to allow colors--regex --query .
is because I don't want to remove any lines from the input -- I'm (ab)using the line selection buffer as a preview of the jq output--multi
is so when Iaccept
or whatever, it can print out the entire line selection buffer--interactive --cmd '{}'
enters interactive mode and just runs whatever command is in the command query--bind ...
sets up a bind forenter
that selects all andaccept
s, similar forC-y
--cmd-history*
command query history (skim
seems to not know how to expand~
to my home directory, that's a separate issue)--cmd-query "..."
this is the meat, where I specify the initialjq
invocation. It's pretty much justjq .
.This is an amazing experience, but I find myself referring to the line selection buffer and typing the name of some JSON key, and it often disappears while I'm typing (because my in-progress
jq
query or command is nonsensical).Suggestion
Could you add an option that disables refreshing of the line selection buffer when the new command query exits with non-zero status?
jq
has an--exit-status
option that makes it exit with status 1 in some cases.The wrapping shell that invokes the command query could be
sh -O pipefail -c ...
instead ofsh -c ...
to make this more robust to noticing failures. I don't know how cross-shellpipefail
is, but you could try invoking it with-O pipefail
and fall back to omitting it if that fails.The text was updated successfully, but these errors were encountered: