2016-03-01 13:26:35 -08:00
|
|
|
#!/usr/bin/env bash
|
2019-01-07 01:04:17 -05:00
|
|
|
set -eo pipefail
|
|
|
|
|
[[ $DOKKU_TRACE ]] && set -x
|
2016-03-01 13:26:35 -08:00
|
|
|
|
2020-02-09 22:41:39 -05:00
|
|
|
cmd-shell-default() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="dokku shell interpreter via command line"
|
2020-02-10 01:40:30 -05:00
|
|
|
declare cmd="shell"
|
2016-03-01 13:26:35 -08:00
|
|
|
local INPUTRC="$PLUGIN_ROOT/inputrc"
|
|
|
|
|
local HISTFILE=~/.dokku_history
|
|
|
|
|
|
|
|
|
|
history -r || true
|
|
|
|
|
|
2019-01-07 01:04:17 -05:00
|
|
|
trim() {
|
2016-03-01 13:26:35 -08:00
|
|
|
sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trap 'history -w' EXIT
|
|
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
|
trap '' SIGINT
|
|
|
|
|
read -rep "dokku> " line || {
|
2019-01-07 01:04:17 -05:00
|
|
|
echo
|
|
|
|
|
true
|
|
|
|
|
break
|
2016-03-01 13:26:35 -08:00
|
|
|
}
|
|
|
|
|
trap - SIGINT
|
|
|
|
|
|
|
|
|
|
local line=$(echo "$line" | trim)
|
|
|
|
|
local CMD=$(echo "$line" | awk '{ print $1 }')
|
|
|
|
|
|
|
|
|
|
[[ -z $CMD ]] && continue
|
|
|
|
|
|
|
|
|
|
[[ "$line" != "$(fc -ln -1 | trim)" ]] && history -s "$line"
|
|
|
|
|
|
|
|
|
|
case $CMD in
|
|
|
|
|
# shell builtins
|
|
|
|
|
clear)
|
|
|
|
|
clear
|
|
|
|
|
;;
|
|
|
|
|
|
2019-01-07 01:04:17 -05:00
|
|
|
quit | exit)
|
2016-03-01 13:26:35 -08:00
|
|
|
break
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
# Not a built-in, run as regular dokku command
|
|
|
|
|
*)
|
|
|
|
|
dokku $line || true
|
2019-01-07 01:04:17 -05:00
|
|
|
;;
|
2016-03-01 13:26:35 -08:00
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-09 22:41:39 -05:00
|
|
|
cmd-shell-default
|