Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
2
votes
1
answers
879
views
Is there a way to format what fzf displays without formatting its output?
I'm currently trying to write a script that takes a list of filenames with their absolute paths as input and feeds them to `fzf`. After making a selection, they are passed as command-line arguments etc. Something along the lines: ``` find $working_directory -type f | fzf -e | ... ``` Now, I do not w...
I'm currently trying to write a script that takes a list of filenames with their absolute paths as input and feeds them to
fzf
. After making a selection, they are passed as command-line arguments etc. Something along the lines:
find $working_directory -type f | fzf -e | ...
Now, I do not want to see the absolute path of every file displayed by fzf
as I feel it both looks ugly and makes it difficult to see the filenames. However, I do need the absolute paths for later on, so I do not just want to format them outright. Is there a way to format what fzf
displays without formatting the output it generates?
Utku Boduroglu
(133 rep)
Nov 8, 2022, 12:59 PM
• Last activity: Jun 20, 2025, 10:57 PM
3
votes
1
answers
167
views
get field from tree with fzf
I've tried something like this ```sh tree -C | fzf --ansi | awk -F'|' '{print $NF}' ``` ```txt ├── repo.git/ │   ├── folder/ │   │   ├── subfolder/ │   │   │   ├── output.0 │   │   │   └── traces.1 │  ...
I've tried something like this
tree -C | fzf --ansi | awk -F'|' '{print $NF}'
├── repo.git/
│ ├── folder/
│ │ ├── subfolder/
│ │ │ ├── output.0
│ │ │ └── traces.1
│ │ ├── subfolder/
│ │ │ └── fold/
│ │ │ └── subtree/
│ │ │ ├── .gitignore
│ │ │ ├── stamp-h1 item
│ │ │ └── stamp-h2
I want to grab stamp-h1 item
, in other words the filename
testoflow
(137 rep)
Oct 20, 2022, 07:26 PM
• Last activity: Jun 20, 2025, 02:39 PM
1
votes
2
answers
1077
views
Cannot Display Bash Functions within FZF Preview Window
**How do I get the FZF Preview Window to Display Functions from my Current Bash Environment?** I want to list my custom bash functions using FZF, and view the code of a selected function in the FZF Preview Window. However, it does not appear that the bash enviroment used by FZF to execute my command...
**How do I get the FZF Preview Window to Display Functions from my Current Bash Environment?**
I want to list my custom bash functions using FZF, and view the code of a selected function in the FZF Preview Window.
However, it does not appear that the bash enviroment used by FZF to execute my command can see the functions in my terminal bash environment. For example:
However, the following works:
$ declare -F | fzf --preview="type {3}"
/bin/bash: line 1: type: g: not found

