Skip to content

Commit

Permalink
Updating README.md and making the search directories an internal comm…
Browse files Browse the repository at this point in the history
…and.
  • Loading branch information
raguay committed Mar 13, 2023
1 parent 895d1c2 commit 1aaa0d3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 45 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ I've created multiple open source resources (I have around 80 GitHub repositorie
- Select entries by regular expressions. The regular expressions are saved and can be reused.
- A number before a hot key runs it's associated command that many times (ex: `5j` will move the cursor 5 entries down the list).
- Watches for changes in the current directory and updates accordingly.
- Changing directories in the Directory Bar (normal mode `q`) shows a list of matching entries from history and then below the current directory.
- Changing directories in the Directory Bar (normal mode `q`) shows a list of matching entries from history and then below the current directory. Pressing `Escape` leaves the Directory Bar in the original location. If you type letters after the current directory, all subdirectories are searched to match that grouping of letters and added to the dropdown list after directories in the history are displayed.
- File editor is configurable by the `~/.myeditorchoice` file (see `Editing Files` below). Otherwise, the system editor for the file type will be used.
- Quick Search - an input to type text so that any entry at that level is removed that doesn't have that text in it. Just refresh the pane to get back to normal. I think of it as a quick filter more than a quick search.
- Toggle System files/folders visibility
Expand Down Expand Up @@ -161,7 +161,6 @@ There are a few command line programs I use with Modal File Manager. They are:

