Skip to content

Commit

Permalink
Remove hidden files from tab complete (#5729)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLimeGlass committed Jun 5, 2023
1 parent ce81e58 commit 46770eb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/ch/njol/skript/SkriptCommandTabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,28 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
// TODO Find a better way for caching, it isn't exactly ideal to be calling this method constantly
try (Stream<Path> files = Files.walk(scripts.toPath())) {
files.map(Path::toFile)
.forEach(f -> {
if (!(enable ? ScriptLoader.getDisabledScriptsFilter() : ScriptLoader.getLoadedScriptsFilter()).accept(f))
.forEach(file -> {
if (!(enable ? ScriptLoader.getDisabledScriptsFilter() : ScriptLoader.getLoadedScriptsFilter()).accept(file))
return;

String fileString = f.toString().substring(scriptsPathLength);
// Ignore hidden files like .git/ for users that use git source control.
if (file.isHidden())
return;

String fileString = file.toString().substring(scriptsPathLength);
if (fileString.isEmpty())
return;

if (f.isDirectory()) {
if (file.isDirectory()) {
fileString = fileString + fs; // Add file separator at the end of directories
} else if (f.getParentFile().toPath().toString().equals(scriptsPathString)) {
} else if (file.getParentFile().toPath().toString().equals(scriptsPathString)) {
fileString = fileString.substring(1); // Remove file separator from the beginning of files or directories in root only
if (fileString.isEmpty())
return;
}

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

// Trim off previous arguments if needed
Expand Down

0 comments on commit 46770eb

Please sign in to comment.