-
Notifications
You must be signed in to change notification settings - Fork 40
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
added possibilty to paste a directory #41
Conversation
Looks really good, thanks! |
For some reason, I think the example does not work in bash. Have you tested in both bash and zsh? Also, do you know whether it is necessary to define a widget with |
In the commit b0ff00d , I slightly modified your implementation of the feature in zsh. Now both
and
should behave as intended. I particular, it seems possible to paste the result after |
That's really dope, I don't know if its possible to with bash readline,, but I'm using https://github.com/akinomyoga/ble.sh which improves bash's apabilities, I'll ask if there is a way to implement the same behavior since its quite useful. |
Ah sorry, I think wasn't testing properly (I think I was pressing
I see that the default fzf bindings Many thanks again! |
Nice, this is amazing! I agree with you that the only issue with this is that the prompt isn't redrawn when changing directory. I looked for solutions here, but the main ones don't seem to work... I was hoping something like this would work, bind '"\er": redraw-current-line'
bind -x '"\ex": fzm'
bind "\"${FZF_MARKS_JUMP:-\C-g}\":\"\\ex\\er\"" but it didn't... |
Thank you very much for this, it looks great! :) I don't think redrawing the next line and clearing the clipboards are big issues, but I noticed (unless I did something wrong in my test) that ls $(fzm) no longer works with this. Is this something you observed as well? |
Yeah, its not going to work anymore since the However there is an issue, if you paste the path in the middle of a command it will put the cursor at the end placing a space after the pasted text and deleting a character (i added this to the mapping avoid pasting the internal bash clipboard content). The gif demonstrates the issue: There is a workaround that I wanted to avoid, which defines 2 macros to save the state of the inputed command (both before and after the cursor) , and if I bind them it works correctly: However this means that I have to bind like this: bind -x '"\200": TEMP_LINE=$READLINE_LINE; TEMP_POINT=$READLINE_POINT'
bind -x '"\201": READLINE_LINE=$TEMP_LINE; READLINE_POINT=$TEMP_POINT; unset TEMP_POINT; unset TEMP_LINE'
bind -x '"\202": "fzm"'
bind '"\C-g":"\202\200\C-a\C-k\C-m\201"' It shouldn't cause any problems unless someone has these macros defined and it interferes with them. But we can assume that if they have, they'll know how to fix the problem, and it can be mentioned on the README file, I updated the pull request #43 with this fix. About the use of |
Unfortunately, the above bindings conflict with normal UTF-8 characters with the normal Bash (i.e., without What is non-trivial is that Actually, the available set of unused bytes depend on the character encoding of your terminal. If the terminal sends UTF-8 encoded characters, maybe you can think of using the UTF-8 representation of |
Hum I see... bind -x '"U+0080": TEMP_LINE=$READLINE_LINE; TEMP_POINT=$READLINE_POINT'
bind -x '"U+0081": READLINE_LINE=$TEMP_LINE; READLINE_POINT=$TEMP_POINT; unset TEMP_POINT; unset TEMP_LINE'
bind -x '"U+0082": "fzm"'
bind '"\C-g":"U+0082U+0080\C-a\C-k\C-mU+0081"' This seems to be working correctly... Any suggestions? |
Many thanks both for your input! I see that |
Maybe we can do something like this (not tested)? function set-up-fzm-bindings {
local mark1='\200' mark2='\201' mark3='\202'
# Change markers for UTF-8 encodings
local locale=${LC_ALL:-${LC_CTYPE:-$LANG}}
local rex_utf8='\.([uU][tT][fF]-?8)$'
if [[ $locale =~ $rex_utf8 ]]; then
mark1='\302\200' mark2='\302\201' mark3='\302\202'
fi
bind -x "\"$mark1\": TEMP_LINE=\$READLINE_LINE TEMP_POINT=\$READLINE_POINT"
bind -x "\"$mark2\": READLINE_LINE=\$TEMP_LINE READLINE_POINT=\$TEMP_POINT; unset -v TEMP_POINT TEMP_LINE"
bind -x "\"$mark3\": fzm"
bind "\"\C-g\":\"$mark3$mark1\C-a\C-k\C-m$mark2\""
}
set-up-fzm-bindings BTW, what is the minimal Bash version that |
Kind of, because
This works 👍 The solutions that fzf has for bind "\"\C-g\":\"fzm\C-m\"" # which wont be able to support placing text on the command line or bind "\"\C-g\":\"`fzm`\C-m\""
# which would be able to place the text but due to running on a subshell wouldn't be able to change directory So I suggest that for Bash>4 we keep the macros with For this to work I modified the function function pmark {
local selected="$(echo "${1}" | sed 's/.*: \(.*\)$/\1/' | sed "s#^~#${HOME}#")"
if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
printf '%q' "$selected"
else
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
fi
} function set-up-fzm-bindings {
if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
bind "\"\C-g\":\"fzm\C-m\""
else
local mark1='\200' mark2='\201' mark3='\202'
# Change markers for UTF-8 encodings
local locale=${LC_ALL:-${LC_CTYPE:-$LANG}}
local rex_utf8='\.([uU][tT][fF]-?8)$'
if [[ $locale =~ $rex_utf8 ]]; then
mark1='\302\200' mark2='\302\201' mark3='\302\202'
fi
bind -x "\"$mark1\": TEMP_LINE=\$READLINE_LINE TEMP_POINT=\$READLINE_POINT"
bind -x "\"$mark2\": READLINE_LINE=\$TEMP_LINE READLINE_POINT=\$TEMP_POINT; unset -v TEMP_POINT TEMP_LINE"
bind -x "\"$mark3\": fzm"
bind "\"\C-g\":\"$mark3$mark1\C-a\C-k\C-m$mark2\""
fi
if [ "${FZF_MARKS_DMARK}" ]; then
bind "\"${FZF_MARKS_DMARK}\":\"dmark\\n\""
fi
}
set-up-fzm-bindings Let me know what you think and I'll update the pull request #43 |
Sounds great to me! I think it's fine if the new feature is available with |
(sorry I mistakenly posted an incomplete comment. I deleted the incomplete comment) Thank you! Would you mind adding diff --git a/fzf-marks.plugin.bash b/fzf-marks.plugin.bash
index 4af287b..c55e25e 100644
--- a/fzf-marks.plugin.bash
+++ b/fzf-marks.plugin.bash
@@ -133,7 +133,9 @@ function jump {
function pmark {
local selected="$(echo "${1}" | sed 's/.*: \(.*\)$/\1/' | sed "s#^~#${HOME}#")"
- if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
+ if [[ $_ble_attached ]]; then
+ ble/widget/insert-string "$selected"
+ elif [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
printf '%q' "$selected"
else
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
@@ -164,7 +166,9 @@ function dmark {
}
function set-up-fzm-bindings {
- if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
+ if [[ $BLE_VERSION ]]; then
+ ble-bind -c C-g fzm
+ elif [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
bind "\"\C-g\":\"fzm\C-m\""
else
local mark1='\200' mark2='\201' mark3='\202' I think the temporary variable names |
Nice, works much better, it also updates the prompt in-place 👍 Cheers! Happy new year if that's the case 😉 ! |
Looks good to me! Thanks both, and happy new year! :) |
OK, thank you! and happy new year! It seems the new year comes just 30 minutes later in the earliest time zone! |
Hi, as sugested in issue #40 it would be great to add a way to paste the path to a directory to make it easy to do these kinds of actions
Then we can hit ctrl-k by default to paste the path and the command substitution will be replaced by the bookmark path when the comand gets executed.
Similar to what you did with the delete key, the default pasting key can be modified with $FZF_MARKS_PASTE
I don't think its possible through this script to be able to hit Ctrl-g and directly paste the path as sugested in the issue..