Replies: 1 comment 4 replies
-
You could try to escape your \$(cat /tmp/fpicker-dir)
# or
\$(</tmp/fpicker-dir) Alternatively, you could leverage the #!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
# https://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# 'fzf' executes commands with '$SHELL -c'. If your 'SHELL' is 'zsh', this script wouldn't work
# without the line below.
SHELL="$(which bash)"
# Variables are not visible to child processes unless they are exported
export SAVE_DIR="/tmp/fpicker-dir"
export FILE_PICKER_CMD="fd --hidden"
echo "." >"$SAVE_DIR"
# =================== helper functions ====================
# Send a POST request to fzf
send_request_to_fzf() {
command curl --silent --request POST --data "$1" "localhost:$FZF_PORT"
}
switch_between_dot_and_config() {
if [[ $FZF_PROMPT =~ config ]]; then
echo "." >$SAVE_DIR
else
echo "$HOME/.config" >$SAVE_DIR
fi
if [[ $FZF_PROMPT =~ Files ]]; then
send_request_to_fzf "change-prompt(Files $(<$SAVE_DIR))"
$FILE_PICKER_CMD --type file . "$(<$SAVE_DIR)"
else
send_request_to_fzf "change-prompt(Dirs $(<$SAVE_DIR))"
${FILE_PICKER_CMD} --type directory . "$(<$SAVE_DIR)"
fi
}
switch_between_files_and_directories() {
if [[ ! $FZF_PROMPT =~ Files ]]; then
send_request_to_fzf "change-prompt(Files $(<$SAVE_DIR))"
$FILE_PICKER_CMD --type file . "$(<$SAVE_DIR)"
else
send_request_to_fzf "change-prompt(Dirs $(<$SAVE_DIR))"
${FILE_PICKER_CMD} --type directory . "$(<$SAVE_DIR)"
fi
}
# Functions are not visible to child processes unless they are exported
export -f send_request_to_fzf switch_between_dot_and_config switch_between_files_and_directories
# ====================== check requirements =======================
# https://github.com/junegunn/fzf/commit/5e6788c
min_fzf_version="0.47.0"
user_version=$(fzf --version 2>&1 | grep -Eo '[0-9]+(\.[0-9]+)*' | sed q)
IFS='.' read -ra ver_parts <<<"$user_version"
IFS='.' read -ra threshold_parts <<<"$min_fzf_version"
for i in "${!threshold_parts[@]}"; do
if ((i >= ${#ver_parts[@]})) || ((ver_parts[i] < threshold_parts[i])); then
echo "Your 'fzf' version is: '$user_version'"
echo "The minimum required version is: '$min_fzf_version'."
exit 1
elif ((ver_parts[i] > threshold_parts[i])); then
break
fi
done
# ===================== let's begin ========================
fzf-tmux \
--ansi \
--bind "start:reload:$FILE_PICKER_CMD --type file . $(<$SAVE_DIR)" \
--bind "ctrl-r:reload:switch_between_dot_and_config" \
--bind "ctrl-t:reload:switch_between_files_and_directories" \
--disabled \
--header "CTRL-R: Switch between '.' and '~/config' | CTRL-T: Switch between Files/Directories" \
--listen \
--no-multi \
--preview $'[[ $FZF_PROMPT =~ Files ]] && bat --color=always {} || tree -C {}' \
--preview-window 'hidden' \
--prompt "Files $(<$SAVE_DIR)" EDIT: Updated requirement check
Note Relevant comment by the maintainer: fzf was designed to be an interactive grep rather than a framework for building TUI applications … Source: PR comment #2440 Footnotes |
Beta Was this translation helpful? Give feedback.
-
I'm trying to do something that might no be possible / easly achieveable and that is turn fzf into a more flexable and dynamic file navigator and manager that will allow for like search toggling between files and directories with a shortcut and between root, home and relative with another (or 3 one per path search if comparmise will be needed)
and does manage to reload update the picker search dir after quitting fzf and reopening fzf then press ++ctrl+t++ (but not live while in fzf changing fzf search dir using the ++ctrl+e++ and ++ctrl+r++ custome shortcuts)
Am I doing something wrong?
Beta Was this translation helpful? Give feedback.
All reactions