Skip to content

Commit

Permalink
Merge pull request #148 from nigels-com/setup_extraterm_bash
Browse files Browse the repository at this point in the history
Early-out from setup_extraterm_bash.sh if aliases already setup (avoi…
  • Loading branch information
sedwards2009 authored Dec 31, 2018
2 parents 6e901ce + 1e7087b commit 6102503
Showing 1 changed file with 55 additions and 43 deletions.
98 changes: 55 additions & 43 deletions extraterm/src/commands/setup_extraterm_bash.sh
Original file line number Diff line number Diff line change
@@ -1,50 +1,62 @@
# This file should be sourced from your .bashrc file.
#
# Copyright 2014-2016 Simon Edwards <[email protected]>
# Copyright 2014-2018 Simon Edwards <[email protected]>
#
# This source code is licensed under the MIT license which is detailed in the LICENSE.txt file.
#

if [ -n "$LC_EXTRATERM_COOKIE" ]; then
echo "Setting up Extraterm support."

# Put our enhanced commands at the start of the PATH.
filedir=`dirname "$BASH_SOURCE"`
if [ ${filedir:0:1} != "/" ]
then
filedir="$PWD/$filedir"
fi

export PATH="$filedir:$PATH"

PREVIOUS_PROMPT_COMMAND=$PROMPT_COMMAND
postexec () {
echo -n -e "\033&${LC_EXTRATERM_COOKIE};3\007"
echo -n $1
echo -n -e "\000"
$PREVIOUS_PROMPT_COMMAND
}
export PROMPT_COMMAND="postexec \$?"

preexec () {
echo -n -e "\033&${LC_EXTRATERM_COOKIE};2;bash\007"
echo -n $1
echo -n -e "\000"
}

preexec_invoke_exec () {
[ -n "$COMP_LINE" ] && return # do nothing if completing
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # don't cause a preexec for $PROMPT_COMMAND
local this_command=`history 1`; # obtain the command from the history
preexec "$this_command"
}
trap 'preexec_invoke_exec' DEBUG

# Look for Python 3 support.
if ! which python3 > /dev/null; then
echo "Unable to find the Python3 executable!"
else
alias from="exfrom.py"
alias show="exshow.py"
fi
# Early-out in case this has been sourced and enabled already
# https://github.com/sedwards2009/extraterm/pull/148

isfunction () {
type $1 2> /dev/null | head -n1 | grep "$1 is a function" > /dev/null
}

if ( isfunction "postexec" ); then return 0; fi
if ( isfunction "preexec" ); then return 0; fi
if ( isfunction "preexec_invoke_exec" ); then return 0; fi

# Early-out if LC_EXTRATERM_COOKIE is not set
if [ -z "$LC_EXTRATERM_COOKIE" ]; then return 0; fi

echo "Setting up Extraterm support."

# Put our enhanced commands at the start of the PATH.
filedir=`dirname "$BASH_SOURCE"`
if [ ${filedir:0:1} != "/" ]
then
filedir="$PWD/$filedir"
fi

export PATH="$filedir:$PATH"

PREVIOUS_PROMPT_COMMAND=$PROMPT_COMMAND
postexec () {
echo -n -e "\033&${LC_EXTRATERM_COOKIE};3\007"
echo -n $1
echo -n -e "\000"
$PREVIOUS_PROMPT_COMMAND
}
export PROMPT_COMMAND="postexec \$?"

preexec () {
echo -n -e "\033&${LC_EXTRATERM_COOKIE};2;bash\007"
echo -n $1
echo -n -e "\000"
}

preexec_invoke_exec () {
[ -n "$COMP_LINE" ] && return # do nothing if completing
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # don't cause a preexec for $PROMPT_COMMAND
local this_command=`history 1`; # obtain the command from the history
preexec "$this_command"
}
trap 'preexec_invoke_exec' DEBUG

# Look for Python 3 support.
if ! which python3 > /dev/null; then
echo "Unable to find the Python3 executable!"
else
alias from="exfrom.py"
alias show="exshow.py"
fi

0 comments on commit 6102503

Please sign in to comment.