From e43c70f6599b6e4581bf19d8caa82c17277fdb10 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Tue, 23 Nov 2021 16:05:43 -0700 Subject: [PATCH] Some OS kiss-vscode commands --- projects/kiss-vscode/src/commands/OS.kiss | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 projects/kiss-vscode/src/commands/OS.kiss 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