Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to exclude certain files/files a-la .gitignore? #113

Closed
dmitry-saritasa opened this issue May 16, 2019 · 6 comments
Closed

how to exclude certain files/files a-la .gitignore? #113

dmitry-saritasa opened this issue May 16, 2019 · 6 comments

Comments

@dmitry-saritasa
Copy link

➜ find . -type f | fzy
> 
./.gitignore
./.gitmessage
./.style.yapf
./docker-compose.yml
./docs/async_processing/index.rst
./docs/jupyter/business/.ipynb_checkpoints/Time Periods-checkpoint.ipynb
./docs/jupyter/business/metrics/.ipynb_checkpoints/flow-checkpoint.ipynb
./docs/jupyter/business/metrics/.ipynb_checkpoints/worktypes_weekly_reports-checkpoint.ipynb
./docs/jupyter/business/metrics/.ipynb_checkpoints/Metrics-checkpoint.ipynb
./docs/jupyter/business/metrics/.ipynb_checkpoints/metrics-checkpoint.ipynb

so how do I exclude folders and files by extensions? For example, exclude all folders named pycache or files with .ipynb extensions?

Dmitry

@iamleot
Copy link

iamleot commented May 16, 2019 via email

@neuschaefer
Copy link
Contributor

git ls-files --cached --others --exclude-standard --recurse-submodules is also an option, but I'm not sure about the relative performance versus ag -l. (If you use git ls-files in your vim macro or similar, you should however consider adding a fallback for such cases when you aren't working in a git repo.)

@casr
Copy link
Contributor

casr commented May 17, 2019

I use this script that I made if it's helpful for others:

#!/bin/sh

# NAME
#      pfind – dumb file finder for projects
#
# SYNOPSIS
#      pfind [-n]
#
# DESCRIPTION
#      It just finds files that are checked into a project.
#
#      It does not give you any fancy options with which to filter.

usage() {
	cat <<EOF >&2
usage: $0 [-n]
EOF
}

args=$(getopt n $*)
if [ $? -ne 0 ]; then
	usage
	exit 1
fi

use_vcs=1

set -- $args
while [ $# -ne 0 ]; do
	case "$1"
	in
		-n)
			use_vcs=0; shift;;
		--)
			shift; break;;
	esac
done

if [ ${use_vcs} -eq 1 ] && git rev-parse --is-inside-work-tree >/dev/null; then
	exec git ls-files . --cached --others --exclude-standard 2>/dev/null
else
	# fallback on find but limit depth in case we are in ${HOME}, etc.
	# exec find . -maxdepth 4 -type f -print 2>/dev/null
	exec ag -l --depth 3 2>/dev/null
fi

If you do pfind -n it forces the non-git search path. I usually have this as find so that it grabs all files that aren't excluded from Git.

@casr
Copy link
Contributor

casr commented May 23, 2019

@neuschaefer Does --recurse-submodules work for you as you had it below?

git ls-files --cached --others --exclude-standard --recurse-submodules

I chucked it in my script thinking it was a nice to have that I was missing (previously I just used --cached --others --exclude-standard) but I've noticed it failing with:

fatal: ls-files --recurse-submodules unsupported mode

and checking the man page gives:

       --recurse-submodules
           Recursively calls ls-files on each submodule in the repository.
           Currently there is only support for the --cached mode.

I've updated my script above to just use --cached --others --exclude-standard for now.

@neuschaefer
Copy link
Contributor

@casr: Yes, AFAICT it works.

@casr
Copy link
Contributor

casr commented May 23, 2019

Lucky! (Thanks for checking)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants