Some OS kiss-vscode commands

This commit is contained in:
2021-11-23 16:05:43 -07:00
parent 7d6adc1760
commit e43c70f659

View File

@@ -0,0 +1,34 @@
// Operating system commands. Hopefully cross-compatible with Windows, Mac, and Ubuntu.
// Before you use commands in this file:
/* (loadFrom "kiss-vscode" "src/commands/OS.kiss") */
// Open any file through the operating system's default program.
// Register this command as follows:
/*
(registerCommand "desired name with [a]ny [b]indings" osOpenFile)
// Or for a specific file:
(registerCommand "desired name with [a]ny [b]indings" ->[&opt _] (osOpenFile "path/to/file.any"))
*/
(function :Void osOpenFile [&opt :String file]
(withValueOrInputBox file
(case (Sys.systemName)
("Windows" (assertProcess "cmd.exe" ["/C" "start" file]))
("Mac" (assertProcess "open" [file]))
("Linux" (assertProcess "xdg-open" [file]))
(otherwise (throw "Unsupported operating system")))))
/*
(registerCommand "desired name with [a]ny [b]indings" osOpenFileInDir)
// Or for a specific directory:
(registerCommand "desired name with [a]ny [b]indings" ->[&opt _] (osOpenFileInDir "path/to/dir"))
*/
(function :Void osOpenFileInDir [&opt :String dir]
(withValueOrInputBox dir
(awaitLet [dirOrFile (quickPick (sys.FileSystem.readDirectory dir))]
(let [dirOrFile (joinPath dir dirOrFile)]
(cond
((sys.FileSystem.isDirectory dirOrFile)
(osOpenFileInDir dirOrFile))
(true
(osOpenFile ~dirOrFile)))))))