Skip to content

Commit de9ea54

Browse files
authored
Don't call external uname when $OSTYPE will do (#1911)
* lib/helpers: use `$OSTYPE` instead of `$(uname)` * plugins/osx: use `$OSTYPE` instead of `$(uname)` * plugins/boot2docker: use `$OSTYPE` instead of `$(uname)` * plugins/python: use `$OSTYPE` instead of `$(uname)` * plugins/base: use `$OSTYPE` instead of `$(uname)` Alsö, use `[[` instead of `[` as the former has less insane argument handling being shell syntax rather than a builtin command that must emulate being a real binary * completion/brew: use `$OSTYPE` instead of `$(uname)` * completion/git: use `$OSTYPE` instead of `$(uname)` Alsö, use `[[` instead of `[`. * completion/fabric: use `$OSTYPE` instead of `uname` * theme/demula: use `$OSTYPE` instead of `$(uname)` * theme/rana: use `$OSTYPE` instead of `$(uname)`
1 parent e321a3d commit de9ea54

File tree

10 files changed

+30
-29
lines changed

10 files changed

+30
-29
lines changed

completion/available/brew.completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ about-completion "brew completion"
55
# Load late to make sure `system` completion loads first
66
# BASH_IT_LOAD_PRIORITY: 375
77

8-
if [[ "$(uname -s)" != 'Darwin' ]]; then
8+
if [[ "$OSTYPE" != 'darwin'* ]]; then
99
_log_warning "unsupported operating system - only 'Darwin' is supported"
1010
return 0
1111
fi

completion/available/fabric.completion.bash

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export FAB_COMPLETION_CACHED_TASKS_FILENAME=".fab_tasks~"
4141

4242

4343
# Set command to get time of last file modification as seconds since Epoch
44-
case `uname` in
45-
Darwin|FreeBSD)
44+
case "$OSTYPE" in
45+
'darwin'*|'freebsd'*)
4646
__FAB_COMPLETION_MTIME_COMMAND="stat -f '%m'"
4747
;;
4848
*)

completion/available/git.completion.bash

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# Only operate on MacOS since there are no linux paths
4-
if [[ "$(uname -s)" != 'Darwin' ]] ; then
4+
if [[ "$OSTYPE" != 'darwin'* ]] ; then
55
_log_warning "unsupported operating system - only 'Darwin' is supported"
66
return 0
77
fi
@@ -24,7 +24,7 @@ _git_bash_completion_paths=(
2424

2525
# Load the first completion file found
2626
for _comp_path in "${_git_bash_completion_paths[@]}" ; do
27-
if [ -r "$_comp_path" ] ; then
27+
if [[ -r "$_comp_path" ]] ; then
2828
_git_bash_completion_found=true
2929
source "$_comp_path"
3030
break

lib/helpers.bash

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ BASH_IT_LOAD_PRIORITY_SEPARATOR="---"
1111
# To use this in Bash-it for inline replacements with `sed`, use the following syntax:
1212
# sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file
1313
BASH_IT_SED_I_PARAMETERS=(-i)
14-
case "$(uname)" in
15-
Darwin*) BASH_IT_SED_I_PARAMETERS=(-i "")
14+
case "$OSTYPE" in
15+
'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "")
1616
esac
1717

1818
function _command_exists ()

plugins/available/base.plugin.bash

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function myip ()
3333
for url in ${list[*]}
3434
do
3535
res=$(curl -fs "${url}")
36-
if [ $? -eq 0 ];then
36+
if [[ $? -eq 0 ]];then
3737
break;
3838
fi
3939
done
@@ -48,7 +48,7 @@ function pickfrom ()
4848
example '$ pickfrom /usr/share/dict/words'
4949
group 'base'
5050
local file=$1
51-
[ -z "$file" ] && reference $FUNCNAME && return
51+
[[ -z "$file" ]] && reference $FUNCNAME && return
5252
length=$(cat $file | wc -l)
5353
n=$(expr $RANDOM \* $length \/ 32768 + 1)
5454
head -n $n $file | tail -1
@@ -70,7 +70,7 @@ function passgen ()
7070

7171
# Create alias pass to passgen when pass isn't installed or
7272
# BASH_IT_LEGACY_PASS is true.
73-
if ! command -v pass &>/dev/null || [ "$BASH_IT_LEGACY_PASS" = true ]
73+
if ! command -v pass &>/dev/null || [[ "$BASH_IT_LEGACY_PASS" = true ]]
7474
then
7575
alias pass=passgen
7676
fi
@@ -129,23 +129,24 @@ function usage ()
129129
about 'disk usage per directory, in Mac OS X and Linux'
130130
param '1: directory name'
131131
group 'base'
132-
if [ $(uname) = "Darwin" ]; then
132+
if [[ "$OSTYPE" == 'darwin'* ]]; then
133133
if [ -n "$1" ]; then
134134
du -hd 1 "$1"
135135
else
136136
du -hd 1
137137
fi
138138

139-
elif [ $(uname) = "Linux" ]; then
140-
if [ -n "$1" ]; then
139+
elif [[ "$OSTYPE" = 'linux'* ]]; then
140+
if [[ -n "$1" ]]; then
141141
du -h --max-depth=1 "$1"
142142
else
143143
du -h --max-depth=1
144144
fi
145145
fi
146146
}
147147

