Skip to content

Commit

Permalink
feat(prompt): indicate (ssh) on prompt when connected to a remote
Browse files Browse the repository at this point in the history
note: uber must be installed on the remote -- the prompt rendered when connected to
an ssh session is the remote prompt, not the local one. there is no way to automatically
override this prompt from the local side.
  • Loading branch information
Deavon M. McCaffery committed Aug 19, 2016
1 parent efbc65c commit ff4a33c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bookmarks.sh
backup/
7 changes: 6 additions & 1 deletion install
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ fi

if test -f ~/.bashprofile; then
cp ~/.bash_profile backup/bash_profile

if grep -q "~/.ssh/bashrc" ~/.bash_profile; then
cat template > ~/.bash_profile
fi
else
cat template > ~/.bash_profile
fi

cp -R ~/.ssh/* backup/ssh

cp -Rf src/* ~/.ssh
cat template > ~/.bash_profile
1 change: 1 addition & 0 deletions src/bashrc
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export CLR_BRIGHT_WHITE='\033[1;37m' # BRIGHT WHITE
export CLR_ROOT_PROMPT=$CLR_BRIGHT_RED # COLOR OF THE PROMPT FOR ROOT
export CLR_STAFF_PROMPT=$CLR_BRIGHT_GREEN # COLOR OF THE PROMPT FOR STAFF
export CLR_USER_PROMPT=$CLR_BRIGHT_BLUE # COLOR OF THE PROMPT FOR USERS
export CLR_SSH_PROMPT=$CLR_BRIGHT_MAGENTA # COLOR OF THE PROMPT FOR SSH

# enable colors for various commands
export TERM=xterm-256color
Expand Down
17 changes: 12 additions & 5 deletions src/scripts/set-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,25 @@ function emit-prompt-arrow()
if [ $(id -u) -eq 0 ]; then
CLR_PROMPT=$CLR_ROOT_PROMPT
fi

echo "\[${CLR_PROMPT}\] ==> \[${CLR_CLEAR}\]"

# set the color for an ssh session
if [ "$SSH_CONNECTION" ]; then
CLR_PROMPT=$CLR_SSH_PROMPT

# emit the prompt using the correct color
echo "\[${CLR_PROMPT}\] (ssh) ==> \[${CLR_CLEAR}\]"
else
# emit the prompt using the correct color
echo "\[${CLR_PROMPT}\] ==> \[${CLR_CLEAR}\]"
fi
}

function set-prompt() {
# set the window title
echo -ne "\033]0;${USER}@${HOSTNAME%%.*} ${PWD}\007"

# use the git prompt with the prompt arrow
export PROMPT_COMMAND='__git_ps1 "\n\u@\h : \w\n" "`emit-prompt-arrow`"'

# specify the two-line prompt with color-coded arrow
# export PS1="\n\u@\h : \w\n $(__git_ps1 '(%s)')\[${CLR_PROMPT}\] ==> \[${CLR_CLEAR}\]"
}

set-prompt
18 changes: 17 additions & 1 deletion src/scripts/show-colors.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
function show-colors() {
set | egrep 'CLR_w*'
echo

for color in $(env | awk '/^CLR_BRIGHT/' | cut -d= -f1 | sort); do
echo -e "${!color}\$$color${CLR_CLEAR}"
done

echo

for color in $(env | awk '/^CLR_/' | awk '!/^CLR_BRIGHT/' | awk '!/_PROMPT/' | cut -d= -f1 | sort); do
echo -e "${!color}\$$color${CLR_CLEAR}"
done

echo

for color in $(env | awk '/^CLR/' | awk '/_PROMPT/' | cut -d= -f1 | sort); do
echo -e "${!color}\$$color${CLR_CLEAR}"
done
}

function colors() {
Expand Down

0 comments on commit ff4a33c

Please sign in to comment.