Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipestatus and command substitutions #6998

Closed
runiq opened this issue May 12, 2020 · 3 comments
Closed

Pipestatus and command substitutions #6998

runiq opened this issue May 12, 2020 · 3 comments

Comments

@runiq
Copy link

runiq commented May 12, 2020

fish version 3.0.2.

I'd like to split the output of fzf --print0 (which writes NUL-delimited output) on NUL bytes and write it into a variable. As far as I'm aware, that requires fzf --print0 | string split0, otherwise all output after the first NUL byte will be cut off.

However, fzf also returns a meaningful exit code if it was aborted, and I'd like to do something with that exit code. Piping fzf into another command gives me no way to get at fzf's exit code.

Is there a way for me to have my cake and eat it too? :)

@krobelus
Copy link
Member

krobelus commented May 12, 2020

Wait, what is the use of --print0? Doesn't fzf split by newlines already, so there won't be newlines in the selected items?

Anyway you can get exit status of the individual commands in the pipe with the $pipestatus variable. See also https://fishshell.com/docs/current/tutorial.html?highlight=pipestatus#exit-status.

@krobelus krobelus added bug Something that's not working as intended question and removed bug Something that's not working as intended labels May 12, 2020
@faho
Copy link
Member

faho commented May 18, 2020

Anyway you can get exit status of the individual commands in the pipe with the $pipestatus variable. See also https://fishshell.com/docs/current/tutorial.html?highlight=pipestatus#exit-status.

The problem with $pipestatus here is that it doesn't work with command substitutions and set, so the naive

set -l res (fzf --print0 | string split0)
echo $pipestatus

will print just the status of string split0.

@faho faho changed the title Can I capture the exit code of fzf in fzf --print0 | string split0? Pipestatus and command substitutions May 23, 2020
@faho faho added enhancement and removed question labels May 23, 2020
@faho faho added this to the fish-future milestone May 23, 2020
@soumya92
Copy link
Contributor

soumya92 commented Aug 4, 2020

Also fixed by #6820

~> set -l res (seq 1 10 | fzf --print0 | string split0); echo $pipestatus
(select "2")
0 0 0
~> set -l res (seq 1 10 | fzf --print0 | string split0); echo $pipestatus
(^D)
0 130 1

@krobelus krobelus modified the milestones: fish-future, fish 3.2.0 Aug 5, 2020
@krobelus krobelus closed this as completed Aug 5, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants