Skip to content

Commit

Permalink
[DOTSLASH] Prioritize executable files (withfig#290)
Browse files Browse the repository at this point in the history
* Prioritizze executables in file lists for dotslash

* Remove characters from ls -F

* Remove characters from ls -F
  • Loading branch information
ankithm28 authored Jun 26, 2021
1 parent 460bea1 commit cf7d00d
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions dev/dotslash.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,55 @@
// use to complete on files when they are the first string in a branch
const dotslashGenerator: Fig.Generator = {
script: function (context) {
let path = context[context.length - 1];

if (path.includes("/")) {
const components = path.split("/");
components.pop();
path = components.join("/");
} else {
path = ".";
}

// escape spaces in path
path = path.split(" ").join("\\");

// output full filepath for each item in `path` folder
return `ls -1AF ${path} | xargs -I '{}' echo $PWD/{} `;
},

postProcess: function (files) {
return files.split("\n").map((path) => {
const components = path.split("/");
let filename = components[components.length - 1];
const isExecutable = path.endsWith("*");
const isFolder = path.endsWith("/");

if (isFolder) {
filename = components[components.length - 2] + "/";
}

// Removes character at the end of the filepath
if (["@", "*", "%", "|"].includes(path.slice(-1))) {
filename = filename.slice(0, -1);
}

return {
name: filename,
icon: "fig:https://" + path,
description: isFolder ? "folder" : "file",
priority: isExecutable && 80,
};
});
},
trigger: "/",
filterTerm: "/",
};

export const completionSpec: Fig.Spec = {
name: "dotslash",
args: {
// This was previously just "filepaths", however, we added folders so
// users of ohmyzsh could cd into a folder by typing the folder name without `cd`
template: ["filepaths", "folders"],
generators: [dotslashGenerator],
},
};

0 comments on commit cf7d00d

Please sign in to comment.