plugin/osx: shellcheck && shfmt
plugins/osx: dead code removal No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).
This commit is contained in:
@@ -103,6 +103,7 @@ plugins/available/jump.plugin.bash
|
|||||||
plugins/available/less-pretty-cat.plugin.bash
|
plugins/available/less-pretty-cat.plugin.bash
|
||||||
plugins/available/node.plugin.bash
|
plugins/available/node.plugin.bash
|
||||||
plugins/available/nodenv.plugin.bash
|
plugins/available/nodenv.plugin.bash
|
||||||
|
plugins/available/osx.plugin.bash
|
||||||
plugins/available/percol.plugin.bash
|
plugins/available/percol.plugin.bash
|
||||||
plugins/available/plenv.plugin.bash
|
plugins/available/plenv.plugin.bash
|
||||||
plugins/available/pyenv.plugin.bash
|
plugins/available/pyenv.plugin.bash
|
||||||
|
|||||||
@@ -1,23 +1,16 @@
|
|||||||
cite about-plugin
|
# shellcheck shell=bash
|
||||||
about-plugin 'osx-specific functions'
|
about-plugin 'osx-specific functions'
|
||||||
|
|
||||||
# OS X: Open new tabs in same directory
|
# OS X: Open new tabs in same directory
|
||||||
if [[ $OSTYPE == 'darwin'* ]]; then
|
if _is_function update_terminal_cwd; then
|
||||||
if type update_terminal_cwd > /dev/null 2>&1 ; then
|
safe_append_prompt_command 'update_terminal_cwd'
|
||||||
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
|
fi
|
||||||
|
|
||||||
function tab() {
|
function tab() {
|
||||||
about 'opens a new terminal tab'
|
about 'opens a new terminal tab'
|
||||||
group 'osx'
|
group 'osx'
|
||||||
|
|
||||||
osascript 2>/dev/null <<EOF
|
osascript 2> /dev/null << EOF
|
||||||
tell application "System Events"
|
tell application "System Events"
|
||||||
tell process "Terminal" to keystroke "t" using command down
|
tell process "Terminal" to keystroke "t" using command down
|
||||||
end
|
end
|
||||||
@@ -30,12 +23,12 @@ EOF
|
|||||||
|
|
||||||
# renames the current os x terminal tab title
|
# renames the current os x terminal tab title
|
||||||
function tabname {
|
function tabname {
|
||||||
printf "\e]1;$1\a"
|
printf '%b' "\e]1;$1\a"
|
||||||
}
|
}
|
||||||
|
|
||||||
# renames the current os x terminal window title
|
# renames the current os x terminal window title
|
||||||
function winname {
|
function winname {
|
||||||
printf "\e]2;$1\a"
|
printf '%b' "\e]2;$1\a"
|
||||||
}
|
}
|
||||||
|
|
||||||
# this one switches your os x dock between 2d and 3d
|
# this one switches your os x dock between 2d and 3d
|
||||||
@@ -46,42 +39,44 @@ function dock-switch() {
|
|||||||
example '$ dock-switch 2d'
|
example '$ dock-switch 2d'
|
||||||
group 'osx'
|
group 'osx'
|
||||||
|
|
||||||
if [[ "$OSTYPE" = 'darwin'* ]]; then
|
case $OSTYPE in
|
||||||
|
*'darwin'*)
|
||||||
if [[ $1 = 3d ]] ; then
|
case $1 in
|
||||||
|
3d)
|
||||||
defaults write com.apple.dock no-glass -boolean NO
|
defaults write com.apple.dock no-glass -boolean NO
|
||||||
killall Dock
|
killall Dock
|
||||||
|
;;
|
||||||
elif [[ $1 = 2d ]] ; then
|
2d)
|
||||||
defaults write com.apple.dock no-glass -boolean YES
|
defaults write com.apple.dock no-glass -boolean YES
|
||||||
killall Dock
|
killall Dock
|
||||||
|
;;
|
||||||
else
|
*)
|
||||||
echo "usage:"
|
echo "usage:"
|
||||||
echo "dock-switch 2d"
|
echo "dock-switch 2d"
|
||||||
echo "dock-switch 3d."
|
echo "dock-switch 3d."
|
||||||
fi
|
;;
|
||||||
else
|
esac
|
||||||
|
;;
|
||||||
|
*)
|
||||||
echo "Sorry, this only works on Mac OS X"
|
echo "Sorry, this only works on Mac OS X"
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
function pman ()
|
function pman() {
|
||||||
{
|
|
||||||
about 'view man documentation in Preview'
|
about 'view man documentation in Preview'
|
||||||
param '1: man page to view'
|
param '1: man page to view'
|
||||||
example '$ pman bash'
|
example '$ pman bash'
|
||||||
group 'osx'
|
group 'osx'
|
||||||
man -t "${1}" | open -fa $PREVIEW
|
man -t "${1}" | open -fa 'Preview'
|
||||||
}
|
}
|
||||||
|
|
||||||
function pri ()
|
function pri() {
|
||||||
{
|
|
||||||
about 'display information about Ruby classes, modules, or methods, in Preview'
|
about 'display information about Ruby classes, modules, or methods, in Preview'
|
||||||
param '1: Ruby method, module, or class'
|
param '1: Ruby method, module, or class'
|
||||||
example '$ pri Array'
|
example '$ pri Array'
|
||||||
group 'osx'
|
group 'osx'
|
||||||
ri -T "${1}" | open -fa $PREVIEW
|
ri -T "${1}" | open -fa 'Preview'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download a file and open it in Preview
|
# Download a file and open it in Preview
|
||||||
@@ -90,12 +85,11 @@ function prevcurl() {
|
|||||||
param '1: url'
|
param '1: url'
|
||||||
group 'osx'
|
group 'osx'
|
||||||
|
|
||||||
if [[ ! $OSTYPE = 'darwin'* ]]
|
if [[ ! $OSTYPE = 'darwin'* ]]; then
|
||||||
then
|
|
||||||
echo "This function only works with Mac OS X"
|
echo "This function only works with Mac OS X"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
curl "$*" | open -fa $PREVIEW
|
curl "$*" | open -fa 'Preview'
|
||||||
}
|
}
|
||||||
|
|
||||||
function refresh-launchpad() {
|
function refresh-launchpad() {
|
||||||
@@ -103,7 +97,7 @@ function refresh-launchpad() {
|
|||||||
example '$ refresh-launchpad'
|
example '$ refresh-launchpad'
|
||||||
group 'osx'
|
group 'osx'
|
||||||
|
|
||||||
if [[ "$OSTYPE" = 'darwin'* ]];then
|
if [[ "$OSTYPE" = 'darwin'* ]]; then
|
||||||
defaults write com.apple.dock ResetLaunchPad -bool TRUE
|
defaults write com.apple.dock ResetLaunchPad -bool TRUE
|
||||||
killall Dock
|
killall Dock
|
||||||
else
|
else
|
||||||
@@ -111,41 +105,41 @@ function refresh-launchpad() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function list-jvms(){
|
function list-jvms() {
|
||||||
about 'List java virtual machines and their states in macOS'
|
about 'List java virtual machines and their states in macOS'
|
||||||
example 'list-jvms'
|
example 'list-jvms'
|
||||||
group 'osx'
|
group 'osx'
|
||||||
|
|
||||||
JVMS_DIR="/Library/Java/JavaVirtualMachines"
|
local JVMS_DIR="/Library/Java/JavaVirtualMachines"
|
||||||
JVMS=( $(ls ${JVMS_DIR}) )
|
# The following variables are intended to impact the enclosing scope, not local.
|
||||||
|
JVMS=("${JVMS_DIR}"/*)
|
||||||
JVMS_STATES=()
|
JVMS_STATES=()
|
||||||
|
|
||||||
# Map state of JVM
|
# Map state of JVM
|
||||||
for (( i = 0; i < ${#JVMS[@]}; i++ )); do
|
for ((i = 0; i < ${#JVMS[@]}; i++)); do
|
||||||
if [[ -f "${JVMS_DIR}/${JVMS[$i]}/Contents/Info.plist" ]]; then
|
if [[ -f "${JVMS[i]}/Contents/Info.plist" ]]; then
|
||||||
JVMS_STATES[${i}]=enabled
|
JVMS_STATES[i]=enabled
|
||||||
else
|
else
|
||||||
JVMS_STATES[${i}]=disabled
|
JVMS_STATES[i]=disabled
|
||||||
fi
|
fi
|
||||||
echo "${i} ${JVMS[$i]} ${JVMS_STATES[$i]}"
|
printf '%s\t%s\t%s\n' "${i}" "${JVMS[i]##*/}" "${JVMS_STATES[i]}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function pick-default-jvm(){
|
function pick-default-jvm() {
|
||||||
about 'Pick the default Java Virtual Machines in system-wide scope in macOS'
|
about 'Pick the default Java Virtual Machines in system-wide scope in macOS'
|
||||||
example 'pick-default-jvm'
|
example 'pick-default-jvm'
|
||||||
|
|
||||||
|
# Declare variables
|
||||||
|
local JVMS JVMS_STATES
|
||||||
|
local DEFAULT_JVM_DIR DEFAULT_JVM OPTION
|
||||||
|
|
||||||
# Call function for listing
|
# Call function for listing
|
||||||
list-jvms
|
list-jvms
|
||||||
|
|
||||||
# Declare variables
|
|
||||||
local DEFAULT_JVM_DIR=""
|
|
||||||
local DEFAULT_JVM=""
|
|
||||||
local OPTION=""
|
|
||||||
|
|
||||||
# OPTION for default jdk and set variables
|
# OPTION for default jdk and set variables
|
||||||
while [[ ! "$OPTION" =~ ^[0-9]+$ || OPTION -ge "${#JVMS[@]}" ]]; do
|
while [[ ! "$OPTION" =~ ^[0-9]+$ || OPTION -ge "${#JVMS[@]}" ]]; do
|
||||||
read -p "Enter Default JVM: " OPTION
|
read -rp "Enter Default JVM: " OPTION
|
||||||
if [[ ! "$OPTION" =~ ^[0-9]+$ ]]; then
|
if [[ ! "$OPTION" =~ ^[0-9]+$ ]]; then
|
||||||
echo "Please enter a number"
|
echo "Please enter a number"
|
||||||
fi
|
fi
|
||||||
@@ -155,22 +149,19 @@ function pick-default-jvm(){
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
DEFAULT_JVM_DIR="${JVMS_DIR}/${JVMS[$OPTION]}"
|
DEFAULT_JVM_DIR="${JVMS[OPTION]}"
|
||||||
DEFAULT_JVM="${JVMS[$OPTION]}"
|
DEFAULT_JVM="${JVMS[OPTION]##*/}"
|
||||||
|
|
||||||
# Disable all jdk
|
# Disable all jdk
|
||||||
for (( i = 0; i < ${#JVMS[@]}; i++ )); do
|
for ((i = 0; i < ${#JVMS[@]}; i++)); do
|
||||||
if [[ -f "${JVMS_DIR}/${JVMS[$i]}/Contents/Info.plist" ]]; then
|
if [[ "${JVMS[i]}" != "${DEFAULT_JVM_DIR}" && -f "${JVMS[i]}/Contents/Info.plist" ]]; then
|
||||||
sudo mv "${JVMS_DIR}/${JVMS[$i]}/Contents/Info.plist" "${JVMS_DIR}/${JVMS[$i]}/Contents/Info.plist.disable"
|
sudo mv "${JVMS[i]}/Contents/Info.plist" "${JVMS[i]}/Contents/Info.plist.disable"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Enable default jdk
|
# Enable default jdk
|
||||||
if [[ -f "${DEFAULT_JVM_DIR}/Contents/Info.plist.disable" ]]; then
|
if [[ -f "${DEFAULT_JVM_DIR}/Contents/Info.plist.disable" ]]; then
|
||||||
sudo mv "${DEFAULT_JVM_DIR}/Contents/Info.plist.disable" "${DEFAULT_JVM_DIR}/Contents/Info.plist"
|
sudo mv -vn "${DEFAULT_JVM_DIR}/Contents/Info.plist.disable" "${DEFAULT_JVM_DIR}/Contents/Info.plist" \
|
||||||
echo "Enabled ${DEFAULT_JVM} as default JVM"
|
&& echo "Enabled ${DEFAULT_JVM} as default JVM"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Make this backwards compatible
|
|
||||||
alias pcurl='prevcurl'
|
|
||||||
|
|||||||
Reference in New Issue
Block a user