$ declare -F
declare -f fcd
declare -f fz
declare -f g
$ type g
g is a function
g ()
{
search="";
for term in $@;
do
search="$search%20$term";
done;
nohup google-chrome --app-url "http://www.google.com/search?q=$search " > /dev/null 2>&1 &
}
declare -F | fzf --preview="echo {3}"
g # my function g()
One reason I suspect that the FZF Preview Window environment may not be able to see my terminal environment is because they have different process ID's.
$ echo $BASHPID
1129439
$ declare -F | fzf --preview="echo $BASHPID"
1208203
**How do I get the FZF Preview Window to Display Functions from my Current Bash Environment?**
user2514157
(225 rep)
Oct 21, 2022, 03:10 PM
• Last activity: Jun 11, 2025, 07:38 AM
3
votes
3
answers
2431
views
Mapfile not removing trailing newline
Sample Data: Tab separated file (TSV) ``` a.1.58 fadado/CSV https://github.com/fadado/CSV a.1.63 jehiah/json2csv https://github.com/jehiah/json2csv a.1.80 stedolan/jq https://github.com/stedolan/jq/issues/370 ``` Following selects one record using `fzf`, and stores 2nd and 3rd column to an array Lin...
Sample Data: Tab separated file (TSV)
a.1.58 fadado/CSV https://github.com/fadado/CSV
a.1.63 jehiah/json2csv https://github.com/jehiah/json2csv
a.1.80 stedolan/jq https://github.com/stedolan/jq/issues/370
Following selects one record using fzf
, and stores 2nd and 3rd column to an array Link:
mapfile -d $'\t' -t Link < <(awk 'BEGIN{FS="\t"; OFS="\t"} {print $2,$3}' "${SessionP}" | fzf)
## Issue
In the above command I have used -t
option of mapfile, but echo "${Link}"
prints a trailing new line!
**Why is it not getting eliminated?**
## Reference
- [mapfile Man Page - Linux - SS64.com](https://ss64.com/bash/mapfile.html)
Porcupine
(2156 rep)
Jul 26, 2021, 04:35 AM
• Last activity: May 30, 2025, 10:52 PM
3
votes
1
answers
219
views
Multiple selection with fzf and vim having new lines in path/file names
I have a Bash function that follows the [fzf](https://github.com/junegunn/fzf/tree/master) key-bindings in [key-bindings.bash](https://raw.githubusercontent.com/junegunn/fzf/refs/heads/master/shell/key-bindings.bash). ``` # shellcheck disable=SC2206 __fzf_edit_file__() { builtin local -a opts builti...
I have a Bash function that follows the [fzf](https://github.com/junegunn/fzf/tree/master) key-bindings in [key-bindings.bash](https://raw.githubusercontent.com/junegunn/fzf/refs/heads/master/shell/key-bindings.bash) .
# shellcheck disable=SC2206
__fzf_edit_file__() {
builtin local -a opts
builtin local edit_file file
opts=(
"+m"
--read0
"--reverse"
"--header-first"
"--scheme='path'"
'--preview-window=right:80%:wrap'
"--height" ${FZF_TMUX_HEIGHT:-80%}
"--walker='file,dir,follow,hidden'"
"--preview 'bat --color=always --wrap never {}'"
"--header='Key: [CTRL-F] Select, preview and edit file(s) in [${PWD}]'."
--bind='ctrl-z:ignore,ctrl-a:toggle-all,ctrl-s:toggle-preview,ctrl-d:preview-down,ctrl-u:preview-up'
)
# shellcheck disable=SC2091
builtin exec {edit_file}CTRL+F
• Use arrow keys to move up and down or CTRL+J, CTRL+K
• CTRL+D to scroll the file contents (or mouse scrolling, if allowed)
• CTRL+S to toggle preview window.
• Enter/return key to select
• CTRL+A to toggle all from fzf, but that is disabled now because of the +m
• TAB to select multiple files, also disable because of the +m
• ESC to exit.
---
That works as expected; the issue is when selecting multiple (with the TAB key) file/path names
with newlines embedded. The +m
option allows only a single selection. It used to be -m
and mapfile
instead of read
to allow multiple file selections, but that causes a problem.
vim
opens a new file that contains all the file or path names, including embedded newlines.
How can I fix that issue? I checked vim; doesn't appear to support null delimited input like -z
.
As far as I know, vim can handle spaces/tabs/newlines in path/file names with:
files=(*.txt)
vim -- "${files[@]}"
---
The version that works for multiple files selection, but fails with newlines.
- Remove the --read0
- Change the +m
to -m
And use mapfile
LC_ALL=C IFS= builtin mapfile -u"$edit_file" file
((${#file[*]})) && {
vim -- "${file[@]%?}"
}
```
---
Jetchisel
(1544 rep)
May 7, 2025, 09:05 PM
• Last activity: May 18, 2025, 01:18 AM
24
votes
4
answers
35115
views
fzf: ctlr-r not triggering history search on command line
I've installed fzf on debian 11 (bullseye). When I type in ctrl-r to trigger a history search, nothing happens. Works fine on my mac. I'm using zsh. UPDATE: tried adding `bindkey '^r' fzf-history-widget` to .zshrc but I just get a "no such widget" error. fzf --version reports 0.24 (devel)
I've installed fzf on debian 11 (bullseye). When I type in ctrl-r to trigger a history search, nothing happens. Works fine on my mac. I'm using zsh.
UPDATE: tried adding
bindkey '^r' fzf-history-widget
to .zshrc but I just get a "no such widget" error.
fzf --version reports 0.24 (devel)
StevieD
(1123 rep)
Aug 22, 2021, 12:35 AM
• Last activity: Apr 18, 2025, 03:27 PM
1
votes
1
answers
318
views
use fzf for all readline / bash completions
Is it somehow possible to tweak Readline in a way that always uses an interactive `fuzzy finder` (`fzf`) for making selections in Bash completions? From the GNU Bash documentation, I understand that Readline is responsible for providing this behavior. So instead of configuring my own completions to...
Is it somehow possible to tweak Readline in a way that always uses an interactive
fuzzy finder
(fzf
) for making selections in Bash completions?
From the GNU Bash documentation, I understand that Readline is responsible for providing this behavior.
So instead of configuring my own completions to use fzf
, I thought it would be easier to tweak the general behavior.
glades
(117 rep)
Sep 1, 2024, 08:51 AM
• Last activity: Mar 25, 2025, 04:11 PM
1
votes
1
answers
54
views
How do you put fzf CTRL-R into rlwrap ed?
I sourced the /usr/share/doc/fzf/examples/key-bindings.bash file so fzf works in Bash; but how do you get that to work with the `rlwrap ed` approach?
I sourced the /usr/share/doc/fzf/examples/key-bindings.bash file so fzf works in Bash; but how do you get that to work with the
rlwrap ed
approach?
mbigras
(3472 rep)
Mar 17, 2025, 07:08 AM
• Last activity: Mar 17, 2025, 09:39 AM
0
votes
1
answers
234
views
fzf: make sort by relevance the default
In the FZF README, under the section for [command line history](https://github.com/junegunn/fzf?tab=readme-ov-file#key-bindings-for-command-line), it states: CTRL-R - Paste the selected command from history onto the command-line - If you want to see the commands in chronological order, press CTRL-R...
In the FZF README, under the section for [command line history](https://github.com/junegunn/fzf?tab=readme-ov-file#key-bindings-for-command-line) , it states:
CTRL-R - Paste the selected command from history onto the command-line
- If you want to see the commands in chronological order, press CTRL-R again which toggles sorting by relevance
I find that I almost always get the best results when toggling that.
How can I configure it to be on by default for CTRL-R?
eugenevd
(156 rep)
Sep 10, 2024, 02:38 PM
• Last activity: Sep 10, 2024, 04:41 PM
0
votes
0
answers
469
views
How to setup zsh with fzf history backsearch in tmux (I get zle errors)
I am using tmux with the zsh shell. I try to setup fzf, and I do it like this (inside my zshrc): ``` eval "$(fzf --zsh)" ``` This works, as long as I am not in tmux. I can use Ctrl-R and get the fzf history search. But inside tmux this does nothing. When I try to invoke the history back search manua...
I am using tmux with the zsh shell.
I try to setup fzf, and I do it like this (inside my zshrc):
eval "$(fzf --zsh)"
This works, as long as I am not in tmux. I can use Ctrl-R and get the fzf history search. But inside tmux this does nothing.
When I try to invoke the history back search manually, I get:
❯ fzf-history-widget
fzf-history-widget:zle:14: widgets can only be called when ZLE is active
A bit of googling suggests, that I need to load zle first, but also:
❯ zmodload zsh/zle
Does not work.
What is wrong? What can I do?
Edit:
As requested, here is the the output of bindkey | grep fzf
:
❯ bindkey | grep fzf
"^I" fzf-completion
"^R" fzf-history-widget
"^T" fzf-file-widget
"^X." fzf-tab-debug
"^[c" fzf-cd-widget
Nathan
(173 rep)
May 22, 2024, 03:38 PM
• Last activity: May 22, 2024, 07:00 PM
1
votes
1
answers
80
views
How to detach a piped command from the terminal?
I want to allow the leading program(s) to operate in a standard manner and detach from the terminal once a graphical application launches. In this example `fzf` reads paths from a file, feeds the selected files and folders to the `mpv` media player: fzf [...] disables any use of the terminal and std...
I want to allow the leading program(s) to operate in a standard manner and detach from the terminal once a graphical application launches. In this example
fzf
reads paths from a file, feeds the selected files and folders to the mpv
media player:
fzf [...] disables any use of the terminal and stdin/stdout/stderr. This completely silences any message output.
>
> Unlike --really-quiet, this disables input and terminal initialization as well.
user598527
(735 rep)
Apr 24, 2024, 05:34 PM
• Last activity: Apr 26, 2024, 01:02 PM
16
votes
2
answers
24007
views
How to auto-trigger history search in zsh using fzf (fuzzy finder)?
Is it possible to trigger `fzf` history search automatically in `zsh` shell? In this [video][1], the user clicks Ctrl + r to start the history search and then starts typing. Is it possible to start the history search automatically when I start typing anything? Alternatively, is it possible to config...
Is it possible to trigger
fzf
history search automatically in zsh
shell?
In this video , the user clicks Ctrl+r to start the history search and then starts typing. Is it possible to start the history search automatically when I start typing anything? Alternatively, is it possible to configure zsh so that a new prompt always starts in the Ctrl+r mode?
kvs
(161 rep)
Aug 10, 2019, 11:49 PM
• Last activity: Jan 25, 2024, 03:00 PM
1
votes
1
answers
1325
views
Dynamically update fzf items
I am writing a script that searches the system for files and then for each file does some sanity checks, and if they pass those, I want to display them in fzf. When the item is clicked on in fzf, I want to run the file with a program. So far I have: dir="/path/to/dir" fd . $dir --size +1MB | while r...
I am writing a script that searches the system for files and then for each file does some sanity checks, and if they pass those, I want to display them in fzf. When the item is clicked on in fzf, I want to run the file with a program.
So far I have:
dir="/path/to/dir"
fd . $dir --size +1MB | while read -r line; do
file_type=$(file -b "$line")
echo "$line" | fzf
if [[ "$file_type" == "data" ]]; then
echo "$file_type"
fi
done
Basically, I search for files bigger than 1MB in the specified dir. For each file I run the file command and check if the command output returns "data". If it does, I want to add it to the fzf list.
Then, when I click on the item, I want to run the file with the full path with an app: e.g.
myapp /path/to/file/selected/in/fzf
.
The problem so far is that fzf is blocking, and I can't populate the list in the loop. Do I really have to add everything to an array first and then pipe this into fzf? Ideally that should happen in parallel, aka, I want to add new items on the fly while the search is still going, instead of waiting for it to complete.
Also I dont know how to later run the selected file.
Can someone help me with this?
Kyu96
(193 rep)
Sep 21, 2021, 06:15 PM
• Last activity: Dec 28, 2023, 09:12 AM
0
votes
1
answers
79
views
problematic script: query buku, select via fzf and then print using (again) buku
First and foremost, thank you for taking the time to review the question. I have the following script: select an array of IDs from `buku`'s database, and then use `buku` again to print information using the previously selected ids. ``` selected_ids=$(buku --print --format 3 | fzf | cut --fields=1) &...
First and foremost, thank you for taking the time to review the question.
I have the following script: select an array of IDs from
buku
's database, and then use buku
again to print information using the previously selected ids.
selected_ids=$(buku --print --format 3 | fzf | cut --fields=1)
&& test="$(buku --print $selected_ids --format 10)"
Problem: the value of test
(echo $test
) is blank when I select *multiple entries* via fzf
.
I tried multiple solutions, including piping into tr
:
selected_ids=$(buku --print --format 3 | fzf | cut --fields=1 | tr '\n' ' ' | xargs)
&& test="$(buku --print $selected_ids --format 10)
but to no avail.
My intuition suggests the problem is maybe $selected_ids
being interpreted as a whole string. Why? Because when I select via fzf
only *one entry*, the value of $test
contains the selected value.
Any suggestions?
Răzvan Petruescu
(101 rep)
Nov 29, 2023, 04:04 PM
• Last activity: Nov 29, 2023, 05:12 PM
5
votes
0
answers
1927
views
How to have the results of an `fzf` selection enter my bash history?
FZF is a lovely tool, the main issue I have is that the commands I end up running with it don't end up in my bash history. Let's say I do this ``` history | fzf ``` And I choose a command I ran recently, say `echo "hello"`. When I then go through my bash history, my most recently run command isn't `...
FZF is a lovely tool, the main issue I have is that the commands I end up running with it don't end up in my bash history.
Let's say I do this
history | fzf
And I choose a command I ran recently, say echo "hello"
. When I then go through my bash history, my most recently run command isn't echo "hello"
, it's history | fzf
. This means that I have to re-run the entire history | fzf
and find the same echo "hello"
command if I want to run it again.
Is there a way to force my selected command that I got by using fzf
into my bash history?
John Allard
(1408 rep)
May 19, 2021, 07:37 AM
• Last activity: Nov 25, 2023, 09:30 PM
0
votes
2
answers
1041
views
How do I backup/restore fzf history?
A very simple question, where is the data stored related to fzf? I'd like to copy my "fzf history" from one machine to another... Can't seem to find this mentioned anywhere.
A very simple question, where is the data stored related to fzf?
I'd like to copy my "fzf history" from one machine to another... Can't seem to find this mentioned anywhere.
Chris Stryczynski
(6603 rep)
Aug 4, 2020, 05:06 PM
• Last activity: Nov 24, 2023, 11:41 AM
0
votes
1
answers
102
views
fzf behavior changes when capturing its output
The following command works fine as expected: find ~ -type f | fzf -m --preview-window=up:30% --header "ctrl-f: selected all and exit" --bind "enter:execute(less {})" --bind "ctrl-f:select-all+accept" But if I add `>outfile.txt` or `| xclip` to the end of this command, all `--bind` options that cont...
The following command works fine as expected:
find ~ -type f | fzf -m --preview-window=up:30% --header "ctrl-f: selected all and exit" --bind "enter:execute(less {})" --bind "ctrl-f:select-all+accept"
But if I add
>outfile.txt
or | xclip
to the end of this command, all --bind
options that contain execute
action are ignored. Is this a known fault? Is there a way around it?
userene
(1856 rep)
Oct 9, 2023, 05:23 PM
• Last activity: Oct 9, 2023, 06:56 PM
0
votes
1
answers
155
views
Fuzzy finding directories is slow
I have following bash script to find git repositories. ```bash echo "$(fd -I -i -H -E '.local' -E '.cargo' -E '.password-store' -t d ^.git$ ~ -x 'echo' '{//}' | sk)" ``` `fd` pipes search results to `sk` (fzf rust alternative) as they are being found but selecting one item waits until `fd` to finish...
I have following bash script to find git repositories.
echo "$(fd -I -i -H -E '.local' -E '.cargo' -E '.password-store' -t d ^.git$ ~ -x 'echo' '{//}' | sk)"
fd
pipes search results to sk
(fzf rust alternative) as they are being found but selecting one item waits until fd
to finish. So there is like a 2 second delay from me selecting the directory using sk
to it actually being echo
ed. I can see the same behavior with fzf
too.
Is there a way to avoid the delay?
s1n7ax
(437 rep)
Jul 30, 2023, 05:42 PM
• Last activity: Jul 30, 2023, 07:41 PM
0
votes
0
answers
262
views
select menu option from a file --shell scripting
I have A question regarding the menu in shell scripting. I created a menu in shell scripting. however, in one of the options, I have a list the user can select from but the list is big, so I want the user to select the option from a file. how do we do that? ``` :select_menu cls echo. echo ==========...
I have A question regarding the menu in shell scripting. I created a menu in shell scripting. however, in one of the options, I have a list the user can select from but the list is big, so I want the user to select the option from a file. how do we do that?
:select_menu
cls
echo.
echo ====================
echo Main Menu
echo ====================
echo 1 =Airport
echo 2 =Warhouse
echo 3 =Parcel
echo 4 =Other Projects
echo ------------------------------------------------------
echo q = Quit
echo -------------------------------------------------------
set /p op="Select option:"
if "%op%"=="1" goto op1
if "%op%"=="2" goto op2
if "%op%"=="3" goto op3
if "%op%"=="4" goto op4
if "%op%"=="q" exit
:op1
color 17
cls
echo.
echo ====================
echo Airport Menu
echo ====================
echo 1 =Gotenburge
echo 2 =Heathrow
echo 3 =Brussels
echo 4 =Kiev
echo ------------------------------------------------------
echo r = Return to Main Menu
echo -------------------------------------------------------
set /p a_op="Select airport:"
if "%a_op%"=="1" echo "Contact A.N.OTher" && pause
if "%a_op%"=="2" echo "Contact B.N.OTher" && pause
if "%a_op%"=="3" echo "Contact B.N.OTher" && pause
if "%a_op%"=="4" echo "Contact C.N.OTher" && pause
if "%a_op%"=="r" goto select_menu
goto op1
:op2
echo you selected Warhouse
color 0a
pause
cls
goto begin
goto :eof
:op3
echo you selected Parcel
color fc
pause
cls
goto begin
:op4
echo you selected Other Projects
color a1
pause
cls
goto begin
:exit
In the Airport Menu, I have 250 airports as an example but I don't want to list all airports, I want the user to be able to check a separate file called Airport_list then choose the relevant option.
sun moon
(1 rep)
May 29, 2023, 11:58 AM
• Last activity: May 29, 2023, 04:45 PM
3
votes
1
answers
3376
views
How to use fzf to search within all lines of files (ignore newlines)?
The [fzf examples wiki page][1] describes how fzf can be used to fuzzy search within the content all the files of a directory. But in the examples from the wiki page, e.g. with ag --nobreak --nonumbers --noheading . | fzf the files are split up by their lines and each line is treated separately. For...
The fzf examples wiki page describes how fzf can be used to fuzzy search within the content all the files of a directory. But in the examples from the wiki page, e.g. with
ag --nobreak --nonumbers --noheading . | fzf
the files are split up by their lines and each line is treated separately.
For example a file:
hello
world
wouldn't match the search term "hello world" because the search terms are in different lines.
How can I use fzf so that it searches within the whole file and not only by lines?
Chris
(31 rep)
Mar 29, 2020, 05:27 PM
• Last activity: May 9, 2023, 06:22 AM
Showing page 1 of 20 total questions