refactor alias and solve case 3
This commit is contained in:
parent
ed816860de
commit
1593f2eccb
30
orcli
30
orcli
|
@ -590,9 +590,6 @@ function init_import() {
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
function interactive() {
|
function interactive() {
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
if ! command -v orcli &>/dev/null; then
|
|
||||||
alias orcli="$orcli"
|
|
||||||
fi
|
|
||||||
PS1="(orcli) [\u@\h \W]\$ "
|
PS1="(orcli) [\u@\h \W]\$ "
|
||||||
source <(orcli completions)
|
source <(orcli completions)
|
||||||
echo '================================================================'
|
echo '================================================================'
|
||||||
|
@ -864,13 +861,6 @@ orcli_run_command() {
|
||||||
|
|
||||||
# locate orcli and OpenRefine
|
# locate orcli and OpenRefine
|
||||||
scriptpath=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
|
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
|
if [[ -x "${scriptpath}/refine" ]]; then
|
||||||
openrefine="${scriptpath}/refine"
|
openrefine="${scriptpath}/refine"
|
||||||
else
|
else
|
||||||
|
@ -907,8 +897,8 @@ orcli_run_command() {
|
||||||
# case 1: interactive mode if stdin is selected but not present
|
# case 1: interactive mode if stdin is selected but not present
|
||||||
bash --rcfile <(
|
bash --rcfile <(
|
||||||
cat ~/.bashrc
|
cat ~/.bashrc
|
||||||
if [[ $orcli ]]; then
|
if ! command -v orcli &>/dev/null; then
|
||||||
echo "alias orcli=$orcli"
|
echo "alias orcli=${scriptpath}/orcli"
|
||||||
fi
|
fi
|
||||||
interactive
|
interactive
|
||||||
) -i </dev/tty
|
) -i </dev/tty
|
||||||
|
@ -919,11 +909,11 @@ orcli_run_command() {
|
||||||
# case 2: execute scripts and keep shell running
|
# case 2: execute scripts and keep shell running
|
||||||
bash --rcfile <(
|
bash --rcfile <(
|
||||||
cat ~/.bashrc
|
cat ~/.bashrc
|
||||||
if [[ $orcli ]]; then
|
if ! command -v orcli &>/dev/null; then
|
||||||
echo "alias orcli=$orcli"
|
echo "alias orcli=${scriptpath}/orcli"
|
||||||
fi
|
fi
|
||||||
for i in "${!files[@]}"; do
|
for i in "${!files[@]}"; do
|
||||||
log "execute script ${files[$i]}"
|
log "executing script ${files[$i]}..."
|
||||||
awk 1 "${files[$i]}"
|
awk 1 "${files[$i]}"
|
||||||
done
|
done
|
||||||
interactive
|
interactive
|
||||||
|
@ -931,8 +921,14 @@ orcli_run_command() {
|
||||||
else
|
else
|
||||||
# case 3: just execute scripts
|
# case 3: just execute scripts
|
||||||
for i in "${!files[@]}"; do
|
for i in "${!files[@]}"; do
|
||||||
log "execute script ${files[$i]}"
|
log "executing script ${files[$i]}..."
|
||||||
bash -e <(awk 1 "${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
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
function interactive() {
|
function interactive() {
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
if ! command -v orcli &>/dev/null; then
|
|
||||||
alias orcli="$orcli"
|
|
||||||
fi
|
|
||||||
PS1="(orcli) [\u@\h \W]\$ "
|
PS1="(orcli) [\u@\h \W]\$ "
|
||||||
source <(orcli completions)
|
source <(orcli completions)
|
||||||
echo '================================================================'
|
echo '================================================================'
|
||||||
|
|
|
@ -19,13 +19,6 @@ OPENREFINE_URL="http://localhost:${args[--port]}"
|
||||||
|
|
||||||
# locate orcli and OpenRefine
|
# locate orcli and OpenRefine
|
||||||
scriptpath=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
|
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
|
if [[ -x "${scriptpath}/refine" ]]; then
|
||||||
openrefine="${scriptpath}/refine"
|
openrefine="${scriptpath}/refine"
|
||||||
else
|
else
|
||||||
|
@ -62,8 +55,8 @@ if [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then
|
||||||
# case 1: interactive mode if stdin is selected but not present
|
# case 1: interactive mode if stdin is selected but not present
|
||||||
bash --rcfile <(
|
bash --rcfile <(
|
||||||
cat ~/.bashrc
|
cat ~/.bashrc
|
||||||
if [[ $orcli ]]; then
|
if ! command -v orcli &>/dev/null; then
|
||||||
echo "alias orcli=$orcli"
|
echo "alias orcli=${scriptpath}/orcli"
|
||||||
fi
|
fi
|
||||||
interactive
|
interactive
|
||||||
) -i </dev/tty
|
) -i </dev/tty
|
||||||
|
@ -74,11 +67,11 @@ if [[ ${args[--interactive]} ]]; then
|
||||||
# case 2: execute scripts and keep shell running
|
# case 2: execute scripts and keep shell running
|
||||||
bash --rcfile <(
|
bash --rcfile <(
|
||||||
cat ~/.bashrc
|
cat ~/.bashrc
|
||||||
if [[ $orcli ]]; then
|
if ! command -v orcli &>/dev/null; then
|
||||||
echo "alias orcli=$orcli"
|
echo "alias orcli=${scriptpath}/orcli"
|
||||||
fi
|
fi
|
||||||
for i in "${!files[@]}"; do
|
for i in "${!files[@]}"; do
|
||||||
log "execute script ${files[$i]}"
|
log "executing script ${files[$i]}..."
|
||||||
awk 1 "${files[$i]}"
|
awk 1 "${files[$i]}"
|
||||||
done
|
done
|
||||||
interactive
|
interactive
|
||||||
|
@ -86,7 +79,13 @@ if [[ ${args[--interactive]} ]]; then
|
||||||
else
|
else
|
||||||
# case 3: just execute scripts
|
# case 3: just execute scripts
|
||||||
for i in "${!files[@]}"; do
|
for i in "${!files[@]}"; do
|
||||||
log "execute script ${files[$i]}"
|
log "executing script ${files[$i]}..."
|
||||||
bash -e <(awk 1 "${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
|
done
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue