Created
December 15, 2021 22:30
-
-
Save akbo/fa0029d583c54c8c0992cc1fd65c3995 to your computer and use it in GitHub Desktop.
Runs Python code formatter on selected text and pastes it back
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Name: black | |
// Shortcut: command+shift+b | |
import "@johnlindquist/kit"; | |
// Change the below to fit your system | |
const tempFile = "~/scriptkit_black_temp.py"; | |
const blackPath = "~/miniconda3/bin/black"; | |
// copy selected text to clipboard | |
await getSelectedText(); | |
// run black on text | |
exec( | |
`pbpaste > ${tempFile} && ${blackPath} ${tempFile} && cat ${tempFile} | pbcopy && rm ${tempFile}` | |
); | |
// remove newline at the end of the text and paste | |
const blackened = await paste(); | |
await setSelectedText(blackened.slice(0, blackened.length - 1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment