-
Notifications
You must be signed in to change notification settings - Fork 82
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
Allow quick open with pre-populated query and non-directories #76
Conversation
Not quite. Well, as you said it only works with executables. What about for text files which is probably the most common use case? I'm indifferent though, will probably still merge this after some more thought. |
That's why we are lifting the limit while still being generic: we don't prepend My example of executables may not be good, but I hope you can get what I mean. It's literally just, if you only selected one path, we prepend |
set first_token_length 0 | ||
end | ||
|
||
if test (string length (commandline)) = $first_token_length && test (count $file_paths_selected) = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you reverse the order of the if statement for performance reasons?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can't you just test (count (commandline --tokenize) = 1)
to tell if the user only inputted one token?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you reverse the order of the if statement for performance reasons?
As you wish, but two builtins vs one builtin doesn't make any difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just
test (count (commandline --tokenize) = 1)
to tell if the user only inputted one token
- This doesn't allow it being triggered with an empty command line
<command> |
(|
indicates cursor position) is considered one token bycommandline --tokenize
, which is not desirable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good point, forgot commandline was a builtin too.
I still find the logic convoluted though. If all we want to know is if the user is still typing the first token, can't we just compare string trim (commandline) to string trim (commandline --current-token)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even test (commandline --tokenize) = (commandline --current-token)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test (commandline --tokenize) = (commandline --current-token)
Brilliant! We can even drop --tokenize
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we should keep tokenize for situations where the user accidentally included a whitespace in the front or back for whatever reason but still has the cursor on the current token. I'll add it in and test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh darn, now it doesn't work if the input is empty. Hmm...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh it's because if the commandline is empty, then (commandline --tokenize) is empty and test doesn't work
test: Missing argument at index 2
~/.config/fish/functions/__fzf_search_current_dir.fish (line 29):
if test (count $file_paths_selected) = 1 && test ""(commandline --tokenize) = ""(commandline --current-token)
^
in function '__fzf_search_current_dir'
@kidonng want me to finish this for you? |
# attempt to cd implicitly if a directory name starts with a dot) | ||
if test (count $file_paths_selected) = 1 | ||
set commandline_tokens (commandline --tokenize) | ||
set current_token (commandline --current-token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kidonng please LMK if you have a better solution to command substitution resulting in an empty string. Seems fish doesn't allow you to do "(commandline --tokenize)" so I have to use variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After further research I think this is the only way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you have to use a variable (which IMO is not bad), see https://fishshell.com/docs/current/index.html#cartesian-products.
Thanks for your work on this! ✨ |
Thanks for getting it started @kidonng! |
…kF1#76) Make the quick cd behavior trigger even if the user was starting to type a token and even if the path is not a directory. Before, it would only prepend ./ if the command line was empty and the selected path is a directory. Now, if the user was in the middle of inputting the first token and only one path is selected, then prepend ./ to the selected path so that - if the path is an executable, the user can hit Enter one more time to immediately execute it - if the path is a directory, the user can hit Enter one more time to immediately cd into it
This PR improves both #72 and #73.
./
to the only selected path if it is a file. This has two benefits:./
allows you to open a executable, just like entering a directory. (But the latter is Fish magic, while the former is not)