Skip to content

Conversation

@schorsch3000
Copy link

What?

This pullrequest allows sd to run fzf on a non-found target.

Why?

i use sd on several boxes with auto-generated targets.
E.g.: a webserver with a folder per vhost.
Often i don't remember if the folder is called example.com or www.example.com or even www.example.net (and the others are aliases).
The sd autocompletion can't help here.
with that feature i'm able to call sd example and get fzf prefiltered.

How was it tested?

At this point in time: only by using it.

Additional work for this pull request

I don't expect you to merge this pull request in it's current state.
This is the code i'm using, it's not tested and not documented.

If this change is okay for you to have, i would prefer to get familiar with shpec, write some tests, document that feature before that gets merged.

So, what do you think?

@rylnd
Copy link
Owner

rylnd commented Oct 12, 2016

@schorsch3000 thanks for this! I wasn't aware of fzf, it definitely looks neat. My preference would be to just automatically use fzf for completion if it's available, and fall back to the default if not.

I would appreciate a test or two and some documentation, but I definitely like the sentiment behind this PR. Good luck, and let me know if you have any questions!

@rylnd
Copy link
Owner

rylnd commented Oct 12, 2016

Also, 👍 👍 👍 on the comprehensive PR description 😍

@rylnd
Copy link
Owner

rylnd commented Oct 12, 2016

One other thought I had: if the goal is just to provide 'fuzzy' completion (i.e. not just from the beginning), that might be accomplished just by changing the regular expressions etc. in the _sd_autocomplete function (unless I'm totally forgetting how bash autocompletion works).

@schorsch3000
Copy link
Author

I've wrapped a lot of shellscripts around fzf since i learned about it, i'm quite fast with it, maybe that's why i've choose to use fzf instead of a fuzzy-regex for autocompletion.

So, i've removed the ENV-var that enabled fzf and use it whenever a target-point is not availible and fzf is in $PATH.

I've added a message if the target is nonexistent and fzd i not in PATH. I'm not sure if i as a user not using fzf would be happy to be pointed to it every time i mistyped a point or not.
What's your thought on that?

I've also added some test-cases using shpec, and man is that awesome, i'm going to use that from now on.

And finally, i've documented that there is a fzf-feature.

@schorsch3000
Copy link
Author

Hi,
whats the status on this one?
Is there anything left to do that i can do?
Greetings Schorsch

@rylnd
Copy link
Owner

rylnd commented Nov 7, 2016

Sorry @schorsch3000, feedback incoming.

Copy link
Owner

@rylnd rylnd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schorsch3000 this is looking great, thanks. There're just a few style quibbles and some portability issues (OSX in particular).

sd Outdated

type fzf >/dev/null 2>&1 || {
echo "Can't shift to point '$requested_point' because it doesn't exist."
echo "Also fzf issn't in path so we can't fuzzy find a match, sorry."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave the messaging as it was; there's no need to remind the user of the features they haven't opted into.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, i'll just remove tha extra line :)

sd Outdated
echo "Also fzf issn't in path so we can't fuzzy find a match, sorry."
return 1
}
point_path="$sdd/$(find "$sdd" -maxdepth 1 -type l -printf "%f\n"|fzf -q "$*")"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OSX version of find does not have the printf option. Can you do this another way?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, -exec should do the trick.

sd Outdated
if [ "$?" -ne "0" ] ; then
return 1
fi

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete unnecessary whitespace here.

end
describe "using fzf"
it "should use fzf if availible"
cd /tmp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation should be two spaces, please.

 - remove extra message about fzf not existent
 - osx find not havong -printf, using -exec basename instead
 - multiple whitespace issue
@schorsch3000
Copy link
Author

having find execute basename results in several warnings like:
find: 'basename' terminated by signal 13
which is caused by stubbing fzf in the test-case.
having the stub read stdin seems not to help either.
the test will run fine with these warnings.
Do you know anything to prevent the stub from breaking the pipe?

@schorsch3000
Copy link
Author

should we do anything about the warning while running tests?
Is there something else that should be done before merging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants