Created
September 28, 2020 21:57
-
-
Save robvanderleek/3378cc60287a56829e8436bd585cf449 to your computer and use it in GitHub Desktop.
Backpack issue #3
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
#!/usr/bin/env node | |
const fs = require('fs'); | |
const os = require('os'); | |
const path = require('path'); | |
function usage() { | |
console.log( | |
'Backpack usage:\n' + | |
' Put in backpack: bp -i <filename>\n' + | |
' Get from backpack: bp -e <filename>\n') | |
} | |
function initializeBackpackDir() { | |
const homeDir = os.homedir(); | |
if (!homeDir) { | |
console.log('Could not resolve home directory'); | |
process.exit(1); | |
} | |
const backpackDir = path.join(homeDir, '.local', 'share', 'backpack'); | |
fs.mkdirSync(backpackDir, {recursive: true}); | |
return backpackDir; | |
} | |
function importFile(filename, backpackDir) { | |
fs.renameSync(filename, path.join(backpackDir, filename)); | |
} | |
function exportFile(filename, backpackDir) { | |
fs.renameSync(path.join(backpackDir, filename), filename); | |
} | |
const backpackDir = initializeBackpackDir(); | |
const args = process.argv.slice(2); | |
if (args.length === 2 && args[0] === '-i') { | |
importFile(args[1], backpackDir); | |
} else if (args.length === 2 && args[0] === '-e') { | |
exportFile(args[1], backpackDir); | |
} else { | |
usage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment