Skip to content

Commit

Permalink
fix: address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Nov 30, 2023
1 parent 74d44a6 commit 237c057
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 280 deletions.
85 changes: 0 additions & 85 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,12 @@ repos:
hooks:
- id: check-dependabot
- id: check-github-workflows
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.292"
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/commitizen-tools/commitizen
rev: 3.10.0
hooks:
- id: commitizen
stages:
- commit-msg
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
- id: cargo-check
args:
- "--locked"
- id: clippy
args:
- "--locked"
- "--"
- "--deny"
- "warnings"
- repo: local
hooks:
- id: deno-fmt
Expand Down Expand Up @@ -73,67 +52,3 @@ repos:
- ts
- tsx
files: ^website/
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
hooks:
- id: insert-license
name: "License MPL-2.0 python"
args:
#- --remove-header
- --license-filepath=dev/license-header-MPL-2.0.txt
- "--comment-style=#"
- "--skip-license-insertion-comment=no-auto-license-header"
types_or:
- python
files: ^typegraph/
- id: insert-license
name: "License Elastic-2.0 rust"
args:
#- --remove-header
- --license-filepath=dev/license-header-Elastic-2.0.txt
- "--comment-style=//"
- "--skip-license-insertion-comment=no-auto-license-header"
types_or:
- rust
files: ^(typegate|libs)/
- id: insert-license
name: "License MPL-2.0 rust"
args:
#- --remove-header
- --license-filepath=dev/license-header-MPL-2.0.txt
- "--comment-style=//"
- "--skip-license-insertion-comment=no-auto-license-header"
types_or:
- rust
files: ^(meta-cli|typegraph)/
- id: insert-license
name: "License Elastic-2.0 deno"
args:
#- --remove-header
- --license-filepath=dev/license-header-Elastic-2.0.txt
- "--comment-style=//"
- "--skip-license-insertion-comment=no-auto-license-header"
types_or:
- ts
files: ^(typegate|dev)/
- id: insert-license
name: "License MPL-2.0 deno"
args:
#- --remove-header
- --license-filepath=dev/license-header-MPL-2.0.txt
- "--comment-style=//"
- "--skip-license-insertion-comment=no-auto-license-header"
types_or:
- ts
files: ^typegraph/
- id: insert-license
name: "License Elastic-2.0 typescript"
args:
#- --remove-header
- --license-filepath=dev/license-header-Elastic-2.0.txt
- "--comment-style=//"
- "--skip-license-insertion-comment=no-auto-license-header"
types_or:
- ts
- tsx
files: ^website/
68 changes: 48 additions & 20 deletions cli/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ switch (Deno.build.os) {
throw new Error(`unsupported os ${Deno.build.os}`);
}

