diff --git a/projects/kiss-vscode/src/commands/OS.kiss b/projects/kiss-vscode/src/commands/OS.kiss new file mode 100644 index 00000000..fa65a5a7 --- /dev/null +++ b/projects/kiss-vscode/src/commands/OS.kiss @@ -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))))))) \ No newline at end of file