This commit fixes an issue with themes on OS X which are sometimes left in a partially broken environment with missing dependencies. When a `BASH_IT_THEME` is active on OS X and has a dynamic `PROMPT_COMMAND` which is not exported, and such `PROMPT_COMMAND` is backed by shell functions which are not exported either, and at the same time the theme is not OS-X-aware (regarding `update_terminal_cwd`), and the user launches a (non-login) interactive subshell from the OS X Terminal, a `command not found` appears on every command invocation. The issue is caused by a regression in PR #514, which attempts to inject `update_terminal_cwd` into the prompt. As a side effect, it also escalates the exportedness of `PROMPT_COMMAND` while the theme-specific backing functions (which power the dynamic prompt) remain unexported. The subshell cannot recover from this partially broken environment because unlike in Linux, Bash-it on OS X is not invoked for non-login subshells. The dependencies remain broken which leads to the error. The fix is to preserve `PROMPT_COMMAND`’s exportedness on OS X, leaving the individual theme responsible for consistently exporting either all or nothing of its environment.
103 lines
2.4 KiB
Bash
103 lines
2.4 KiB
Bash
cite about-plugin
|
|
about-plugin 'osx-specific functions'
|
|
|
|
# OS X: Open new tabs in same directory
|
|
if [ $(uname) = "Darwin" ]; then
|
|
if type update_terminal_cwd > /dev/null 2>&1 ; then
|
|
if ! [[ $PROMPT_COMMAND =~ (^|;)update_terminal_cwd($|;) ]] ; then
|
|
PROMPT_COMMAND="$PROMPT_COMMAND;update_terminal_cwd"
|
|
declared="$(declare -p PROMPT_COMMAND)"
|
|
[[ "$declared" =~ \ -[aAilrtu]*x[aAilrtu]*\ ]] 2>/dev/null
|
|
[[ $? -eq 0 ]] && export PROMPT_COMMAND
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
function tab() {
|
|
about 'opens a new terminal tab'
|
|
group 'osx'
|
|
|
|
osascript 2>/dev/null <<EOF
|
|
tell application "System Events"
|
|
tell process "Terminal" to keystroke "t" using command down
|
|
end
|
|
tell application "Terminal"
|
|
activate
|
|
do script with command " cd \"$PWD\"; $*" in window 0
|
|
end tell
|
|
EOF
|
|
}
|
|
|
|
# renames the current os x terminal tab title
|
|
function tabname {
|
|
printf "\e]1;$1\a"
|
|
}
|
|
|
|
# renames the current os x terminal window title
|
|
function winname {
|
|
printf "\e]2;$1\a"
|
|
}
|
|
|
|
# this one switches your os x dock between 2d and 3d
|
|
# thanks to savier.zwetschge.org
|
|
function dock-switch() {
|
|
about 'switch dock between 2d and 3d'
|
|
param '1: "2d" or "3d"'
|
|
example '$ dock-switch 2d'
|
|
group 'osx'
|
|
|
|
if [ $(uname) = "Darwin" ]; then
|
|
|
|
if [ $1 = 3d ] ; then
|
|
defaults write com.apple.dock no-glass -boolean NO
|
|
killall Dock
|
|
|
|
elif [ $1 = 2d ] ; then
|
|
defaults write com.apple.dock no-glass -boolean YES
|
|
killall Dock
|
|
|
|
else
|
|
echo "usage:"
|
|
echo "dock-switch 2d"
|
|
echo "dock-switch 3d."
|
|
fi
|
|
else
|
|
echo "Sorry, this only works on Mac OS X"
|
|
fi
|
|
}
|
|
|
|
function pman ()
|
|
{
|
|
about 'view man documentation in Preview'
|
|
param '1: man page to view'
|
|
example '$ pman bash'
|
|
group 'osx'
|
|
man -t "${1}" | open -fa $PREVIEW
|
|
}
|
|
|
|
function pri ()
|
|
{
|
|
about 'display information about Ruby classes, modules, or methods, in Preview'
|
|
param '1: Ruby method, module, or class'
|
|
example '$ pri Array'
|
|
group 'osx'
|
|
ri -T "${1}" | open -fa $PREVIEW
|
|
}
|
|
|
|
# Download a file and open it in Preview
|
|
function prevcurl() {
|
|
about 'download a file and open it in Preview'
|
|
param '1: url'
|
|
group 'osx'
|
|
|
|
if [ ! $(uname) = "Darwin" ]
|
|
then
|
|
echo "This function only works with Mac OS X"
|
|
return 1
|
|
fi
|
|
curl "$*" | open -fa $PREVIEW
|
|
}
|
|
|
|
# Make this backwards compatible
|
|
alias pcurl='prevcurl'
|