- [git](https://git-scm.com/) for downloading extensions and themes.
- [ffmpeg](https://ffmpeg.org/) for getting and using video information in the Extra Panel.
- [fd](https://github.com/sharkdp/fd) for quick file finding. It's a `find` replacement written in Rust.
- For using the macOS trashcan, you have to have (`trash`)[https://github.com/andreafrancia/trash-cli] command line program installed using `brew install trash-cli`. You have to have [HomeBrew](homebrew.sh) installed on your system to use the `brew` command line program. If the program isn't installed before installing mfm, then you will need to adjust the environment variable for PATH in the preferences to make sure it is in the path.

All of the programs should be downloaded and in your shell's path. Modal File Manager doesn't assume location for anything except for it's own configuration files. But, if Modal File Manager can't find the program, you can adjust the path used in the preferences general tab (Command Prompt command is `Show Preferences`).
Expand Down
29 changes: 29 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"path/filepath"
goruntime "runtime"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -454,3 +455,31 @@ func (b *App) GetGitHubScripts() []GitHubRepos {
}
return result
}

func (b *App) SearchMatchingDirectories(path string, pat string, max int) []string {
result := make([]string, max, max)
count := 0
err := filepath.Walk(path, func(path string, info fs.FileInfo, err error) error {
if err == nil && info.IsDir() {
//
// check for a directory that matches the pattern.
//
if strings.Contains(path, pat) {
result[count] = path
count++
if count >= max {
return filepath.SkipAll
}
}
}
return nil
})
if err != nil {
b.err = err.Error()
}

//
// Return the results.
//
return result
}
25 changes: 9 additions & 16 deletions frontend/src/components/DirectoryListing.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { dirHistory } from "../stores/dirHistory.js";
import { keyProcess } from "../stores/keyProcess.js";
import { theme } from "../stores/theme.js";
import { config } from "../stores/config.js";
import { directoryListeners } from "../stores/directoryListeners.js";
const dispatch = createEventDispatcher();
Expand All @@ -21,7 +22,6 @@
let newPath = "";
let inputPath = "";
let dirlist = [];
let tryagain = false;
let pending = false;
let dirIndex = 0;
let lastDir = "";
Expand Down Expand Up @@ -76,7 +76,6 @@
el !== null &&
typeof el.getBoundingClientRect !== "undefined"
) {
var windowInner = getInnerHeight(DOM) - 31;
var boundingEl = el.getBoundingClientRect();
return {
Expand Down Expand Up @@ -250,16 +249,19 @@
async function processInput() {
let nPath = inputPath;
if (pending) {
tryagain = true;
} else {
//
// If we are already running it once, don't start another search.
//
if (!pending) {
if (
typeof path !== "undefined" &&
typeof path.fileSystem !== "undefined"
) {
pending = true;
const sep = path.fileSystem.sep;
if (nPath[nPath.length - 1] !== sep) {
var numleft = 10;
var numleft = $config.maxSearchDepth;
dirlist = [];
//
Expand All @@ -274,22 +276,13 @@
if (dirlist === null) dirlist = [];
numleft -= dirlist.length;
if (numleft > 0) {
//
// Get more from dirctory.
//
tryagain = false;
pending = true;
//
// Get rest from file system.
//
await path.fileSystem.searchdir(last, begindir, numleft, (data) => {
dirlist = dirlist.concat(data).filter((item) => item !== "");
pending = false;
dirIndex = 0;
if (tryagain) {
processInput();
}
pending = false;
});
}
}
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/components/FileManager.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@
var configFile = await OS.appendPath(configDir, "config.json");
$config = await OS.readFile(configFile);
$config = JSON.parse($config);
//
// Make sure this field is defined.
//
if (typeof $config.maxSearchDepth === "undefined") {
$config.maxSearchDepth = 100;
const cfgFile = await OS.appendPath(configDir, "config.json");
await OS.writeFile(cfgFile, JSON.stringify($config));
}
$config.OS = OS;
}
Expand Down
43 changes: 16 additions & 27 deletions frontend/src/modules/OS.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ var OS = {
},
deleteEntries: async function (entry, callback) {
let item = entry;
if (typeof entry != "string") {
if (typeof entry !== "string") {
item = await this.appendPath(entry.dir, entry.name);
}
var that = this;
Expand All @@ -250,7 +250,7 @@ var OS = {
//
if (typeof callback === "undefined") {
this.runCommandLine(
"trash '" + item + "'",
`trash '${item}'`,
[],
(err, stdout) => {
if (err) {
Expand All @@ -261,7 +261,7 @@ var OS = {
".",
);
} else {
this.runCommandLine("trash '" + item + "'", [], callback, ".");
this.runCommandLine(`trash '${item}'`, [], callback, ".");
}
} else {
//
Expand Down Expand Up @@ -348,9 +348,9 @@ var OS = {
},
allFilter: function (item) {
//
// Still, don't show the Icon and DS_Store files.
// Still, don't show the Icon and DS_Store files on macOS.
//
return !item.name.includes("Icon") && !item.name.includes(".DS_Store");
return item.name.includes("Icon") || item.name.includes(".DS_Store");
},
alphaSort: function (item1, item2) {
const a = item1.name.toLowerCase();
Expand Down Expand Up @@ -395,6 +395,7 @@ var OS = {
env: null,
shell: "",
useTrash: true,
maxSearchDepth: 100,
};

//
Expand All @@ -412,21 +413,20 @@ var OS = {
// Add directories that the user's system should have.
//
if (this.local)
if (await this.dirExists(this.localHomeDir + "/bin")) {
this.config.env.PATH =
this.localHomeDir + "/bin:" + this.config.env.PATH;
if (await this.dirExists(`${this.localHomeDir}/bin`)) {
this.config.env.PATH = `${this.localHomeDir}/bin:${this.config.env.PATH}`;
}
if (await this.dirExists("/opt/homebrew/bin")) {
this.config.env.PATH = "/opt/homebrew/bin:" + this.config.env.PATH;
this.config.env.PATH = `/opt/homebrew/bin:${this.config.env.PATH}`;
}
if (await this.dirExists("/usr/local/bin")) {
this.config.env.PATH = "/usr/local/bin:" + this.config.env.PATH;
this.config.env.PATH = `/usr/local/bin:${this.config.env.PATH}`;
}
if (await this.dirExists(this.localHomeDir + "/.cargo/bin")) {
this.config.env.PATH += ":" + this.localHomeDir + "/.cargo/bin";
if (await this.dirExists(`${this.localHomeDir}/.cargo/bin`)) {
this.config.env.PATH += `:${this.localHomeDir}/.cargo/bin`;
}
if (await this.dirExists(this.localHomeDir + "/go/bin")) {
this.config.env.PATH += ":" + this.localHomeDir + "/go/bin";
if (await this.dirExists(`${this.localHomeDir}/go/bin`)) {
this.config.env.PATH += `:${this.localHomeDir}/go/bin`;
}

//
Expand Down Expand Up @@ -574,19 +574,8 @@ var OS = {
try {
if (dir === "") dir = this.path;
if (pat !== "") {
this.runCommandLine(
`fd -i --max-results ${numEntries} -t d '${pat}' '${dir}'`,
[],
(err, data) => {
if (err) {
console.log(err);
this.lastError = err.toString();
} else {
returnFunction(data.toString().split("\n"));
}
},
dir,
);
let data = await App.SearchMatchingDirectories(dir, pat, numEntries);
returnFunction(data);
}
} catch (e) {
console.log(e);
Expand Down

0 comments on commit 1aaa0d3

Please sign in to comment.