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

use fzf to navigate through completion proposals #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

orel1
Copy link

@orel1 orel1 commented Feb 26, 2024

Hello,

I've extended the script to allow navigation through the possible completions proposed by autojump in case fzf is present in the PATH.

note: code formatting using `black`
Copy link
Owner

@fdw fdw left a comment

Choose a reason for hiding this comment

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

Thank you! Please note that this repo is mostly unmaintained, as autojump itself doesn't seem maintained anymore.

However, I had a look at your changes and I like the general idea :)


if autojump.returncode == 0:
if autojump_stdout.rstrip("\n"):
fzf = self.fm.execute_command(
Copy link
Owner

Choose a reason for hiding this comment

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

We're executing the same exact command a second time? Can't we just send the results from the first run to fzf?

Copy link
Author

Choose a reason for hiding this comment

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

yes, there's probably a better way to do it

directory = subprocess.check_output(["autojump", self.arg(1)])
directory = directory.decode("utf-8", "ignore")
directory = directory.rstrip("\n")
self.fm.cd(directory)
Copy link
Owner

Choose a reason for hiding this comment

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

Can we do an early return to save some indentation?

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure, if fzf is absent, an action must still be performed.

universal_newlines=True,
stdout=subprocess.PIPE,
)
fzf_stdout, fzf_stderr = fzf.communicate()
Copy link
Owner

Choose a reason for hiding this comment

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

Isn't there are more modern way to do this? The first branch uses subprocess directly, maybe we can align all of them and get rid of communicate? Or is this the recommended way?

Copy link
Author

Choose a reason for hiding this comment

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

To be honest, I don't know much about python ;-) , but reading the documentation, there are ways to make things simpler.

self.fm.cd(fzf_file_path)
else:
self.fm.select_file(fzf_file_path)
else: # sdtout is empty
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't we do the same handling in the first branch, without fzf?

Copy link
Author

Choose a reason for hiding this comment

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

a priori no, because in this first case we don't try to navigate through the proposals, we jump directly to the path with the highest weight in the history

)
fzf_stdout, fzf_stderr = fzf.communicate()

if fzf.returncode == 0:
Copy link
Owner

Choose a reason for hiding this comment

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

What happens if not?

Copy link
Author

Choose a reason for hiding this comment

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

Good point, the user should be notified of the error

@orel1
Copy link
Author

orel1 commented Mar 3, 2024

First of all, thank you for taking the time to provide this detailed feedback :-). There are a lot of little things to review. I'll update this first version as soon as possible.

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.

None yet

2 participants