148-
if [ ! -e "${BASH_IT}/plugins/enabled/todo.plugin.bash" ] && [ ! -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}todo.plugin.bash" ]; then
148+
if [[ ! -e "${BASH_IT}/plugins/enabled/todo.plugin.bash" ]] && [[ ! -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}todo.plugin.bash" ]]
149+
then
149150
# if user has installed todo plugin, skip this...
150151
function t ()
151152
{
@@ -180,11 +181,11 @@ mkiso ()
180181
group 'base'
181182

182183
if type "mkisofs" > /dev/null; then
183-
[ -z ${1+x} ] && local isoname=${PWD##*/} || local isoname=$1
184-
[ -z ${2+x} ] && local destpath=../ || local destpath=$2
185-
[ -z ${3+x} ] && local srcpath=${PWD} || local srcpath=$3
184+
[[ -z ${1+x} ]] && local isoname=${PWD##*/} || local isoname=$1
185+
[[ -z ${2+x} ]] && local destpath=../ || local destpath=$2
186+
[[ -z ${3+x} ]] && local srcpath=${PWD} || local srcpath=$3
186187

187-
if [ ! -f "${destpath}${isoname}.iso" ]; then
188+
if [[ ! -f "${destpath}${isoname}.iso" ]]; then
188189
echo "writing ${isoname}.iso to ${destpath} from ${srcpath}"
189190
mkisofs -V ${isoname} -iso-level 3 -r -o "${destpath}${isoname}.iso" "${srcpath}"
190191
else

plugins/available/boot2docker.plugin.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ about-plugin 'Helpers to get Docker setup correctly for boot2docker'
33

44
# Note, this might need to be different if you have an older version
55
# of boot2docker, or its configured for a different IP
6-
if [[ `uname -s` == "Darwin" ]]; then
6+
if [[ "$OSTYPE" == 'darwin'* ]]; then
77
export DOCKER_HOST="tcp://192.168.59.103:2376"
88
export DOCKER_CERT_PATH="~/.boot2docker/certs/boot2docker-vm"
99
export DOCKER_TLS_VERIFY=1

plugins/available/osx.plugin.bash

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cite about-plugin
22
about-plugin 'osx-specific functions'
33

44
# OS X: Open new tabs in same directory
5-
if [ $(uname) = "Darwin" ]; then
5+
if [[ $OSTYPE == 'darwin'* ]]; then
66
if type update_terminal_cwd > /dev/null 2>&1 ; then
77
if ! [[ $PROMPT_COMMAND =~ (^|;)update_terminal_cwd($|;) ]] ; then
88
PROMPT_COMMAND="${PROMPT_COMMAND%;};update_terminal_cwd"
@@ -46,13 +46,13 @@ function dock-switch() {
4646
example '$ dock-switch 2d'
4747
group 'osx'
4848

49-
if [ $(uname) = "Darwin" ]; then
49+
if [[ "$OSTYPE" = 'darwin'* ]]; then
5050

51-
if [ $1 = 3d ] ; then
51+
if [[ $1 = 3d ]] ; then
5252
defaults write com.apple.dock no-glass -boolean NO
5353
killall Dock
5454

55-
elif [ $1 = 2d ] ; then
55+
elif [[ $1 = 2d ]] ; then
5656
defaults write com.apple.dock no-glass -boolean YES
5757
killall Dock
5858

@@ -90,7 +90,7 @@ function prevcurl() {
9090
param '1: url'
9191
group 'osx'
9292

93-
if [ ! $(uname) = "Darwin" ]
93+
if [[ ! $OSTYPE = 'darwin'* ]]
9494
then
9595
echo "This function only works with Mac OS X"
9696
return 1
@@ -103,7 +103,7 @@ function refresh-launchpad() {
103103
example '$ refresh-launchpad'
104104
group 'osx'
105105

106-
if [ $(uname) = "Darwin" ];then
106+
if [[ "$OSTYPE" = 'darwin'* ]];then
107107
defaults write com.apple.dock ResetLaunchPad -bool TRUE
108108
killall Dock
109109
else

plugins/available/python.plugin.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cite about-plugin
22
about-plugin 'alias "shttp" to SimpleHTTPServer'
33

4-
if [ $(uname) = "Linux" ]
4+
if [[ "$OSTYPE" == 'linux'* ]]
55
then
66
alias shttp='python2 -m SimpleHTTPServer'
77
else
@@ -16,7 +16,7 @@ function pyedit() {
1616

1717
xpyc=`python -c "import os, sys; f = open(os.devnull, 'w'); sys.stderr = f; module = __import__('$1'); sys.stdout.write(module.__file__)"`
1818

19-
if [ "$xpyc" == "" ]; then
19+
if [[ "$xpyc" == "" ]]; then
2020
echo "Python module $1 not found"
2121
return -1
2222

themes/demula/demula.theme.bash

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ prompt() {
9898
local MOVE_CURSOR_RIGHTMOST='\033[500C'
9999
local MOVE_CURSOR_5_LEFT='\033[5D'
100100

101-
if [ $(uname) = "Linux" ];
101+
if [[ "$OSTYPE" = 'linux'* ]]
102102
then
103103
PS1="${TITLEBAR}${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}
104104
$(safe_battery_charge)${RESTORE_CURSOR}\

themes/rana/rana.theme.bash

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ prompt() {
181181
local MOVE_CURSOR_RIGHTMOST='\033[500C'
182182
local MOVE_CURSOR_5_LEFT='\033[5D'
183183

184-
if [ $(uname) = "Linux" ];
184+
if [[ "$OSTYPE" == 'linux'* ]];
185185
then
186186
PS1="${TITLEBAR}
187187
${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\

0 commit comments

Comments
 (0)