1
\$\begingroup\$

This is the new code after following the advice from here:

Setting up a development environment

General feedback is requested. Also, should I be using $() or () for my sub-shell. What is the difference.

#
#
#
# Divider - configures bash, git, grunt, sublime and chrome
#
#
#
user1=foo
config_bash() {
 rm ~/.bash_profile
 ln -sf ~/root/config/bash/login.sh ~/.bash_profile
 source ~/.bash_profile
 echo "Bash configured."
}
config_git() {
 local a
 if [ $# -eq 0 ]
 then
 a="client"
 fi
 if [ $# -eq 1 ]
 then
 a="1ドル"
 fi
 if [ $# -gt 1 ]
 then
 a="1ドル"
 echo "Git-tooo many arguments"
 fi
 git config --global user.name "$a"
 git config --global user.email "$a@$a.com" 
 git config --global push.default matching
 git config --global core.editor "subl"
 git remote add godaddy [email protected]:~/root.git
 git remote add heroku https://git.heroku.com/frozen-dusk-2587.git
 echo "Git configured." 
}
config_grunt() {
 sudo npm install -g grunt-cli
 mkdir -p ~/root_install/grunt
 ln -sf ~/root/config/grunt/package.json ~/root_install/grunt/package.json
 ln -sf ~/root/config/grunt/Gruntfile.js ~/root_install/grunt/Gruntfile.js
 (cd ~/root_install/grunt; npm install)
 cd ~/root
 echo "Grunt configured."
} 
config_sublime_2() {
 ln -sf /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
 rm -rf ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User
 ln -sf ~/root/config/sublime ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User
 echo "Sublime configured."
}
reset_sublime_2() {
 rm -rf ~/Library/Application\ Support/Sublime\ Text\ 2
}
config_chrome(){
 chmod 0444 ~/Library/Application\ Support/Google/Chrome/Default/History
 echo "Chrome configured."
}
config_all() {
 config_bash
 config_git
 config_grunt
 config_sublime_2
 config_chrome
 list
}
list(){
 local bash=$(which bash) git=$(which git) grunt=$(which grunt) subl=$(which subl)
 local node=$(which node) heroku=$(which heroku)
 echo "****" 
 echo "Your bash executble is here: $bash." 
 echo "Your git executble is here: $git." 
 echo "Your grunt executble is here: $grunt."
 echo "Your sublime executble is here: $subl."
 echo "Your node executble is here: $node."
 echo "Your heroku executble is here: $heroku."
 echo "****"
}
asked Mar 11, 2016 at 21:32
\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Code Review! Please add more context to your question. What is your code doing? What improvements have you made from the other post's code? \$\endgroup\$ Commented Mar 11, 2016 at 23:46
  • \$\begingroup\$ Why did you create a new account instead of posting this with the other one? \$\endgroup\$ Commented Mar 12, 2016 at 6:13

1 Answer 1

1
\$\begingroup\$

These conditions are mutually exclusive, so they should be chained using elif:

if [ $# -eq 0 ]
then
 a="client"
fi
if [ $# -eq 1 ]
then
 a="1ドル"
fi
if [ $# -gt 1 ]
then
 a="1ドル"
 echo "Git-tooo many arguments"
fi

Like this:

if [ $# -eq 0 ]
then
 a="client"
elif [ $# -eq 1 ]
then
 a="1ドル"
else
 a="1ドル"
 echo "Git-tooo many arguments"
fi

This avoids unnecessary evaluations. That is, when $# is 0, only the first condition will be evaluated, the others won't be. In your original code, all conditions will be evaluated always.


As mentioned in the previous review, changing directory inside a script is not recommended. In config_grunt you have this as the last statement of the function:

cd ~/root

It seems pointless, and as it doesn't seem to have anything to do with configuring grunt, it probably shouldn't be in this function.

answered Mar 12, 2016 at 15:18
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.