Issue
I use ag
to select filenames and pipe them into fzy
with the following script
set "$(ag -g "\.gz$" archives/ | fzy )"
echo "selected file: $1"
How can I run a function on all files in the folder archives
, so only files in are selected, that are newer than already existing files with the same name the folder itp-files/
? and pipe only those into fzy
then?
I tried something like
for f in $(ag --nonumbers -g "\.gz$" archives/); do
echo do something with $f and only output if file is older than the same in itp-files/;
done | fzy
But I am not sure how to compare the filetimes ike this
Solution
I tried something like
for f in $(ag --nonumbers -g "\.gz$" archives/); do echo do something with $f and only output if file is older than the same in tmp/; done | fzy
But I am not sure how to compare the filetimes ike this
If you like your construction for ... in ...
with ag
, you may compare timestamps like this:
for f in $(ag --nonumbers -g "\.gz$" archives/); do
fn=$(basename $f)
if [ $f -ot tmp/$fn ]; then
fzy $f
fi
done
Ajust full path of tmp
folder, if needed.
-ot
means "older than".
Narrowed solution (to provide a list of newline-separated items for fzy
):
find archives -iname "*.gz" -type f -printf "%f\n" | \
xargs -I '{}' find itp-files -name '{}' -type f -newer '{}' -printf "%f\n" | \
sort | \
fzy
Answered By - seeker Answer Checked By - Senaida (WPSolving Volunteer)