Issue 3914 enhance Ctrl-t [bash shell]#3918
Open
eli-percepto wants to merge 2 commits intojunegunn:masterfrom
Open
Issue 3914 enhance Ctrl-t [bash shell]#3918eli-percepto wants to merge 2 commits intojunegunn:masterfrom
eli-percepto wants to merge 2 commits intojunegunn:masterfrom
Conversation
912308a to
b907a6f
Compare
1d3b746 to
ed5c2a0
Compare
This was referenced Dec 24, 2024
|
so, I've tried it. simplescreenrecorder-2024-12-24_16.42.49.mp4I picked your patch and modified the key-bindings.bash file directly, to test it. diff --git a/key-bindings.bash b/key-bindings.bash
index 2da32cb..4a7bb99 100755
--- a/key-bindings.bash
+++ b/key-bindings.bash
@@ -25,34 +25,59 @@ __fzf_defaults() {
echo "${FZF_DEFAULT_OPTS-} $2"
}
-__fzf_select__() {
- FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} \
- FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path" "${FZF_CTRL_T_OPTS-} -m") \
- FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" |
- while read -r item; do
- printf '%q ' "$item" # escape special chars
- done
-}
-
__fzfcmd() {
[[ -n "${TMUX_PANE-}" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "${FZF_TMUX_OPTS-}" ]]; } &&
echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf"
}
-fzf-file-widget() {
- local selected="$(__fzf_select__ "$@")"
- READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
- READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
+# Override defaults for improved ctrl-t experience
+__fzf_find() {
+ command ls -1t $1;
+ command find -L $1 -mindepth 2 \( -path '*/\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune \
+ -o -type f -printf '%P\n' \
+ -o -type d -printf '%P\n' \
+ -o -type l -printf '%P\n' 2> /dev/null
}
-__fzf_cd__() {
- local dir
- dir=$(
- FZF_DEFAULT_COMMAND=${FZF_ALT_C_COMMAND:-} \
- FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path" "${FZF_ALT_C_OPTS-} +m") \
- FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd)
- ) && printf 'builtin cd -- %q' "$(builtin unset CDPATH && builtin cd -- "$dir" && builtin pwd)"
+__fzf_select__() {
+ local cmd opts
+ local dir=$1
+ shift
+ cmd="${FZF_CTRL_T_COMMAND:-"__fzf_find $dir"}"
+ opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS -m"
+ eval "$cmd" |
+ FZF_DEFAULT_OPTS="$opts" $(__fzfcmd) "$@" |
+ while read -r item; do
+ if [ "$dir" == "." ]; then
+ printf '%q ' "$item" # escape special chars
+ else
+ printf '%q/%q ' "$dir" "$item"
+ fi
+ done
+}
+
+fzf-file-widget() {
+ local trailing_spaces=$(echo -n "${READLINE_LINE:0:$READLINE_POINT}" | sed "s/^.*\S//")
+ local word=$(echo -n "${READLINE_LINE:0:$READLINE_POINT}" | sed "s/\s*$//"| awk '{print $NF}')
+ local dir=$(echo "${word/#\~/$HOME}" | sed "s#/\+#/#g; s#/\$##")
+ if [[ $READLINE_POINT -eq 0 || -n "$trailing_spaces" || ! -d "$dir" ]]; then
+ local maybe_space=""
+ [[ $READLINE_POINT -gt 0 && -z "$trailing_spaces" ]] && maybe_space=" "
+ local selected="$(__fzf_select__ . "$@")"
+ if [ -n "$selected" ]; then
+ READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$maybe_space$selected${READLINE_LINE:$READLINE_POINT}"
+ READLINE_POINT=$((READLINE_POINT + ${#maybe_space} + ${#selected}))
+ fi
+ else
+ local selected="$(__fzf_select__ "$dir" "$@")"
+ if [ -n "$selected" ]; then
+ local pre_word=$((READLINE_POINT - ${#word}))
+ READLINE_LINE="${READLINE_LINE:0:$pre_word}$selected${READLINE_LINE:$READLINE_POINT}"
+ READLINE_POINT=$((pre_word + ${#selected}))
+ fi
+ fi
}
+# end of non default section
if command -v perl > /dev/null; then
__fzf_history__() {I do ctrl+t with Also made sure I am using your code only, not the old version. I checked if it is updated to new function$ type fzf-file-widget
fzf-file-widget is a function
fzf-file-widget ()
{
local trailing_spaces=$(echo -n "${READLINE_LINE:0:$READLINE_POINT}" | sed "s/^.*\S//");
local word=$(echo -n "${READLINE_LINE:0:$READLINE_POINT}" | sed "s/\s*$//" | awk '{print $NF}');
local dir=$(echo "${word/#\~/$HOME}" | sed "s#/\+#/#g; s#/\$##");
if [[ $READLINE_POINT -eq 0 || -n "$trailing_spaces" || ! -d "$dir" ]]; then
local maybe_space="";
[[ $READLINE_POINT -gt 0 && -z "$trailing_spaces" ]] && maybe_space=" ";
local selected="$(__fzf_select__ . "$@")";
if [ -n "$selected" ]; then
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$maybe_space$selected${READLINE_LINE:$READLINE_POINT}";
READLINE_POINT=$((READLINE_POINT + ${#maybe_space} + ${#selected}));
fi;
else
local selected="$(__fzf_select__ "$dir" "$@")";
if [ -n "$selected" ]; then
local pre_word=$((READLINE_POINT - ${#word}));
READLINE_LINE="${READLINE_LINE:0:$pre_word}$selected${READLINE_LINE:$READLINE_POINT}";
READLINE_POINT=$((pre_word + ${#selected}));
fi;
fi
} |
Author
|
@phanirithvij Thanks for testing :) |
|
sorry, I meant to say 0.57.0 tag |
9acc4ad to
e000483
Compare
0ca9a9d to
c368de0
Compare
c368de0 to
dfc367d
Compare
ee5da07 to
15d5399
Compare
5c19332 to
769f0db
Compare
a037ce8 to
e810b1c
Compare
e810b1c to
34d5454
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementation of issues/3914 but only for bash shell.
Modify Ctrl-t behaviour in the following way (bash shell):
ls -t1)Issue #3914