rschmitt / heatseeker

A high-performance Selecta clone, written in Rust.
MIT License
214 stars 10 forks source link

hs with multiple selections don't play nice with spaces #18

Closed louwers closed 8 years ago

louwers commented 8 years ago

Multiple selections are absolutely brilliant. I use it to quickly copy boilerplate code into the current directory, selecting only the files I need.

cp "$(find ~/src/templates -type f | hs)" .

I know parsing the output of ls and friends is supposed to be evil, but for scripts for my own convenience I see no harm in it. However, it would be nice to be able to deal with output of multiple selections that have spaces in them. For example, this:

screenshot_2016-02-21_23-13-37

Yields:

boilerplate.tex this is a nasty file.txt assignment.tex 

So there is no way to differentiate between those files. I believe the output should be:

boilerplate.tex 'this is a nasty file.txt' assignment.tex 

or at least, there should be an option to enable enable single quotes around selections that contain spaces.

Thanks for considering :smile:

rschmitt commented 8 years ago

This is an interesting point. However, if you just run ls | hs without getting echo involved, you'll see that heatseeker is already writing each selection on a separate line, so a useful delimiter is already present. You could add quotes with a loop, as in for i in $(ls | hs); echo -n \"$i\"\.

rschmitt commented 8 years ago

Note that the final character after the escaped quote is intended to be an escaped space. Instead of looping, you could add quotes with something like sed and then string everything together using paste: ls | hs | sed 's/^\|$/"/g' | paste -sd' ' -

louwers commented 8 years ago

Very useful! Didn't know about the newlines. Thank you. :-)