const BASH_PREXEC = await (
async () => {
const resp = await fetch(
"https://raw.githubusercontent.com/rcaloras/bash-preexec/0.5.0/bash-preexec.sh",
);
if (!resp.ok) {
throw new Error("error fetching bash-preexec");
}
return await resp.text();
}
)();
// null means it should be removed (for cleaning up old versions)
const vfs = {
// the script executed when users use the ghjk command
Expand All @@ -27,29 +38,38 @@ console.log = log;
mod.ghjk.runCli(Deno.args.slice(1), mod.options);
`,

"hooks/bash-preexec.sh": await (
await fetch(
"https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh",
)
).text(),
"hooks/bash-preexec.sh": BASH_PREXEC,

"hooks/.zshenv": `
if [ -e ~/.zshenv ]; then . ~/.zshenv; fi
hooksDir=$(dirname -- "$(readlink -f -- "\${(%):-%x}")")
. $hooksDir/hook.sh
`,
// the hook run before every prompt draw in bash
"hooks/hook.sh": `
__ghjk_clean_up_paths() {
PATH=$(echo "$PATH" | tr ':' '\\n' | grep -vE "^$HOME/\\.local/share/ghjk/envs" | tr '\\n' ':')
PATH="$\{PATH%:\}"
PATH="\${PATH%:}"
LIBRARY_PATH=$(echo "$LIBRARY_PATH" | tr ':' '\\n' | grep -vE "^$HOME/\\.local/share/ghjk/envs" | tr '\\n' ':')
LIBRARY_PATH="$\{LIBRARY_PATH%:\}"
LIBRARY_PATH="\${LIBRARY_PATH%:}"
${LD_LIBRARY_ENV}=$(echo "$${LD_LIBRARY_ENV}" | tr ':' '\\n' | grep -vE "^$HOME/\\.local/share/ghjk/envs" | tr '\\n' ':')
${LD_LIBRARY_ENV}="$\{${LD_LIBRARY_ENV}%:\}"
${LD_LIBRARY_ENV}="\${${LD_LIBRARY_ENV}%:}"
C_INCLUDE_PATH=$(echo "$C_INCLUDE_PATH" | tr ':' '\\n' | grep -vE "^$HOME/\\.local/share/ghjk/envs" | tr '\\n' ':')
C_INCLUDE_PATH="$\{C_INCLUDE_PATH%:\}"
C_INCLUDE_PATH="\${C_INCLUDE_PATH%:}"
CPLUS_INCLUDE_PATH=$(echo "$CPLUS_INCLUDE_PATH" | tr ':' '\\n' | grep -vE "^$HOME/\\.local/share/ghjk/envs" | tr '\\n' ':')
CPLUS_INCLUDE_PATH="$\{CPLUS_INCLUDE_PATH%:\}"
CPLUS_INCLUDE_PATH="\${CPLUS_INCLUDE_PATH%:}"
}
# Define color variables
ansi_red='\\033[0;31m'
# GREEN='\\033[0;32m'
ansi_yel='\\033[0;33m'
# BLUE='\\033[0;34m'
ansi_nc='\\033[0m' # No Color
init_ghjk() {
if [[ -v GHJK_CLEANUP ]]; then
eval $GHJK_CLEANUP
if [ -n "\${GHJK_CLEANUP+x}" ]; then
eval "$GHJK_CLEANUP"
unset GHJK_CLEANUP
fi
cur_dir=$PWD
Expand All @@ -61,16 +81,18 @@ init_ghjk() {
PATH="$envDir/shims/bin:$PATH"
LIBRARY_PATH="$envDir/shims/lib:$LIBRARY_PATH"
${LD_LIBRARY_ENV}="$envDir/shims/lib:$${LD_LIBRARY_ENV}"
LD_LIBRARY_PATH="$envDir/shims/lib:$LD_LIBRARY_PATH"
C_INCLUDE_PATH="$envDir/shims/include:$C_INCLUDE_PATH"
CPLUS_INCLUDE_PATH="$envDir/shims/include:$CPLUS_INCLUDE_PATH"
source "$envDir/loader.sh"
. "$envDir/loader.sh"
# FIXME: -ot not valid in POSIX
# shellcheck disable=SC3000-SC4000
if [ "$envDir/loader.sh" -ot "$cur_dir/ghjk.ts" ]; then
echo -e "\e[38;2;255;69;0m[ghjk] Detected changes, please sync...\e[0m"
echo "\${ansi_yel}[ghjk] Detected changes, please sync...\${ansi_nc}"
fi
else
echo -e "\e[38;2;255;69;0m[ghjk] Uninstalled runtime found, please sync...\e[0m"
echo "\${ansi_red}[ghjk] Uninstalled runtime found, please sync...\${ansi_nc}"
echo "$envDir"
fi
export ghjk_alias="deno run -A $HOME/.local/share/ghjk/hooks/entrypoint.ts $cur_dir/ghjk.ts"
Expand All @@ -79,12 +101,12 @@ init_ghjk() {
cur_dir="$(dirname "$cur_dir")"
done
__ghjk_clean_up_paths
export ghjk_alias="echo 'No ghjk.ts config found.'"
export ghjk_alias="echo '\${ansi_red}No ghjk.ts config found.\${ansi_nc}'"
}
ghjk_alias="echo 'No ghjk.ts config found.'"
ghjk () {
eval "$ghjk_alias" $*;
eval "$ghjk_alias" "$*";
}
# export function for non-interactive use
Expand All @@ -93,8 +115,8 @@ export -f init_ghjk
export -f __ghjk_clean_up_paths
# use precmd to check for ghjk.ts before every prompt draw
hooksDir=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")")
source "$hooksDir/bash-preexec.sh"
hooksDir=$(dirname -- "$(readlink -f -- "\${BASH_SOURCE}")")
. "$hooksDir/bash-preexec.sh"
precmd() {
init_ghjk
}
Expand Down Expand Up @@ -236,6 +258,12 @@ export async function install() {
/\.local\/share\/ghjk\/hooks\/hook.sh/,
"source $HOME/.local/share/ghjk/hooks/hook.sh",
);
} else if (shell === "zsh") {
await filterAddFile(
std_path.resolve(homeDir, ".zshrc"),
/\.local\/share\/ghjk\/hooks\/hook.sh/,
"source $HOME/.local/share/ghjk/hooks/hook.sh",
);
} else {
throw new Error(`unsupported shell: ${shell}`);
}
Expand Down
23 changes: 1 addition & 22 deletions core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type SpawnOptions = {
// pipeErr?: WritableStream<Uint8Array>;
};

// FIXME: pita function responsible for test flakiness
// FIXME: replace with deidcated ergonomic library
export async function spawn(
cmd: string[],
options: SpawnOptions = {},
Expand All @@ -40,8 +40,6 @@ export async function spawn(
const child = new Deno.Command(cmd[0], {
args: cmd.slice(1),
cwd,
// stdout: "piped",
// stderr: "piped",
...(pipeInput
? {
stdin: "piped",
Expand All @@ -50,14 +48,6 @@ export async function spawn(
env,
}).spawn();

// keep pipe asynchronous till the command exists
// void child.stdout.pipeTo(options.pipeOut ?? Deno.stdout.writable, {
// preventClose: true,
// });
// void child.stderr.pipeTo(options.pipeErr ?? Deno.stderr.writable, {
// preventClose: true,
// });

if (pipeInput) {
const writer = child.stdin.getWriter();
await writer.write(new TextEncoder().encode(pipeInput));
Expand All @@ -83,20 +73,9 @@ export async function spawnOutput(
cwd,
stdout: "piped",
stderr: "piped",
// ...(pipeInput
// ? {
// stdin: "piped",
// }
// : {}),
env,
}).spawn();

// if (pipeInput) {
// const writer = child.stdin.getWriter();
// await writer.write(new TextEncoder().encode(pipeInput));
// writer.releaseLock();
// await child.stdin.close();
// }
const { code, success, stdout, stderr } = await child.output();
if (!success) {
throw new Error(
Expand Down
8 changes: 4 additions & 4 deletions ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ wasmedge({});
// jco({});
// mold({});
// act({});
// asdf({
// plugRepo: "https://github.com/asdf-community/asdf-zig",
// installType: "version",
// });
asdf({
plugRepo: "https://github.com/asdf-community/asdf-python",
installType: "version",
});
// protoc({});
// earthly({});
// ruff({});
Expand Down
Loading

0 comments on commit 237c057

Please sign in to comment.