Skip to content

Commit 46770eb

Browse files
authored
Remove hidden files from tab complete (#5729)
1 parent ce81e58 commit 46770eb

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/main/java/ch/njol/skript/SkriptCommandTabCompleter.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,28 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
6060
// TODO Find a better way for caching, it isn't exactly ideal to be calling this method constantly
6161
try (Stream<Path> files = Files.walk(scripts.toPath())) {
6262
files.map(Path::toFile)
63-
.forEach(f -> {
64-
if (!(enable ? ScriptLoader.getDisabledScriptsFilter() : ScriptLoader.getLoadedScriptsFilter()).accept(f))
63+
.forEach(file -> {
64+
if (!(enable ? ScriptLoader.getDisabledScriptsFilter() : ScriptLoader.getLoadedScriptsFilter()).accept(file))
6565
return;
6666

67-
String fileString = f.toString().substring(scriptsPathLength);
67+
// Ignore hidden files like .git/ for users that use git source control.
68+
if (file.isHidden())
69+
return;
70+
71+
String fileString = file.toString().substring(scriptsPathLength);
6872
if (fileString.isEmpty())
6973
return;
7074

71-
if (f.isDirectory()) {
75+
if (file.isDirectory()) {
7276
fileString = fileString + fs; // Add file separator at the end of directories
73-
} else if (f.getParentFile().toPath().toString().equals(scriptsPathString)) {
77+
} else if (file.getParentFile().toPath().toString().equals(scriptsPathString)) {
7478
fileString = fileString.substring(1); // Remove file separator from the beginning of files or directories in root only
7579
if (fileString.isEmpty())
7680
return;
7781
}
7882

7983
// Make sure the user's argument matches with the file's name or beginning of file path
80-
if (scriptArg.length() > 0 && !f.getName().startsWith(scriptArg) && !fileString.startsWith(scriptArg))
84+
if (scriptArg.length() > 0 && !file.getName().startsWith(scriptArg) && !fileString.startsWith(scriptArg))
8185
return;
8286

8387
// Trim off previous arguments if needed

0 commit comments

Comments
 (0)