diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef9082b --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +package-lock.json +node_modules +npm-debug.log* +yarn-error.log + +.nyc_output +*.swp + +coverage +.idea diff --git a/.madrun.js b/.madrun.js new file mode 100644 index 0000000..6afca12 --- /dev/null +++ b/.madrun.js @@ -0,0 +1,19 @@ +import {run} from 'madrun'; + +export default { + 'test': () => 'tape test/*.js', + 'coverage': async () => `c8 ${await run('test')}`, + 'lint': () => 'putout .', + 'fresh:lint': () => run('lint', '--fresh'), + 'lint:fresh': () => run('lint', '--fresh'), + 'fix:lint': () => run('lint', '--fix'), + 'report': () => 'c8 report --reporter=lcov', + 'watcher': () => 'nodemon -w test -w lib --exec', + 'watch:test': () => run('watcher', 'npm test'), + 'watch:lint': async () => await run('watcher', `'npm run lint'`), + 'watch:tape': () => 'nodemon -w test -w lib --exec tape', + 'watch:coverage:base': () => run('watcher', 'nyc npm test'), + 'watch:coverage:tape': () => run('watcher', 'nyc tape'), + 'watch:coverage': () => run('watch:coverage:base'), +}; + diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..af611c6 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,44 @@ +2026.04.05, v1.3.3 + +fix: +- d84d983 user-menu: paste-to-clip: clip + +2026.04.04, v1.3.2 + +feature: +- 1dbceae @cloudcmd/user-menu: copyURLToCurrentFile -> copyUrlToCurrentFile + +2026.04.04, v1.3.1 + +feature: +- 9663a49 @cloudcmd/user-menu: copy-url-to-current-file: additional slash + +2026.04.04, v1.3.0 + +feature: +- 0eda6b1 past-to-clip: add + +2023.01.22, v1.2.4 + +fix: +- mp4 -> MOV + +2023.01.22, v1.2.3 + +fix: +- mp4 -> mp3 + +2023.01.22, v1.2.2 + +fix: +- ffmpeg: convertMovToMp3 + +2023.01.22, v1.2.1 + +feature: +- package: update + +2023.01.18, v1.1.1 + +fix: +- ffmpeg: lint diff --git a/README.md b/README.md index ba7b0f1..3755783 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # user-menu -User Menu Cookbook + +[User Menu Cookbook](https://github.com/coderaiser/cloudcmd/wiki/User-Menu-Cookbook) diff --git a/menu/change-directory.js b/menu/change-directory.js new file mode 100644 index 0000000..a85577e --- /dev/null +++ b/menu/change-directory.js @@ -0,0 +1,5 @@ +export default { + 'R - cd /': async ({CloudCmd}) => { + await CloudCmd.changeDir('/'); + } +} diff --git a/menu/copy-url-to-current-file.js b/menu/copy-url-to-current-file.js index f479acf..a0e18ac 100644 --- a/menu/copy-url-to-current-file.js +++ b/menu/copy-url-to-current-file.js @@ -1,6 +1,6 @@ -export const copyURLToCurrentFile = async ({DOM}) => { +export const copyUrlToCurrentFile = async ({DOM}) => { const {path} = DOM.CurrentInfo; - const url = `${window.location.href}${path}`; + const url = `${window.location.href}${path.slice(1)}`; const {default: clipboard} = await import('https://cdn.skypack.dev/@cloudcmd/clipboard'); await clipboard.writeText(url); diff --git a/menu/ffmpeg.js b/menu/ffmpeg.js new file mode 100644 index 0000000..9df45af --- /dev/null +++ b/menu/ffmpeg.js @@ -0,0 +1,60 @@ +const isMp3 = (a) => /\.mp3$/.test(a); + +export default { + 'F - Convert flac to mp3': convertFlacToMp3, + 'M - Convert mp4 to mp3': convertMp4ToMp3, + 'O - convert mov to mp3': convertMovToMp3, +}; + +export async function convertFlacToMp3({DOM, CloudCmd}) { + const command = 'for f in *.flac; do ffmpeg -vsync 2 -i "$f" -b:a 320k "${f%flac}mp3"; done'; + await convert(command, { + DOM, + CloudCmd, + }); +} + +export async function convertMp4ToMp3({DOM, CloudCmd}) { + const command = 'for f in *.mp4; do ffmpeg -i "$f" "${f%mp4}mp3"; done'; + await convert(command, { + DOM, + CloudCmd, + }); +} + +export async function convertMovToMp3({DOM, CloudCmd}) { + const command = 'for f in *.MOV; do ffmpeg -i "$f" "${f%MOV}mp3"; done'; + await convert(command, { + DOM, + CloudCmd, + }); +} + +async function convert(command, {DOM, CloudCmd}) { + const {IO, Dialog, CurrentInfo} = DOM; + + const root = CloudCmd.config('root'); + const cwd = `${root}${CurrentInfo.dirPath}`; + + const exitCode = await CloudCmd.TerminalRun.show({ + cwd, + command: `bash -c '${command}'`, + }); + + if (exitCode === -1) + return Dialog.alert(`☝️ Looks like Terminal is disabled, start Cloud Coammnder with '--terminal' flag.`); + + if (exitCode) + return Dialog.alert(`☝️ Looks like something bad happend. Exit code: ${exitCode}`); + + await CloudCmd.refresh(); + + const names = DOM.getFilenames(CurrentInfo.files); + const mp3Names = names.filter(isMp3); + + const from = CurrentInfo.dirPath; + const to = `${from}mp3` + + await IO.move(from, to, mp3Names); + await CloudCmd.refresh(); +} diff --git a/menu/paste-to-clip.js b/menu/paste-to-clip.js new file mode 100644 index 0000000..99a0734 --- /dev/null +++ b/menu/paste-to-clip.js @@ -0,0 +1,22 @@ +export const pasteToClip = async ({CloudCmd, DOM}) => { + const value = await navigator.clipboard.readText(); + const encoded = btoa(encodeURIComponent(`${value}\n`)); + + const command = [ + 'node', + '-e', + `'process.stdout.write(decodeURIComponent(atob("${encoded}")))'`, + '>', + '~/clip', + ].join(' '); + + const {TerminalRun, config} = CloudCmd; + const cwd = config('root') + DOM.CurrentInfo.dirPath; + + return await TerminalRun.show({ + cwd, + command, + closeMessage: 'Press any key to close Terminal', + autoClose: false, + }); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..2385aaf --- /dev/null +++ b/package.json @@ -0,0 +1,54 @@ +{ + "name": "@cloudcmd/user-menu", + "private": true, + "version": "1.3.3", + "type": "module", + "commitType": "colon", + "description": "User Menu for Cloud Commander", + "scripts": { + "test": "madrun test", + "coverage": "madrun coverage", + "lint": "madrun lint", + "fix:lint": "madrun fix:lint", + "report": "madrun report", + "watcher": "madrun watcher", + "watch:test": "madrun watch:test", + "watch:lint": "madrun watch:lint", + "watch:tape": "madrun watch:tape", + "watch:coverage:base": "madrun watch:coverage:base", + "watch:coverage:tape": "madrun watch:coverage:tape", + "watch:coverage": "madrun watch:coverage" + }, + "repository": { + "type": "git", + "url": "git://github.com/cloudcmd/user-menu.git" + }, + "keywords": [ + "tag", + "literal", + "join", + "template", + "array" + ], + "author": "coderaiser (http://coderaiser.github.io/)", + "license": "MIT", + "bugs": { + "url": "https://github.com/cloudcmd/user-menu/issues" + }, + "homepage": "https://github.com/coderaiser/montag", + "devDependencies": { + "c8": "^7.8.0", + "eslint": "^8.11.0", + "eslint-plugin-n": "^15.6.1", + "eslint-plugin-putout": "^16.3.0", + "madrun": "^9.0.0", + "mock-require": "^3.0.3", + "nodemon": "^2.0.2", + "putout": "^28.5.0", + "supertape": "^8.2.0" + }, + "dependencies": {}, + "publishConfig": { + "access": "public" + } +}