Skip to content

Commit

Permalink
Fixing GBT__HOME priority, gbt_vagrant arguments, gbt_docker cleanup …
Browse files Browse the repository at this point in the history
…and the which command detection
  • Loading branch information
jtyr committed Nov 19, 2017
1 parent 262576f commit cf62b70
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
35 changes: 18 additions & 17 deletions sources/prompt_forwarding/local
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,28 +32,20 @@ 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

if [ "$1" != 'shell' ]; then
$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
Expand All @@ -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

Expand All @@ -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)

Expand All @@ -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

Expand All @@ -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\" &&
Expand All @@ -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
}
20 changes: 17 additions & 3 deletions sources/prompt_forwarding/remote
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
}

Expand Down

0 comments on commit cf62b70

Please sign in to comment.