I want to use fzf to list all files in git, sorted by modification date. (I use this output in vim)
This command seems to work:
(while read file; do echo $(git log --pretty=format:%ad -n 1 --date=raw -- $file) $file; done < <(git ls-tree -r --name-only HEAD) | sort -k1,1n | awk {"print \$3"}) 2> /dev/nul
But how can I get this as the default FZF command? I tried this, but the variable FZF_DEFAULT_COMMAND remains empty:
export FZF_DEFAULT_COMMAND='
(while read file; do echo $(git log --pretty=format:%ad -n 1 --date=raw -- $file) $file; done < <(git ls-tree -r --name-only HEAD) | sort -k1,1n | awk {"print \$3"}) 2> /dev/null'
Maybe I need to escape something?
Edit: This is the command I'm now using:
export FZF_DEFAULT_COMMAND='(git ls-tree -r --name-only HEAD)|(while read file; do echo $(git log --pretty=format:%ad -n 1 --date=raw -- "$file") $file; done | sort -r | awk {"print \$3"}) 2> /dev/null'
fzf
uses /bin/sh
(Posix shell) to execute your command . Even if /bin/sh
is linked to /bin/bash
it will fail on non posix features (like process substitution in your case). You can enforce GNU/bash support:
export FZF_DEFAULT_COMMAND='set +o posix
(while read file; do echo $(git log --pretty=format:%ad -n 1 --date=raw -- $file) $file; done < <(git ls-tree -r --name-only HEAD) | sort -k1,1n | awk {"print \$3"}) 2> /dev/null'
If you don't have bash
symlinked to /bin/sh
, you have to get rid of the process substitution:
export FZF_DEFAULT_COMMAND='
(git ls-tree -r --name-only HEAD)|(while read file; do echo $(git log --pretty=format:%ad -n 1 --date=raw -- $file) $file; done | sort -k1,1n | awk {"print \$3"}) 2> /dev/null'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.