From 0d7ee4866be581902e8c1a41f6eb4bd41541e94c Mon Sep 17 00:00:00 2001 From: Trey Hunner Date: Thu, 20 Oct 2011 10:32:44 -0700 Subject: [PATCH 1/2] Remove dependence on bash in install.sh Replace bashisms with syntax supported by all posix-compliant shells. The echo command does not support -e in many simplified shells (including dash) so printf is favored. The [[ ... ]] notation is also not accepted by all posix shells so [ ... ] notation is used instead. --- install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 7035d68..08f41db 100755 --- a/install.sh +++ b/install.sh @@ -1,12 +1,12 @@ -#!/bin/bash +#!/bin/sh # This loads SCM Breeze into the shell session. -exec_string='[[ -s "$HOME/.scm_breeze/scm_breeze.sh" ]] && . "$HOME/.scm_breeze/scm_breeze.sh"' +exec_string='[ -s "$HOME/.scm_breeze/scm_breeze.sh" ] && . "$HOME/.scm_breeze/scm_breeze.sh"' # Add line to bashrc and zshrc if not already present. for rc in bashrc zshrc; do - if [[ -s "$HOME/.$rc" ]] && ! grep -q "$exec_string" "$HOME/.$rc"; then - echo -e "\n$exec_string" >> "$HOME/.$rc" - echo "== Added SCM Breeze to '~/.$rc'" + if [ -s "$HOME/.$rc" ] && ! grep -q "$exec_string" "$HOME/.$rc"; then + printf "\n$exec_string\n" >> "$HOME/.$rc" + printf "== Added SCM Breeze to '~/.$rc'\n" fi done From f9244d0f940b507d34fefc3ffec2b192094c0c53 Mon Sep 17 00:00:00 2001 From: Trey Hunner Date: Thu, 20 Oct 2011 10:47:19 -0700 Subject: [PATCH 2/2] Remove bashisms from scm breeze update scripts --- lib/scm_breeze.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/scm_breeze.sh b/lib/scm_breeze.sh index 9176bea..2133003 100644 --- a/lib/scm_breeze.sh +++ b/lib/scm_breeze.sh @@ -1,10 +1,10 @@ # Detect shell if [ -n "${ZSH_VERSION:-}" ]; then shell="zsh"; else shell="bash"; fi # Detect whether zsh 'shwordsplit' option is on by default. -if [[ $shell == "zsh" ]]; then zsh_shwordsplit=$((setopt | grep -q shwordsplit) && echo "true"); fi +if [ $shell = "zsh" ]; then zsh_shwordsplit=$( (setopt | grep -q shwordsplit) && echo "true" ); fi # Switch on/off shwordsplit for functions that require it. -zsh_compat(){ if [[ $shell == "zsh" && -z $zsh_shwordsplit ]]; then setopt shwordsplit; fi; } -zsh_reset(){ if [[ $shell == "zsh" && -z $zsh_shwordsplit ]]; then unsetopt shwordsplit; fi; } +zsh_compat(){ if [ $shell = "zsh" && -z $zsh_shwordsplit ]; then setopt shwordsplit; fi; } +zsh_reset(){ if [ $shell = "zsh" && -z $zsh_shwordsplit ]; then unsetopt shwordsplit; fi; } # Alias wrapper that ignores errors if alias is not defined. _alias(){ alias "$@" 2> /dev/null; } @@ -31,7 +31,7 @@ _create_or_patch_scmbrc() { # Create file from example if it doesn't already exist if ! [ -e "$HOME/.$scm.scmbrc" ]; then cp "$HOME/.scm_breeze/$scm.scmbrc.example" "$HOME/.$scm.scmbrc" - echo "== '~/.$scm.scmbrc' has been created. Please edit this file to change SCM Breeze settings for '$scm'." + printf "== '~/.$scm.scmbrc' has been created. Please edit this file to change SCM Breeze settings for '$scm'.\n" # If file exists, attempt to update it with any new settings elif [ -n "$1" ]; then # Create diff of example file, substituting example file for user's config. @@ -40,8 +40,8 @@ _create_or_patch_scmbrc() { cd $HOME # If the patch cannot be applied cleanly, show the updates and tell user to update file manually. if ! patch -f "$HOME/.$scm.scmbrc" $patchfile; then - echo -e "== \e[0;31mUpdates could not be applied to '\e[1m~/.$scm.scmbrc\e[0;31m'.\e[0m" - echo -e "== Please look at the following changes and manually update '~/.$scm.scmbrc', if necessary.\n" + printf "== \e[0;31mUpdates could not be applied to '\e[1m~/.$scm.scmbrc\e[0;31m'.\e[0m\n" + printf "== Please look at the following changes and manually update '~/.$scm.scmbrc', if necessary.\n\n" cat "$HOME/.$scm.scmbrc.rej" fi cd "$scmbDir"