WIP
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
#/usr/bin/env zsh
|
||||
autoload -U compinit
|
||||
compinit
|
||||
|
||||
function findJJSource {
|
||||
# @source http://stackoverflow.com/a/246128/330439
|
||||
local SOURCE="$jjCpmmandRunPoint"
|
||||
local DIR=""
|
||||
while [[ -h "$SOURCE" ]]; do
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
||||
done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
while [[ ! -e "${DIR}/jj.filelocation" ]]; do
|
||||
DIR=$(dirname "${DIR}")
|
||||
done
|
||||
echo "${DIR}"
|
||||
}
|
||||
|
||||
|
||||
export JJ_SOURCE_DIR=$(findJJSource)
|
||||
|
||||
if [[ -e "$JJ_SOURCE_DIR/~~tmp/shEnvs.sh" ]]; then
|
||||
source $JJ_SOURCE_DIR/~~tmp/shEnvs.sh
|
||||
fi
|
||||
|
||||
|
||||
typeset -A opt_args
|
||||
|
||||
function _AuctoCompletion(){
|
||||
# echo $words
|
||||
COMMANDS_WITH_HELP=$($JJ_SOURCE_DIR/bashUtils/auto-completion.ts "1" $words )
|
||||
COMMANDS=$($JJ_SOURCE_DIR/bashUtils/auto-completion.ts "0" $words )
|
||||
|
||||
_arguments "1: :($COMMANDS)"
|
||||
_describe 'command' "$COMMANDS_WITH_HELP" && ret=0
|
||||
}
|
||||
|
||||
compdef _AuctoCompletion jj
|
||||
Executable
+110
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
import { bashRunAndReturnSync } from "@helpers/bashUtils"
|
||||
import { getJJConfigByKeyChain } from "@helpers/jjConfigUtils"
|
||||
|
||||
async function main() {
|
||||
const inputArgs = [...process.argv]
|
||||
inputArgs.shift()
|
||||
inputArgs.shift()
|
||||
const displayHelp = inputArgs[0]
|
||||
inputArgs.shift()
|
||||
inputArgs.shift()
|
||||
|
||||
let remainingArgsCount = inputArgs.length
|
||||
const commandConfig = getJJConfigByKeyChain(`commands`)
|
||||
const jjCommandsList = Object.keys(commandConfig).map((cmdKey) => ({
|
||||
key: cmdKey,
|
||||
...commandConfig[cmdKey]
|
||||
}))
|
||||
let lastArrayOfKeys = [...jjCommandsList]
|
||||
|
||||
let commands = ""
|
||||
let preHelp = ``
|
||||
|
||||
while (remainingArgsCount > 0) {
|
||||
const matchingCommand = lastArrayOfKeys.find((item) => {
|
||||
return item?.key == inputArgs[0]
|
||||
})
|
||||
|
||||
if (matchingCommand?.commandForRetrieveKeys) {
|
||||
if (remainingArgsCount == 2 && matchingCommand?.commandForRetrieveKeys2) {
|
||||
matchingCommand.commandForRetrieveKeys = matchingCommand?.commandForRetrieveKeys2
|
||||
}
|
||||
const oldArgOrder = remainingArgsCount
|
||||
remainingArgsCount = 0
|
||||
const command =
|
||||
matchingCommand?.commandForRetrieveKeys + ` ${matchingCommand?.commandForRetrieveKeys?.includes("auto-completion") ? ` auto-completion ${process.argv.join(" ")}` : ""}`
|
||||
const res = await bashRunAndReturnSync(command)
|
||||
const newCommands = res?.split("\n") || []
|
||||
newCommands.push(String(""))
|
||||
lastArrayOfKeys = []
|
||||
|
||||
newCommands.forEach((element) => {
|
||||
if (element.includes(".") && !element.includes(".com")) {
|
||||
return
|
||||
}
|
||||
lastArrayOfKeys.push({
|
||||
key: element,
|
||||
desc: "",
|
||||
keys: [],
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (matchingCommand?.keysOnly && matchingCommand?.keysOnly?.length > 0) {
|
||||
remainingArgsCount = 0
|
||||
lastArrayOfKeys = []
|
||||
|
||||
matchingCommand?.keysOnly.forEach((element) => {
|
||||
lastArrayOfKeys.push({
|
||||
key: element,
|
||||
desc: "",
|
||||
keys: [],
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (matchingCommand?.postCommandsForce && matchingCommand?.postCommandsForce?.length > 0) {
|
||||
remainingArgsCount = 0
|
||||
|
||||
matchingCommand?.postCommandsForce.forEach((element) => {
|
||||
lastArrayOfKeys.push({
|
||||
key: element,
|
||||
desc: "",
|
||||
keys: [],
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (matchingCommand?.key && matchingCommand?.keys && remainingArgsCount > 0) {
|
||||
preHelp += `${matchingCommand?.desc || ""} `
|
||||
lastArrayOfKeys = matchingCommand?.keys
|
||||
inputArgs.shift()
|
||||
remainingArgsCount -= 1
|
||||
} else {
|
||||
// lastArrayOfKeys = [];
|
||||
remainingArgsCount = 0
|
||||
}
|
||||
}
|
||||
|
||||
if (remainingArgsCount == 0) {
|
||||
for (const item of lastArrayOfKeys) {
|
||||
if (displayHelp == "1") {
|
||||
commands += `'${item?.key}:${preHelp}${item?.desc}' `
|
||||
} else {
|
||||
commands += `${item?.key} `
|
||||
}
|
||||
if (item?.commandForRetrieveKeys) {
|
||||
commands += `-- `
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`(${commands})`)
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error("FATAL ERROR:", err)
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -1,10 +1,6 @@
|
||||
#!/usr/bin/env zsh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# source "$JJ_SOURCE_DIR/bashUtils/index.sh"
|
||||
|
||||
osDependencies=(${=OS_DEPENDENCIES})
|
||||
|
||||
for osDependency in $osDependencies ; do
|
||||
for osDependency in $OS_DEPENDENCIES ; do
|
||||
if ! hash $osDependency; then
|
||||
jjCliLog jjLogWarning "bashUtils/ensureDependency.sh Unable to find OS package '$osDependency'. Installing now..."
|
||||
eval "$PACKAGE_MANAGER_INSTALL $osDependency"
|
||||
@@ -20,11 +16,7 @@ if [[ -e $ASDF_DIR/asdf.sh ]]; then
|
||||
fi
|
||||
|
||||
|
||||
asdfInstalledVersionPrefix=$(asdf info 2> /dev/null | grep -A 1 'ASDF VERSION' | tail -1 | grep "^${ASDF_VERSION}")
|
||||
|
||||
if [[ -z "${asdfInstalledVersionPrefix}" ]] || \
|
||||
! hash asdf || \
|
||||
[[ "${asdfInstalledVersionPrefix}" != "$ASDF_VERSION" ]] || \
|
||||
if ! hash asdf || \
|
||||
[[ ! -e $JJ_SOURCE_DIR/~~tmp/deps/asdf-tools-installed ]] \
|
||||
|| jjIsFileNewerFile "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" "$JJ_SOURCE_DIR/~~tmp/deps/asdf-tools-installed" ; then
|
||||
rm -rf $ASDF_DIR
|
||||
@@ -39,11 +31,11 @@ if [[ -z "${asdfInstalledVersionPrefix}" ]] || \
|
||||
set +e
|
||||
while read tool_and_version; do
|
||||
jjCliLog jjLog "... checking tool: $tool_and_version"
|
||||
tool_and_version_split=(${=tool_and_version})
|
||||
# echo ${tool_and_version_split[1]}
|
||||
# echo ${tool_and_version_split[2]}
|
||||
asdf plugin add ${tool_and_version_split[1]} || true
|
||||
asdf install ${tool_and_version_split[1]} ${tool_and_version_split[2]}
|
||||
tool_and_version_split=(${tool_and_version})
|
||||
echo ${tool_and_version_split[0]}
|
||||
echo ${tool_and_version_split[1]}
|
||||
asdf plugin add ${tool_and_version_split[0]} || true
|
||||
asdf install ${tool_and_version_split[0]} ${tool_and_version_split[1]}
|
||||
done <${ASDF_DEFAULT_TOOL_VERSIONS_FILENAME}
|
||||
asdf install
|
||||
set -e
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env zsh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
|
||||
Reference in New Issue
Block a user