Skip to content

Commit da27ca6

Browse files
committed
fix(extension.js): faster way to open yazi
1 parent 324ba7f commit da27ca6

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

extension.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ function setNeovimPath(homeExtension) {
4747
}
4848

4949
// remove ~/.vscode/extensions/yefery.retronvim created by retronvim/nvim/init.lua when retronvim extensions was not installed previously
50-
if (fs.existsSync(nvimPath)) {
51-
fs.rmSync(nvimPath, { recursive: true })
52-
}
50+
fs.existsSync(nvimPath) && fs.rmSync(nvimPath, { recursive: true })
5351

5452
// decompress terminal dependencies
5553
if (os.platform() == "win32" && fs.existsSync(gitPathWindows) === false) {
@@ -80,9 +78,9 @@ function setNeovimPath(homeExtension) {
8078
config.update('vscode-neovim.neovimExecutablePaths.linux', nvimPathUnix, vscode.ConfigurationTarget.Global)
8179
config.update('vscode-neovim.neovimExecutablePaths.darwin', nvimPathUnix, vscode.ConfigurationTarget.Global)
8280
config.update('vscode-neovim.neovimExecutablePaths.win32', nvimPathWindows, vscode.ConfigurationTarget.Global)
83-
config.update('vscode-neovim.neovimInitVimPaths.linux', initDotLuaPath, vscode.ConfigurationTarget.Global)
84-
config.update('vscode-neovim.neovimInitVimPaths.darwin', initDotLuaPath, vscode.ConfigurationTarget.Global)
85-
config.update('vscode-neovim.neovimInitVimPaths.win32', initDotLuaPath, vscode.ConfigurationTarget.Global)
81+
config.update('vscode-neovim.neovimInitVimPaths.linux', initDotLuaPath, vscode.ConfigurationTarget.Global)
82+
config.update('vscode-neovim.neovimInitVimPaths.darwin', initDotLuaPath, vscode.ConfigurationTarget.Global)
83+
config.update('vscode-neovim.neovimInitVimPaths.win32', initDotLuaPath, vscode.ConfigurationTarget.Global)
8684
}
8785

8886
// You can call this function in your extension's activate function or based on certain events
@@ -104,6 +102,7 @@ function activate(context) {
104102
const init_lua = path.join(context.extensionPath, '/nvim/init.lua')
105103
const yazi_config_home = path.join(context.extensionPath, '/yazi')
106104
const yazi_file_one = path.join(context.extensionPath, '/bin/windows/envs/windows/Library/usr/bin/file.exe')
105+
const yazi_choosen_file = path.join(home, '/.yazi')
107106
const mingw_path = path.join(context.extensionPath, '/bin/windows/envs/windows/Library/mingw64/bin;')
108107
const win_path = retronvim_bin + `;${home}\\.pixi\\bin;${home}\\.local\\bin;${home}appdata\\local\\pnpm;` + mingw_path + process.env.PATH
109108
const unix_path = retronvim_bin + `:${home}/pixi/bin:${home}/.local/bin:${home}/Library/pnpm:${home}/Library/pnpm:` + process.env.PATH
@@ -112,25 +111,42 @@ function activate(context) {
112111

113112
let open_yazi = vscode.commands.registerCommand("retronvim.yazi", () => {
114113
let curr_file = vscode.window.activeTextEditor?.document.uri.fsPath || ""
114+
let yazi_args = curr_file ? ["--chooser-file", yazi_choosen_file, curr_file] : ["--chooser-file", yazi_choosen_file]
115+
116+
fs.existsSync(yazi_choosen_file) && fs.rmSync(yazi_choosen_file)
115117

116118
let yaziTerminal = vscode.window.createTerminal({
117119
name: "Yazi",
118120
shellPath: "yazi",
119-
shellArgs: curr_file ? [curr_file] : [],
121+
shellArgs: yazi_args,
120122
location: vscode.TerminalLocation.Editor,
121123
env: {
122-
BAT_THEME:"base16",
123-
EDITOR: "code",
124+
// EDITOR: "code",
125+
// YAZI_CMD: 'ya emit quit',
126+
BAT_THEME: "base16",
124127
FZF_DEFAULT_OPTS: fzf_preview,
125128
PATH: get_path,
126129
VIMINIT: `lua vim.cmd.source([[${init_lua}]])`,
127130
YAZI_CONFIG_HOME: yazi_config_home,
128131
YAZI_FILE_ONE: get_yazi_file_one,
129-
YAZI_CMD: 'ya emit quit',
130132
},
131133
})
132134

133135
// yaziTerminal.show(); // not required if vscode.TerminalLocation.Editor
136+
137+
// https://github.com/dautroc/yazi-vscode/blob/main/src/extension.ts
138+
const closeSubscription = vscode.window.onDidCloseTerminal(async (terminal) => {
139+
if (terminal === yaziTerminal && fs.existsSync(yazi_choosen_file)) {
140+
141+
const filePaths = fs.readFileSync(yazi_choosen_file, "utf8").trim().split('\n')
142+
143+
for (const filePath of filePaths) {
144+
const doc = await vscode.workspace.openTextDocument(filePath);
145+
await vscode.window.showTextDocument(doc, { preview: false });
146+
}
147+
}
148+
closeSubscription.dispose();
149+
})
134150
})
135151

136152
let open_lazygit = vscode.commands.registerCommand("retronvim.lazygit", () => {

yazi/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
require("session"):setup { sync_yanked = true }
21
require("bookmarks"):setup()
2+
require("session"):setup { sync_yanked = true }
3+
require("smart-enter"):setup { open_multi = true }
34

45
Status:children_add(function(self)
56
local h = self._current.hovered

0 commit comments

Comments
 (0)