refactor alias and solve case 3

This commit is contained in:
felixlohmeier 2022-10-22 21:42:49 +00:00
parent ed816860de
commit 1593f2eccb
3 changed files with 26 additions and 34 deletions

30
orcli
View File

@ -590,9 +590,6 @@ function init_import() {
# shellcheck shell=bash
function interactive() {
cat <<'EOF'
if ! command -v orcli &>/dev/null; then
alias orcli="$orcli"
fi
PS1="(orcli) [\u@\h \W]\$ "
source <(orcli completions)
echo '================================================================'
@ -864,13 +861,6 @@ orcli_run_command() {
# locate orcli and OpenRefine
scriptpath=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
if ! command -v orcli &>/dev/null; then
if [[ -x "${scriptpath}/orcli" ]]; then
orcli="${scriptpath}/orcli"
else
error "orcli is not executable!" "Try: chmod + ${scriptpath}/orcli"
fi
fi
if [[ -x "${scriptpath}/refine" ]]; then
openrefine="${scriptpath}/refine"
else
@ -907,8 +897,8 @@ orcli_run_command() {
# case 1: interactive mode if stdin is selected but not present
bash --rcfile <(
cat ~/.bashrc
if [[ $orcli ]]; then
echo "alias orcli=$orcli"
if ! command -v orcli &>/dev/null; then
echo "alias orcli=${scriptpath}/orcli"
fi
interactive
) -i </dev/tty
@ -919,11 +909,11 @@ orcli_run_command() {
# case 2: execute scripts and keep shell running
bash --rcfile <(
cat ~/.bashrc
if [[ $orcli ]]; then
echo "alias orcli=$orcli"
if ! command -v orcli &>/dev/null; then
echo "alias orcli=${scriptpath}/orcli"
fi
for i in "${!files[@]}"; do
log "execute script ${files[$i]}"
log "executing script ${files[$i]}..."
awk 1 "${files[$i]}"
done
interactive
@ -931,8 +921,14 @@ orcli_run_command() {
else
# case 3: just execute scripts
for i in "${!files[@]}"; do
log "execute script ${files[$i]}"
bash -e <(awk 1 "${files[$i]}")
log "executing script ${files[$i]}..."
bash -e <(
if ! command -v orcli &>/dev/null; then
echo "shopt -s expand_aliases"
echo "alias orcli=${scriptpath}/orcli"
fi
awk 1 "${files[$i]}"
)
done
fi

View File

@ -1,9 +1,6 @@
# shellcheck shell=bash
function interactive() {
cat <<'EOF'
if ! command -v orcli &>/dev/null; then
alias orcli="$orcli"
fi
PS1="(orcli) [\u@\h \W]\$ "
source <(orcli completions)
echo '================================================================'

View File

@ -19,13 +19,6 @@ OPENREFINE_URL="http://localhost:${args[--port]}"
# locate orcli and OpenRefine
scriptpath=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
if ! command -v orcli &>/dev/null; then
if [[ -x "${scriptpath}/orcli" ]]; then
orcli="${scriptpath}/orcli"
else
error "orcli is not executable!" "Try: chmod + ${scriptpath}/orcli"
fi
fi
if [[ -x "${scriptpath}/refine" ]]; then
openrefine="${scriptpath}/refine"
else
@ -62,8 +55,8 @@ if [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then
# case 1: interactive mode if stdin is selected but not present
bash --rcfile <(
cat ~/.bashrc
if [[ $orcli ]]; then
echo "alias orcli=$orcli"
if ! command -v orcli &>/dev/null; then
echo "alias orcli=${scriptpath}/orcli"
fi
interactive
) -i </dev/tty
@ -74,11 +67,11 @@ if [[ ${args[--interactive]} ]]; then
# case 2: execute scripts and keep shell running
bash --rcfile <(
cat ~/.bashrc
if [[ $orcli ]]; then
echo "alias orcli=$orcli"
if ! command -v orcli &>/dev/null; then
echo "alias orcli=${scriptpath}/orcli"
fi
for i in "${!files[@]}"; do
log "execute script ${files[$i]}"
log "executing script ${files[$i]}..."
awk 1 "${files[$i]}"
done
interactive
@ -86,7 +79,13 @@ if [[ ${args[--interactive]} ]]; then
else
# case 3: just execute scripts
for i in "${!files[@]}"; do
log "execute script ${files[$i]}"
bash -e <(awk 1 "${files[$i]}")
log "executing script ${files[$i]}..."
bash -e <(
if ! command -v orcli &>/dev/null; then
echo "shopt -s expand_aliases"
echo "alias orcli=${scriptpath}/orcli"
fi
awk 1 "${files[$i]}"
)
done
fi