diff --git a/sources/prompt_forwarding/local b/sources/prompt_forwarding/local index eae5beb..447beef 100644 --- a/sources/prompt_forwarding/local +++ b/sources/prompt_forwarding/local @@ -12,10 +12,10 @@ function gbt__local_rcfile() { GBT__CONF="/tmp/.gbt.$RANDOM" - cp $GBT__PROFILE $GBT__CONF + echo "export GBT__CONF='$GBT__CONF'" > $GBT__CONF + cat $GBT__PROFILE >> $GBT__CONF echo "$(alias | awk '/gbt_/ {sub(/^(alias |)(gbt___|)/, "", $0); print "alias "$0}')" >> $GBT__CONF echo "export GBT__STATUS='$(source $GBT__THEME; GBT_SHELL='bash' GBT_CARS='Status, Custom1' gbt 1)'" >> $GBT__CONF - echo "export GBT__CONF='\$GBT__CONF'" >> $GBT__CONF echo -n "PS1='" >> $GBT__CONF (source $GBT__THEME; gbt | awk '{gsub(/\\\$/, "$"); printf "%s", $0}') >> $GBT__CONF echo "'" >> $GBT__CONF @@ -32,6 +32,8 @@ function gbt_docker() { [ -z "$GBT__PROFILE" ] && GBT__PROFILE="$GBT__HOME/sources/prompt_forwarding/remote" [ -z "$GBT__THEME" ] && GBT__THEME="$GBT__HOME/themes/ssh_prompt" + local WHICH=$(which $GBT__WHICH_OPTS which 2>/dev/null) + [ -z $WHICH ] && gbt__err "'which' not found" && return 1 local DOCKER_BIN=$(which $GBT__WHICH_OPTS docker 2>/dev/null) [ $? -ne 0 ] && gbt__err "'docker' not found" && return 1 @@ -39,21 +41,11 @@ function gbt_docker() { $DOCKER_BIN $@ else local GBT__CONTAINER_ID="${@: -1}" - - [ -z "$GBT__CONF" ] && export GBT__CONF="/tmp/.gbt.$RANDOM" - - ( - echo "export GBT__CONF='$GBT__CONF'"; - cat $GBT__PROFILE; - echo "export GBT__STATUS='$(source $GBT__THEME; GBT_SHELL='bash' GBT_CARS='Status, Custom1' gbt 1)'"; - echo -n "PS1='"; - source $GBT__THEME; - gbt | awk '{gsub(/\\\$/, "$"); printf "%s", $0}'; - echo "'" - ) > $GBT__CONF + local GBT__CONF=$(gbt__local_rcfile) $DOCKER_BIN cp $GBT__CONF $GBT__CONTAINER_ID:$(dirname $GBT__CONF) $DOCKER_BIN exec ${@:2:$(($# - 2))} -it $GBT__CONTAINER_ID bash --rcfile $GBT__CONF + $DOCKER_BIN exec ${@:2:$(($# - 2))} -it $GBT__CONTAINER_ID rm -f $GBT__CONF $GBT__CONF.bash rm -f $GBT__CONF unset GBT__CONF @@ -66,6 +58,8 @@ function gbt_ssh() { [ -z "$GBT__PROFILE" ] && GBT__PROFILE="$GBT__HOME/sources/prompt_forwarding/remote" [ -z "$GBT__THEME" ] && GBT__THEME="$GBT__HOME/themes/ssh_prompt" + local WHICH=$(which $GBT__WHICH_OPTS which 2>/dev/null) + [ -z $WHICH ] && gbt__err "'which' not found" && return 1 local SSH_BIN=$(which $GBT__WHICH_OPTS ssh 2>/dev/null) [ $? -ne 0 ] && gbt__err "'ssh' not found" && return 1 @@ -86,8 +80,10 @@ function gbt_ssh() { } function gbt_su() { + local WHICH=$(which $GBT__WHICH_OPTS which 2>/dev/null) + [ -z $WHICH ] && gbt__err "'which' not found" && return 1 local SU_BIN=$(which $GBT__WHICH_OPTS su 2>/dev/null) - [ $? -ne 0 ] && gbt__err "'su' not found" && return 1 + [ $? -ne 0 ] && gbt__err "'su' not found" && return 1 local GBT__CONF=$(gbt__local_rcfile) @@ -97,8 +93,10 @@ function gbt_su() { } function gbt_sudo() { + local WHICH=$(which $GBT__WHICH_OPTS which 2>/dev/null) + [ -z $WHICH ] && gbt__err "'which' not found" && return 1 local SU_BIN=$(which $GBT__WHICH_OPTS su 2>/dev/null) - [ $? -ne 0 ] && gbt__err "'su' not found" && return 1 + [ $? -ne 0 ] && gbt__err "'su' not found" && return 1 local SUDO_BIN=$(which $GBT__WHICH_OPTS sudo 2>/dev/null) [ $? -ne 0 ] && gbt__err "'sudo' not found" && return 1 @@ -120,12 +118,15 @@ function gbt_vagrant() { [ -z "$GBT__PROFILE" ] && GBT__PROFILE="$GBT__HOME/sources/prompt_forwarding/remote" [ -z "$GBT__THEME" ] && GBT__THEME="$GBT__HOME/themes/ssh_prompt" + local WHICH=$(which $GBT__WHICH_OPTS which 2>/dev/null) + [ -z $WHICH ] && gbt__err "'which' not found" && return 1 local VAGRANT_BIN=$(which $GBT__WHICH_OPTS vagrant 2>/dev/null) [ $? -ne 0 ] && gbt__err "'vagrant' not found" && return 1 if [ "$1" != 'ssh' ]; then $VAGRANT_BIN $@ else + shift $VAGRANT_BIN ssh --command " cat /etc/motd 2>/dev/null; export GBT__CONF=\"/tmp/.gbt.$RANDOM\" && @@ -135,6 +136,6 @@ function gbt_vagrant() { echo \"export GBT__STATUS='$(source $GBT__THEME; GBT_SHELL='bash' GBT_CARS='Status, Custom1' gbt 1)'\" >> \$GBT__CONF && echo \"PS1='$(source $GBT__THEME; gbt)'\" >> \$GBT__CONF && bash --rcfile \$GBT__CONF; - rm -f \$GBT__CONF \$GBT__CONF.bash" + rm -f \$GBT__CONF \$GBT__CONF.bash" $@ fi } diff --git a/sources/prompt_forwarding/remote b/sources/prompt_forwarding/remote index 386ab48..a15b600 100644 --- a/sources/prompt_forwarding/remote +++ b/sources/prompt_forwarding/remote @@ -1,3 +1,4 @@ + declare -A GBT__SYMBOLS GBT__SYMBOLS[amzn]='\001\e[38;5;208m\002' GBT__SYMBOLS[arch]='\001\e[38;5;25m\002' @@ -44,6 +45,8 @@ function gbt__get_os() { } function gbt_docker() { + local WHICH=$(which $GBT__WHICH_OPTS which 2>/dev/null) + [ -z $WHICH ] && gbt__err "'which' not found" && return 1 local DOCKER_BIN=$(which $GBT__WHICH_OPTS docker 2>/dev/null) [ $? -ne 0 ] && gbt__err "'docker' not found" && return 1 @@ -54,18 +57,24 @@ function gbt_docker() { $DOCKER_BIN cp $GBT__CONF $GBT__CONTAINER_ID:$(dirname $GBT__CONF) $DOCKER_BIN exec ${@:2:$(($# - 2))} -it $GBT__CONTAINER_ID bash --rcfile $GBT__CONF + $DOCKER_BIN exec ${@:2:$(($# - 2))} -it $GBT__CONTAINER_ID rm -f $GBT__CONF $GBT__CONF.bash fi } + function gbt_su() { + local WHICH=$(which $GBT__WHICH_OPTS which 2>/dev/null) + [ -z $WHICH ] && gbt__err "'which' not found" && return 1 local SU_BIN=$(which $GBT__WHICH_OPTS su 2>/dev/null) - [ $? -ne 0 ] && gbt__err "'su' not found" && return 1 + [ $? -ne 0 ] && gbt__err "'su' not found" && return 1 $SU_BIN -s "$GBT__CONF.bash" $@ } function gbt_sudo() { + local WHICH=$(which $GBT__WHICH_OPTS which 2>/dev/null) + [ -z $WHICH ] && gbt__err "'which' not found" && return 1 local SU_BIN=$(which $GBT__WHICH_OPTS su 2>/dev/null) - [ $? -ne 0 ] && gbt__err "'su' not found" && return 1 + [ $? -ne 0 ] && gbt__err "'su' not found" && return 1 local SUDO_BIN=$(which $GBT__WHICH_OPTS sudo 2>/dev/null) [ $? -ne 0 ] && gbt__err "'sudo' not found" && return 1 @@ -78,6 +87,8 @@ function gbt_sudo() { } function gbt_ssh() { + local WHICH=$(which $GBT__WHICH_OPTS which 2>/dev/null) + [ -z $WHICH ] && gbt__err "'which' not found" && return 1 local SSH_BIN=$(which $GBT__WHICH_OPTS ssh 2>/dev/null) [ $? -ne 0 ] && gbt__err "'ssh' not found" && return 1 @@ -90,17 +101,20 @@ function gbt_ssh() { } function gbt_vagrant() { + local WHICH=$(which $GBT__WHICH_OPTS which 2>/dev/null) + [ -z $WHICH ] && gbt__err "'which' not found" && return 1 local VAGRNAT_BIN=$(which $GBT__WHICH_OPTS vagrant 2>/dev/null) [ $? -ne 0 ] && gbt__err "'vagrant' not found" && return 1 if [ "$1" != 'ssh' ]; then $VAGRANT_BIN $@ else + shift $VAGRANT_BIN ssh --command " cat /etc/motd 2>/dev/null; echo \"$(base64 $GBT__CONF | tr -d '\r\n')\" | base64 -d > $GBT__CONF && bash --rcfile $GBT__CONF; - rm -f $GBT__CONF $GBT__CONF.bash" + rm -f $GBT__CONF $GBT__CONF.bash" $@ fi }