Sublime Text - Ignore files in search - sublimetext3

There is a way to exclude a file (javascript compresed) from my searchs in sublime text?

Find > Find In Files... (Ctrl+Shift+F on Windows, Cmd+Shift+F on Mac)
Find: string to find
Where: path/to/folder, path/to/another/folder, -*.min.js
You can either manually type the comma-separated paths into the 'Where' input field or click the ... button to the right of the field to select criteria. To exclude minified js files you would add -*.min.js

Yes!
binary_file_patterns will work.
"binary_file_patterns": ["*.svg", "*.png", "*.otf", "*.pdf", "*.jpg",
"*.png", "package-lock.json", "node_modules/*"]

Related

Exclude folder in goto (CTRL + P) in Sublime text

I can't find a tick to exclude / ignore a folder when I want to open a file with goto or with CTRL + P shortcut.
For example in a java project I want to open a file to edit some lines, as you know in a project we have src folders and target with the same compiled files, I want ignore all the files above every target folder.
I found the property makes for me
"folder_exclude_patterns": ["target",".git"]

Is there a way to tell .dockerignore to ignore all but certain packages from node_modules? [duplicate]

I have the folder application/ which I add to the .gitignore. Inside the application/ folder is the folder application/language/gr. How can I include this folder?
I've tried this
application/
!application/language/gr/
If you exclude application/, then everything under it will always be excluded (even if some later negative exclusion pattern (“unignore”) might match something under application/).
To do what you want, you have to “unignore” every parent directory of anything that you want to “unignore”. Usually you end up writing rules for this situation in pairs: ignore everything in a directory, but not some certain subdirectory.
# you can skip this first one if it is not already excluded by prior patterns
!application/
application/*
!application/language/
application/language/*
!application/language/gr/
Note
The trailing /* is significant:
The pattern dir/ excludes a directory named dir and (implicitly) everything under it.
With dir/, Git will never look at anything under dir, and thus will never apply any of the “un-exclude” patterns to anything under dir.
The pattern dir/* says nothing about dir itself; it just excludes everything under dir.
With dir/*, Git will process the direct contents of dir, giving other patterns a chance to “un-exclude” some bit of the content (!dir/sub/).
Commit 59856de from Karsten Blees (kblees) for Git 1.9/2.0 (Q1 2014) clarifies that case:
gitignore.txt: clarify recursive nature of excluded directories
An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again.
It is not possible to re-include a file if a parent directory of that file is excluded. (*)
(*: unless certain conditions are met in git 2.8+, see below)
Git doesn't list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.
Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "\!important!.txt".
Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):
--------------------------------------------------------------
$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*
!/foo/bar
--------------------------------------------------------------
In your case:
application/*
!application/**/
application/language/*
!application/language/**/
!application/language/gr/**
You must white-list folders first, before being able to white-list files within a given folder.
Update Feb/March 2016:
Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.
Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:
commit 506d8f1 for git v2.7.0, reverted in commit 76b620d git v2.8.0-rc0
commit 5e57f9c git v2.8.0-rc0,... reverted(!) in commit 5cee3493 git 2.8.0.
So with git 2.9+, this could have actually worked, but was ultimately reverted:
application/
!application/language/gr/
#Chris Johnsen's answer is great, but with a newer versions of Git (1.8.2 or later), there is a double asterisk pattern you can leverage for a bit more shorthand solution:
# assuming the root folder you want to ignore is 'application'
application/**/*
# the subfolder(s) you want to track:
!application/language/gr/
This way you don't have to "unignore" parent directory of the subfolder you want to track.
With Git 2.17.0 (Not sure how early before this version. Possibly back to 1.8.2), using the ** pattern combined with excludes for each subdirectory leading up to your file(s) works. For example:
# assuming the root folder you want to ignore is 'application'
application/**
# Explicitly track certain content nested in the 'application' folder:
!application/language/
!application/language/gr/
!application/language/gr/** # Example adding all files & folder in the 'gr' folder
!application/language/gr/SomeFile.txt # Example adding specific file in the 'gr' folder
I've found only this actually works.
**/node_modules/*
!**/node_modules/keep-dir
There are a bunch of similar questions about this, so I'll post what I wrote before:
The only way I got this to work on my machine was to do it this way:
# Ignore all directories, and all sub-directories, and it's contents:
*/*
#Now ignore all files in the current directory
#(This fails to ignore files without a ".", for example
#'file.txt' works, but
#'file' doesn't):
*.*
#Only Include these specific directories and subdirectories:
!wordpress/
!wordpress/*/
!wordpress/*/wp-content/
!wordpress/*/wp-content/themes/
!wordpress/*/wp-content/themes/*
!wordpress/*/wp-content/themes/*/*
!wordpress/*/wp-content/themes/*/*/*
!wordpress/*/wp-content/themes/*/*/*/*
!wordpress/*/wp-content/themes/*/*/*/*/*
Notice how you have to explicitly allow content for each level you want to include. So if I have subdirectories 5 deep under themes, I still need to spell that out.
This is from #Yarin's comment here: https://stackoverflow.com/a/5250314/1696153
These were useful topics:
How do negated patterns work in .gitignore?
How do gitignore exclusion rules actually work?
I also tried
*
*/*
**/**
and **/wp-content/themes/**
or /wp-content/themes/**/*
None of that worked for me, either. Lots of trial and error!
The simplest and probably best way is to try adding the files manually (generally this takes precedence over .gitignore-style rules):
git add /path/to/module
You might need -f if the file is already ignored. You may even want the -N intent to add flag, to suggest you will add them, but not immediately. I often do this for new files I’m not ready to stage yet.
This a copy of an answer posted on what could easily be a duplicate QA. I am reposting it here for increased visibility—I find it easier not to have a mess of gitignore rules.
I have found a similar case here, where in laravel by default, .gitignore ignores all using asterix, then overrides the public directory.
( This is also the same solution as the main answer #Chris Johnsen, just a bit thinner and more concise maybe.)
*
!public
!.gitignore
This is not sufficient if you run into the OP scenario.
If you want to commit a specific subfolders of public, say for e.g. in your public/products directory you want to include files that are one subfolder deep e.g. to include public/products/a/b.jpg they wont be detected correctly, even if you add them specifically like this !/public/products, !public/products/*, etc..
The solution is to make sure you add an entry for every path level like this to override them all.
*
!.gitignore
!public/
!public/*/
!public/products/
!public/products/*
!public/products/*/
!public/products/*/
!public/products/*/*
I wanted to track Nagios configuration files located in /etc/nagios/ together with the plugins in /usr/lib64/nagios/plugins/. For this I have initialized a git repo in / and used the following exclusion list:
/*
!etc
etc/*
!etc/nagios
!usr
usr/*
!usr/lib64
usr/lib64/*
!usr/lib64/nagios
usr/lib64/nagios/*
!usr/lib64/nagios/plugins
Git walks down the list like that:
/* exclude everything under / ...
!etc but include /etc back
etc/* exclude everything under /etc/...
!etc/nagios but include /etc/nagios back
!usr but include /usr back
usr/* exclude everything under /usr/...
and so on...
add a file named .gitignore to subfolder, then fill with
!/Bin/
this works for me!
So , since many programmers uses node . the use case which meets this question is to exclude node_modules except one module module-a for example:
!node_modules/
node_modules/*
!node_modules/module-a/
Add an additional answer:
!/.vs/ <== include this folder to source control, folder only, nothing else
/.vs/* <== but ignore all files and sub-folder inside this folder
!/.vs/ProjectSettings.json <== but include this file to source control
!/.vs/config/ <== then include this folder to source control, folder only, nothing else
!/.vs/config/* <== then include all files inside the folder
here is result:
This worked for me:
**/.idea/**
!**/.idea/copyright/
!.idea/copyright/profiles_settings.xml
!.idea/copyright/Copyright.xml
gitignore - Specifies intentionally untracked files to ignore.
Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):
$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*
!/foo/bar
Another example for WordPress:
!/wp-content
wp-content/*
!/wp-content/plugins
wp-content/plugins/*
!wp-content/plugins/my-awesome-plugin
More informations in here: https://git-scm.com/docs/gitignore
my JetBrains IntelliJ IDEA .gitignore configuration, where I need exclude wholde .idea folder except .idea/runConfigurations:
.idea
!.idea/
.idea/*
!.idea/runConfigurations/
see: https://github.com/daggerok/gitignore-idea-runConfigurations
Especially for the older Git versions, most of the suggestions won't work that well.
If that's the case, I'd put a separate .gitignore in the directory where I want the content to be included regardless of other settings and allow there what is needed.
For example:
/.gitignore
# ignore all .dll files
*.dll
/dependency_files/.gitignore
# include everything
!*
So everything in /dependency_files (even .dll files) are included just fine.
In WordPress, this helped me:
wp-admin/
wp-includes/
/wp-content/*
!wp-content/plugins/
/wp-content/plugins/*
!/wp-content/plugins/plugin-name/
!/wp-content/plugins/plugin-name/*.*
!/wp-content/plugins/plugin-name/**
Just another example of walking down the directory structure to get exactly what you want. Note: I didn't exclude Library/ but Library/**/*
# .gitignore file
Library/**/*
!Library/Application Support/
!Library/Application Support/Sublime Text 3/
!Library/Application Support/Sublime Text 3/Packages/
!Library/Application Support/Sublime Text 3/Packages/User/
!Library/Application Support/Sublime Text 3/Packages/User/*macro
!Library/Application Support/Sublime Text 3/Packages/User/*snippet
!Library/Application Support/Sublime Text 3/Packages/User/*settings
!Library/Application Support/Sublime Text 3/Packages/User/*keymap
!Library/Application Support/Sublime Text 3/Packages/User/*theme
!Library/Application Support/Sublime Text 3/Packages/User/**/
!Library/Application Support/Sublime Text 3/Packages/User/**/*macro
!Library/Application Support/Sublime Text 3/Packages/User/**/*snippet
!Library/Application Support/Sublime Text 3/Packages/User/**/*settings
!Library/Application Support/Sublime Text 3/Packages/User/**/*keymap
!Library/Application Support/Sublime Text 3/Packages/User/**/*theme
> git add Library
> git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: Library/Application Support/Sublime Text 3/Packages/User/Default (OSX).sublime-keymap
new file: Library/Application Support/Sublime Text 3/Packages/User/ElixirSublime.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/Package Control.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/Preferences.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/RESTer.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/SublimeLinter/Monokai (SL).tmTheme
new file: Library/Application Support/Sublime Text 3/Packages/User/TextPastryHistory.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/ZenTabs.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/adrian-comment.sublime-macro
new file: Library/Application Support/Sublime Text 3/Packages/User/json-pretty-generate.sublime-snippet
new file: Library/Application Support/Sublime Text 3/Packages/User/raise-exception.sublime-snippet
new file: Library/Application Support/Sublime Text 3/Packages/User/trailing_spaces.sublime-settings
Similar to this comment, none of the solutions and patterns worked for me; forcing git to add the files and folders that should be excluded, worked:
git add -f .
I wanted to track jquery production js files and this worked:
node_modules/*
!node_modules/jquery
node_modules/jquery/*
!node_modules/jquery/dist/*
I often use this workaround in CLI where instead of configuring my .gitignore, I create a separate .include file where I define the (sub)directories I want included in spite of directories directly or recursively ignored by .gitignore.
Thus, I additionally use
git add `cat .include`
during staging, before committing.
To the OP, I suggest using a .include which has these lines:
<parent_folder_path>/application/language/gr/*
NOTE: Using cat does not allow usage of aliases (within .include) for specifying $HOME (or any other specific directory). This is because the line homedir/app1/*
when passed to git add using the above command appears as git add 'homedir/app1/*', and enclosing characters in single quotes ('') preserves the literal value of each character within the quotes, thus preventing aliases (such as homedir) from functioning (see Bash Single Quotes).
Here is an example of a .include file I use in my repo here.
/home/abhirup/token.txt
/home/abhirup/.include
/home/abhirup/.vim/*
/home/abhirup/.viminfo
/home/abhirup/.bashrc
/home/abhirup/.vimrc
/home/abhirup/.condarc

Automatically renames files with correct file extention in bulk

I have a folder with multiple types of file ( mp4, mp4, jpg, wma .etc) and these files have either have no extension, or all messed up extensions extension such as mp3.mp3, mp3.jpg, or just file name. I was reading that exiftool or even python magic can be used to assign correct file extension on understanding filetype. I am looking for exiftool based solution where these file can be renamed with correct file extension.
eg
filename (this is mp3 file)
filename1.jpg ( this is again mp3 file, with jpg as file extension)
filename.mp3.mp3.mp3 (repetition of extension)
At the simplest, try this (change double quotes to single quotes if on Mac/Linux):
exiftool -ext "*" "-filename<$filename.$filetype" TargetDir
or
exiftool -ext "*" "-testname<%f.$filetype" TargetDir
That will simply add the extension all the files in TargetDir. To recurse, add -r. If there was already an extension, this will add the proper extension at the end of the false extension e.g. filename.mp3 would become filename.mp3.jpeg.
For a more complex version which strips away some of the previous, false extensions, you could try something like this:
exiftool -ext "*" "-filename<${filename;s/(\.(mp3|mp4|jpe?g|png|wma|mov))*($)//i}%-c.$filetype" TargetDir
which would strip away extensions that are in the center parens in the regex. The %-c will add a number if the resulting rename would be a duplicate e.g. filename.jpeg, filename-1.jpeg, … filename-n.jpeg.
Edit: added -ext option to deal with files without an extension.

Hiding files/directories from goto menu, but keep in project tree [duplicate]

For a large project with many dependencies e.g. in the node_modules/ folder, I noticed frequent CPU spikes because of Sublime indexing all the files in the folder.
I know I can hide files and folders using the folder_exclude_patterns setting, but I still want the folder to be visible in the sidebar.
How can I keep e.g. node_modules/ in the sidebar, but exclude it from indexing?
To exclude files from the index but keep them in the sidebar, use the binary_file_patterns setting in your User Settings, for example:
"binary_file_patterns": [
"*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds",
"*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip",
"node_modules/**",
"bower_components/**"
]
Make sure to copy the values from your Settings - Default preferences (here shown as "*.jpg" etc.), or you will start indexing binary files.
You can change your personal settings, in Preferences -> Settings - User, add:
{
"folder_exclude_patterns":
[
".svn", ".git", ".hg", "CVS",
"node_modules",
],
}
Sublime Text 3 now provides a way to exclude files and folders from indexing while keeping them in the sidebar:
"index_exclude_patterns": [
"*.log",
"node_modules/*"
]
On my project I observed the following improvement in the indexing status menu after applying changes:
Before:
index "MyApp" collated in 0.70s from 73934 files
index "MyApp" is using 15167488 bytes for 54234 symbols across 1357673 locations
After:
index "MyApp" collated in 0.00s from 137 files
index "MyApp" is using 61440 bytes for 730 symbols across 4763 locations
Doesn't work in ST3 (Build 3126).
You can show node modules folders in sidebar and hide files inside this way :
"file_exclude_patterns":
[
...,
"node_modules/**"
]
If you want to hide subfolders from each node module :
"folder_exclude_patterns":
[
"node_modules/*/**"
]
All files inside node_modules will be removed from search, but each node_module subfolder will be still visible in sidebar.
I thought binary_file_patterns wasn't working, because I am in the habit of right-clicking my top level folder and choosing "Find in folder". folder_exclude_patterns works with this but binary_file_patterns still searches everything - because the "Where" field overrides the setting.
So you can either use the menu option Find > Find in files OR right click-your top level folder, choose "Find in folder" and then delete the text in the "Where" field so it shows the placeholder text "Open files and folders".
Obviously you still have to add this to Preferences/Settings:
"binary_file_patterns": [
"node_modules/",
],

How to ignore .svn folder when searching in Total Commander

How can I ignore .svn folders when searching in Total Commander?
To exclude some files or folders from your search, use the following syntax in "Search field:":
Exclude from search *.bak and *.old files
my*.*|*.bak *.old
Don't search in .svn folders
*.cs|.svn\
Don't search in .git folder
*.cs|.git\
The meaning of | is: 'and not'. Everything after it is excluded from the search. This syntax can also be used in other places, for example inside the ignore list.
With Total Commander 8.01: Configuration menu / Options / (Operation) / Ignore List
With older versions: Configuration menu / Options / (Display) / Ignore List
Then add
.svn
to the textbox.
In my case I tried search text, but exclude searching in directories bin and obj. I didn't know that pattern before pipe is required too, but I found help here:
https://gist.github.com/DStereo/af5f54c2d2d0d7073383f22753396185
So I had to put pattern in Search for field.
*|bin\ obj\
In version 9.12 you should also use an asterix.
So add the following to Configuration menu / Options / (Operation) / Ignore List:
*.svn

Resources