Compare commits

...

2 Commits

Author SHA1 Message Date
minjaesong
4e7fe82690 command.js: getFileDir and getFilePath 2026-05-24 00:45:58 +09:00
minjaesong
13eaf1b999 hop up 2026-05-23 22:57:11 +09:00
3 changed files with 20 additions and 1 deletions

View File

@@ -178,6 +178,19 @@ shell.replaceVarCall = function(value) {
shell.getPwd = function() { return shell_pwd; }
shell.getPwdString = function() { return "\\" + (shell_pwd.concat([""])).join("\\"); }
shell.getCurrentDrive = function() { return CURRENT_DRIVE; }
shell.runningScriptPaths = []
shell.getFilePath = function() {
return shell.runningScriptPaths[shell.runningScriptPaths.length - 1]
}
shell.getFileDir = function() {
let p = shell.runningScriptPaths[shell.runningScriptPaths.length - 1]
if (p === undefined) return undefined
let lastSlash = Math.max(p.lastIndexOf('\\'), p.lastIndexOf('/'))
if (lastSlash < 0) return p
// root of a drive (e.g. "A:\foo.js" -> "A:\")
if (lastSlash === 2 && p[1] === ':') return p.substring(0, 3)
return p.substring(0, lastSlash)
}
// example input: echo "the string" > subdir\test.txt
shell.parse = function(input) {
let tokens = []
@@ -787,6 +800,8 @@ shell.execute = function(line, nameOverride) {
let programCode = searchFile.sread()
let extension = searchFile.extension.toUpperCase()
shell.runningScriptPaths.push(searchFile.fullPath)
try {
if ("BAT" == extension) {
// parse and run as batch file
var lines = programCode.split('\n').filter(function(it) { return it.length > 0 }) // this return is not shell's return!
@@ -879,6 +894,9 @@ shell.execute = function(line, nameOverride) {
continue
}
}
} finally {
shell.runningScriptPaths.pop()
}
}
}

View File

@@ -0,0 +1 @@
hopper $0

View File

@@ -11,7 +11,7 @@ const USER_PACKAGE_INCLUDE_DIR = `${USER_BASE_DIR}/include`
const MANIFEST_EXT = "hop.per"
const MIRROR_LIST_PATH = `${SYSTEM_PACKEAGE_DEF_DIR}/mirrors.list`
const net = require("A:/tvdos/include/net.mjs")
const net = require("net")
// SYNOPSIS
// hopper {search,se} [--provides, --requires, --description, --author] query