From 85500377ff8e1b5a0f8f617be83f2a93ba26cbe6 Mon Sep 17 00:00:00 2001 From: Thiago Mendonca Date: Sun, 19 Mar 2023 16:49:14 +0100 Subject: [PATCH] feat(tools): remove scriptkit --- TOOLS_DOCS.md | 12 -- configure/scriptkit/.scripts/homebrew.mjs | 20 -- configure/scriptkit/package.json | 8 - configure/scriptkit/scriptkit.sh | 117 ----------- .../scripts/download-youtube-video.js | 194 ------------------ configure/scriptkit/scripts/homebrew.ts | 33 --- configure/scriptkit/scripts/jira-issues.js | 179 ---------------- configure/scriptkit/scripts/kill-port.js | 24 --- .../scriptkit/scripts/open-jira-ticket.js | 17 -- .../scriptkit/scripts/open-project-vs-code.js | 47 ----- 10 files changed, 651 deletions(-) delete mode 100644 configure/scriptkit/.scripts/homebrew.mjs delete mode 100644 configure/scriptkit/package.json delete mode 100755 configure/scriptkit/scriptkit.sh delete mode 100644 configure/scriptkit/scripts/download-youtube-video.js delete mode 100644 configure/scriptkit/scripts/homebrew.ts delete mode 100644 configure/scriptkit/scripts/jira-issues.js delete mode 100644 configure/scriptkit/scripts/kill-port.js delete mode 100644 configure/scriptkit/scripts/open-jira-ticket.js delete mode 100644 configure/scriptkit/scripts/open-project-vs-code.js diff --git a/TOOLS_DOCS.md b/TOOLS_DOCS.md index 952b434..7ac58b0 100644 --- a/TOOLS_DOCS.md +++ b/TOOLS_DOCS.md @@ -68,15 +68,3 @@ To be able to run it (and when the computer is started) 1. Copy the net.duplicati.server.plist file from 'tools' folder and save it to `/Library/LaunchAgents` 2. Access Duplicate in the browser with [http://localhost:8200](http://localhost:8200/) - -## ScriptKit - -ScriptKit is a command-line tool that allows you to run JavaScript scripts from the command line. It is built on top of the V8 JavaScript engine and Node.js. - -It needs to be installed manually as there is no Homebrew formula for it. - -Download the latest version from [here](https://www.scriptkit.com/) and then execute the configure script to install all custom scripts - -```bash - ./configure/scriptkit/scriptkit.sh -``` diff --git a/configure/scriptkit/.scripts/homebrew.mjs b/configure/scriptkit/.scripts/homebrew.mjs deleted file mode 100644 index 336515d..0000000 --- a/configure/scriptkit/.scripts/homebrew.mjs +++ /dev/null @@ -1,20 +0,0 @@ -// Users/todd/Documents/Thiago/Repos/dotfiles/configure/scriptkit/scripts/homebrew.ts -import "@johnlindquist/kit"; -var query = await arg("Search homebrew"); -var response = await get(`https://formulae.brew.sh/api/formula/${query.trim()}.json`); -var { name } = response.data; -var bins = await readdir(`/opt/homebrew/bin`); -var installed = bins.includes(name); -if (installed) { - setDescription(`${name} already installed`); -} -var message = `${installed ? `Uninstall` : `Install`} ${name}?`; -var confirm = await arg(message, [ - { name: `[y]es`, value: true }, - { name: `[n]o`, value: false } -]); -setPlaceholder(`Please wait...`); -if (confirm) { - setDescription(`${installed ? `Uninstalling` : `Installing`} ${name}`); - await exec(`/opt/homebrew/bin/brew ${installed ? `uninstall` : `install`} ${name}`); -} diff --git a/configure/scriptkit/package.json b/configure/scriptkit/package.json deleted file mode 100644 index a81852f..0000000 --- a/configure/scriptkit/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "type": "module", - "devDependencies": { - "@johnlindquist/kit": "file:~/.kit", - "kill-port": "^2.0.1", - "youtube-dl-exec": "^2.2.3" - } -} diff --git a/configure/scriptkit/scriptkit.sh b/configure/scriptkit/scriptkit.sh deleted file mode 100755 index b7180c3..0000000 --- a/configure/scriptkit/scriptkit.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env bash - -# https://espanso.org/docs/packages/basics/ - -# dotfiles folder -DOTFILES_FOLDER="$(pwd | grep -o '.*dotfiles')" - -# Load helper functions -#shellcheck source=/dev/null -source "$DOTFILES_FOLDER/lib/functions" - -_link_file () { - dateStr=$(date +%Y-%m-%d-%H%M) - - local src=$1 dst=$2 - - local overwrite='' backup='' skip='' action='' - - if [ -f "$dst" ] || [ -d "$dst" ] || [ -L "$dst" ] - then - - if [ "$overwrite_all" == "false" ] && [ "$backup_all" == "false" ] && [ "$skip_all" == "false" ] - then - - currentSrc="$(readlink "$dst")" - - if [ "$currentSrc" == "$src" ] - then - - skip=true; - - else - - user "File already exists: $dst ($(basename "$src")), what do you want to do?\n\ - [s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all?" - read -r -n 1 action - - case "$action" in - o ) - overwrite=true;; - O ) - overwrite_all=true;; - b ) - backup=true;; - B ) - backup_all=true;; - s ) - skip=true;; - S ) - skip_all=true;; - * ) - ;; - esac - - fi - - fi - - overwrite=${overwrite:-$overwrite_all} - backup=${backup:-$backup_all} - skip=${skip:-$skip_all} - - if [ "$overwrite" == "true" ] - then - success "Removing $dst" - rm -rf "$dst" - fi - - if [ "$backup" == "true" ] - then - success "Backing up file $dst as ${dst}.${dateStr}" - mv "$dst" "${dst}.${dateStr}" - fi - - if [ "$skip" == "true" ] - then - success "Skiping $src" - fi - fi - - if [ "$skip" != "true" ] # "false" or empty - then - success "Linking $src to $dst" - ln -sv "$src" "$dst" - fi -} - -# --------------------------------------------- -# Install process -# --------------------------------------------- - -preInstall() { - info "Executing pre-installation steps..." -} - -postInstall() { - info "Executing post-install steps..." - - cd "${HOME}/.kenv/kenvs/thiago" || exit - npm install -} - -install() { - info "Installing ScriptKit Scripts" - - local overwrite_all=false backup_all=false skip_all=false - - _link_file "${DOTFILES_FOLDER}/configure/scriptkit/" "${HOME}/.kenv/kenvs/thiago" -} - -execute() { - preInstall - install - postInstall -} - -execute 2>&1 | tee -a "$DOTFILE_LOG_FILE" diff --git a/configure/scriptkit/scripts/download-youtube-video.js b/configure/scriptkit/scripts/download-youtube-video.js deleted file mode 100644 index 27a5993..0000000 --- a/configure/scriptkit/scripts/download-youtube-video.js +++ /dev/null @@ -1,194 +0,0 @@ -// Name: Download YouTube Video -// Description: Download a video from a YouTube URL as .mp4 -// Author: Vogelino -// Twitter: @soyvogelino -// Shortcut: cmd option shift y - -import "@johnlindquist/kit"; - -const youtubeDlExec = await npm("youtube-dl-exec"); -const slugify = await npm("slugify"); -const apiKey = await env("YOUTUBE_API_KEY"); - -// Show feedback as HTML (Adds padding and some feedback styles) -const showFeedback = async (message) => { - await div(` - -
- ${message} -
- `); - return message; -}; - -// Returns the SVG markup of an animated loading spinner -const getLoadingSpinner = () => ` - - - - - - - - - - - - -`; - -// Returns a small HTML structure showing basic information about the video currently downloaded -const getVideoTemplate = (title, metadata) => ` -

${title}

- - - - - -
- - -
- Destination - ${metadata.path} -
-
- Language - ${metadata.defaultAudioLanguage} -
-
- Channel - ${metadata.channelTitle} -
-
-`; - -// Retruns basic information about the youtube video (For the feedback and the file name) -const getVideoMetadata = (url) => - new Promise((resolve, reject) => { - const urlObj = new URL(url); - const id = urlObj.searchParams.get("v"); - if (!id) return reject(`Video ID not present in the url`); - const ytUrl = new URL(`https://www.googleapis.com/youtube/v3/videos`); - ytUrl.searchParams.set("key", apiKey); - ytUrl.searchParams.set("id", id); - ytUrl.searchParams.set("part", "snippet"); - console.log(ytUrl.toString()); - get(ytUrl.toString()) - .then((response) => response.data) - .then((data) => data.items[0].snippet) - .then(resolve); - }); - -// We save the metadata outside the try catch so it's available in the catch -let fullMetadata = {}; - -try { - const videoSrc = await arg("Video url:"); - const videoMetadata = await getVideoMetadata(videoSrc); - const videoPath = "Downloads"; - - const videoName = slugify(videoMetadata.title.slice(0, 50).toLowerCase()); - const fileName = videoName !== "" ? videoName : videoSrc; - const newPath = home(videoPath, path.basename(fileName) + ".mp4"); - fullMetadata = { ...videoMetadata, path: `~/${videoPath}/${fileName}.mp4` }; - - // We display the loading state - void showFeedback(` -
- ${getVideoTemplate( - `${getLoadingSpinner()} Downloading "${fullMetadata.title}"`, - fullMetadata - )} -
- `); - - // We download the video - const res = await youtubeDlExec(videoSrc, { output: newPath }); - console.log(res); - - // If all went well, we can show a success message - showFeedback(` -
- ${getVideoTemplate( - `✅ Successfully downloaded "${fullMetadata.title}"`, - fullMetadata - )} -
- `); - await wait(1000); - - // After a second, we offer the user the choice of what to do next - const nextStep = await arg("What would you like to do with this file?", [ - { - name: "Show in finder ↗️", - description: `Open ~/${videoPath}`, - value: "locate", - }, - { - name: "Open video 🎥", - description: `View video in default player`, - value: `view`, - }, - ]); - - // We check for the user's choice in and open either the file or the location - if (nextStep === "locate") { - exec(`open --reveal ${newPath}`); - } else if (nextStep === "view") { - exec(`open ${newPath}`); - } - - // In case something went wrong, we show the error -} catch (err) { - console.log(err); - await showFeedback(` -
-

- 🔴 Error ${err} -

- ${getVideoTemplate( - `🔴 Error downloading "${fullMetadata?.title}"`, - fullMetadata || {} - )} -
- `); -} diff --git a/configure/scriptkit/scripts/homebrew.ts b/configure/scriptkit/scripts/homebrew.ts deleted file mode 100644 index 5f2e0b5..0000000 --- a/configure/scriptkit/scripts/homebrew.ts +++ /dev/null @@ -1,33 +0,0 @@ -// Name: Search Homebrew -// Shortcut: cmd option shift h - -import "@johnlindquist/kit" - -let query = await arg("Search homebrew") - -let response = await get(`https://formulae.brew.sh/api/formula/${query.trim()}.json`) -let { name } = response.data; - -let bins = await readdir(`/opt/homebrew/bin`) - -let installed = bins.includes(name) - -if(installed){ - setDescription(`${name} already installed`) -} - -let message = `${installed ? `Uninstall` : `Install`} ${name}?` - -let confirm = await arg(message, [ - {name: `[y]es`, value: true}, - {name: `[n]o`, value: false} -]) - -setPlaceholder(`Please wait...`) - -if(confirm){ - setDescription(`${installed ? `Uninstalling` : `Installing`} ${name}`) - await exec(`/opt/homebrew/bin/brew ${installed ? `uninstall` : `install`} ${name}`) -} - - diff --git a/configure/scriptkit/scripts/jira-issues.js b/configure/scriptkit/scripts/jira-issues.js deleted file mode 100644 index 616a439..0000000 --- a/configure/scriptkit/scripts/jira-issues.js +++ /dev/null @@ -1,179 +0,0 @@ -/* -# 🏷️ My Jira issues -- Lists the last 10 issues assigned to me -- You can open the issue in jira -- When selecting an issue, displays a widget on the screen that contains the issue data -- default shortcut to run the script: `cmd+option+shift+j` -*/ - -// Name: 🏷️ Jira issues -// Description: List issues assigned to me in Jira -// Shortcut: cmd option shift j -// Author: WaelNalouti - -import "@johnlindquist/kit"; - -const JIRA_HOST = await env( - "JIRA_HOST_URL", - "jira host url: exemple.atlassian.net" -); -const JIRA_USERNAME = await env("JIRA_USERNAME", "your jira username"); -const AUTH = await env("AUTH", "your jira acces token"); - -const JIRA_APP_URL = `${JIRA_HOST}/browse`; -const JIRA_API_URL = `${JIRA_HOST}/rest/api/latest`; - -const JIRA_ISSUES_QUERY = `/search?orderBy=-created&jql=assignee=%22${JIRA_USERNAME.replaceAll( - " ", - "%20" -)}%22+and+status+not+in(Finalizada, Descartada, Cerrado)&maxResults=25&startAt=0`; - -let headersList = { - Authorization: `Bearer ${AUTH}`, -}; - -let response = await get(`${JIRA_API_URL}${JIRA_ISSUES_QUERY}`, { - headers: headersList, -}); - -let data = await response.data; - -let issuesData = data.issues.map((issue) => ({ - key: issue.key, - summary: issue.fields.summary, - issuetype: issue.fields.issuetype, - project: issue.fields.project, - created: issue.fields.created, - priority: issue.fields.priority, - description: issue.fields.description, - creator: issue.fields.creator, - status: issue.fields.status, -})); - -const selectedIssue = await arg("Select an issue to open in browser", () => { - return issuesData.map((issue) => ({ - name: issue.summary, - icon: issue.issuetype.iconUrl, - description: `[${issue.status.statusCategory.name}] - ${issue.project.name}/${issue.key}`, - value: issue.key, - preview: () => - ` -
-
- -

${issue.issuetype.name}

-

[${issue.status.statusCategory.name}]

-
-

- ${issue.summary} -

-
-
-

Project: ${issue.project.name}

-

Key: ${issue.key}

-
-
-
- created by: -
- - ${issue.creator.displayName} -
-
-
- created at: -

- ${new Date(issue.created).toLocaleString()} -

-
-
-
- - - Open issue in jira - -

${ - issue.description || - "No description for this task 🌵" - }

-
- `, - })); -}); - -let issueDataRes = await fetch(`${JIRA_API_URL}/issue/${selectedIssue}`, { - method: "GET", - headers: headersList, -}); - -let issueData = await issueDataRes.json(); - -let issue = { - key: issueData.key, - summary: issueData.fields.summary, - issuetype: issueData.fields.issuetype, - project: issueData.fields.project, - created: issueData.fields.created, - priority: issueData.fields.priority, - description: issueData.fields.description, - creator: issueData.fields.creator, - status: issueData.fields.status, -}; - -await widget( - ` -
-
- -

${issue.issuetype.name}

-

[${issue.status.statusCategory.name}]

-
-

- ${issue.summary} -

-
-
-

Project: ${issue.project.name}

-

Key: ${issue.key}

-
-
-
- created by: -
- - ${issue.creator.displayName} -
-
-
- created at: -

- ${new Date(issue.created).toLocaleString()} -

-
-
- - go to issue - -
-

${ - issue.description || - "No description for this task 🌵" - }

-
- `, - { - alwaysOnTop: true, - opacity: 0.7, - roundedCorners: true, - hasShadow: true, - draggable: true, - backgroundColor: "#000", - // frame: true, - darkTheme: true, - useContentSize: true, - } -); diff --git a/configure/scriptkit/scripts/kill-port.js b/configure/scriptkit/scripts/kill-port.js deleted file mode 100644 index 591c17b..0000000 --- a/configure/scriptkit/scripts/kill-port.js +++ /dev/null @@ -1,24 +0,0 @@ -// Name: Port kill -// Description: Enter port number to kill process listening on port. -// Author: kyo young -// Shortcut: cmd shift k -// GitHub: - -import '@johnlindquist/kit'; - -const killPort = await npm('kill-port'); -const port = await arg('Enter port to kill') -const containerClassName = 'flex justify-center items-center text-4xl h-full' - -try { - await killPort(port, 'tcp') - await div(`🤖 listening on port ${port} has been killed.`,containerClassName); -} catch (error) { - console.error(error); - await div(` - 🛰️ ${error.message} - `,containerClassName) -} - - - diff --git a/configure/scriptkit/scripts/open-jira-ticket.js b/configure/scriptkit/scripts/open-jira-ticket.js deleted file mode 100644 index 24aac99..0000000 --- a/configure/scriptkit/scripts/open-jira-ticket.js +++ /dev/null @@ -1,17 +0,0 @@ -import "@johnlindquist/kit" - -// Menu: Open Jira ticket in browser -// Description: Parses a valid ticket number from selection and opens it in browser -// Author: Jakub Olek -// Shortcut: cmd shift j -// Twitter: @JakubOlek - -const jiraDomain = await env("JIRA_DOMAIN"); -const text = await arg("Enter JIRA Ticket ID") -const jiraTicket = text.match(/([A-Z]{2,5}-[0-9]+)/); - -if (jiraTicket) { - focusTab(`${jiraDomain}/browse/${jiraTicket[0]}`); -} else { - await div(`Informed JIRA "${text}" is not valid!`, `flex justify-center items-center text-4xl h-full`) -} diff --git a/configure/scriptkit/scripts/open-project-vs-code.js b/configure/scriptkit/scripts/open-project-vs-code.js deleted file mode 100644 index 780a8ba..0000000 --- a/configure/scriptkit/scripts/open-project-vs-code.js +++ /dev/null @@ -1,47 +0,0 @@ -// Menu: Open Project in VS Code -// Description: Opens a project in code -// Shortcut: cmd shift . - -const containerClassName = 'flex justify-center items-center text-sm h-full' -async function getProjects(parentDir) { - const codeDir = await ls(parentDir) - const choices = [] - - if (codeDir.includes("package.json")) { - choices.push({ - name: parentDir, - value: parentDir, - description: parentDir, - }) - - return choices - } - - for (const dir of codeDir) { - if (dir.includes("node_modules")) { - continue - } - const fullPath = path.join(parentDir, dir) - if (!await isFile(fullPath)) { - choices.push(...(await getProjects(fullPath))) - } - } - return choices -} - -const categories = [ - { name: "Personal", path: "~/Documents/Thiago/Repos" }, - { name: "Work", path: "~/Documents/GFT" } -] - -const categoryChoice = await arg( - "What are you working on ?", - categories.map((category) => category.name) -) -const category = - categories.find((item) => item.name === categoryChoice)?.path || - categories[0].path - -const choice = await arg("Which project?", [...(await getProjects(category))]) - -edit(choice) \ No newline at end of file