From bdf17eb7052199751437690f40ff9d1ed955861d Mon Sep 17 00:00:00 2001 From: Omri Date: Sun, 11 Mar 2018 12:00:20 +0200 Subject: [PATCH 1/7] Added install script --- install | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 install diff --git a/install b/install new file mode 100755 index 0000000..902a72a --- /dev/null +++ b/install @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +function _goto_install_error() +{ + echo "$@" >&2 +} + + # sudo-check + if [ $EUID -ne 0 ]; then + _goto_install_error 'Please run this script in sudo mode or as root user' + exit + fi + + GOTO_FILE_LOCATION='/usr/local/share/goto.bash' + RC="" + if [ -f ~/.bashrc ]; then + RC="$HOME/.bashrc" + elif [ -f ~/.cshrc ]; then + RC="$HOME/.cshrc" + elif [ -f ~/.kshrc ]; then + RC="$HOME/.kshrc" + elif [ -f ~/.zshrc ]; then + RC="$HOME/.zshrc" + fi + + cp ./goto.bash "$GOTO_FILE_LOCATION" + + if [ -n "$RC" ]; then + # Append source to RC startup file if not already there + if [ `grep -c "source $GOTO_FILE_LOCATION" "$RC"` == "0" ]; then + # Append source to RC file + echo -e "\n#Source goto\nsource $GOTO_FILE_LOCATION\n" >> "$RC" + fi + source "$GOTO_FILE_LOCATION" + else + _goto_install_error "Error sourcing goto in your startup file.." + _goto_install_error "E.g ~/.bashrc ~/.cshrc etc.." + fi + From fe1ca689501cbc9f432c00f615ec85bee47e831e Mon Sep 17 00:00:00 2001 From: Omri Date: Sun, 11 Mar 2018 13:02:24 +0200 Subject: [PATCH 2/7] Updated readme's install --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b5c8737..5f6d8a0 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,11 @@ rubies /home/iridakos/.rvm/rubies ``` ## Installation - -Copy the file `goto.bash` somewhere in your filesystem and add a line in your `.bashrc` to source it. - -For example, if you placed the file in your home folder, all you have to do is add the following line to your `.bashrc` file: - +Clone the repository and run the install script as super user or root ```bash -source ~/goto.bash +git clone https://github.com/iridakos/goto.git +cd goto +sudo ./install ``` ## Usage From 3182b61b98e8e887cc92baa0c0941df138036d7e Mon Sep 17 00:00:00 2001 From: Lazarus Lazaridis Date: Mon, 12 Mar 2018 08:12:54 +0200 Subject: [PATCH 3/7] Fix shellcheck errors and warnings. --- install | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/install b/install index 902a72a..877fc8b 100755 --- a/install +++ b/install @@ -27,10 +27,12 @@ function _goto_install_error() if [ -n "$RC" ]; then # Append source to RC startup file if not already there - if [ `grep -c "source $GOTO_FILE_LOCATION" "$RC"` == "0" ]; then + if [ "$(grep -c "source $GOTO_FILE_LOCATION" "$RC")" == "0" ]; then # Append source to RC file - echo -e "\n#Source goto\nsource $GOTO_FILE_LOCATION\n" >> "$RC" + echo -e "\\n#Source goto\\nsource $GOTO_FILE_LOCATION\\n" >> "$RC" fi + + # shellcheck source=/dev/null source "$GOTO_FILE_LOCATION" else _goto_install_error "Error sourcing goto in your startup file.." From 2dde2ed27474ab42853689314ac8cbaa335e260f Mon Sep 17 00:00:00 2001 From: Lazarus Lazaridis Date: Mon, 12 Mar 2018 08:13:16 +0200 Subject: [PATCH 4/7] Add license info --- install | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/install b/install index 877fc8b..435cb56 100755 --- a/install +++ b/install @@ -1,4 +1,25 @@ #!/usr/bin/env bash +# MIT License +# +# Copyright (c) 2018 Lazarus Lazaridis +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. function _goto_install_error() { From 34a08a4bee376b1bfe08ac6868cf58f0acbb4e9b Mon Sep 17 00:00:00 2001 From: Lazarus Lazaridis Date: Mon, 12 Mar 2018 08:13:38 +0200 Subject: [PATCH 5/7] Fix indentation --- install | 61 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/install b/install index 435cb56..7a981d0 100755 --- a/install +++ b/install @@ -26,37 +26,36 @@ function _goto_install_error() echo "$@" >&2 } - # sudo-check - if [ $EUID -ne 0 ]; then - _goto_install_error 'Please run this script in sudo mode or as root user' - exit - fi - - GOTO_FILE_LOCATION='/usr/local/share/goto.bash' - RC="" - if [ -f ~/.bashrc ]; then - RC="$HOME/.bashrc" - elif [ -f ~/.cshrc ]; then - RC="$HOME/.cshrc" - elif [ -f ~/.kshrc ]; then - RC="$HOME/.kshrc" - elif [ -f ~/.zshrc ]; then - RC="$HOME/.zshrc" - fi - - cp ./goto.bash "$GOTO_FILE_LOCATION" - - if [ -n "$RC" ]; then - # Append source to RC startup file if not already there - if [ "$(grep -c "source $GOTO_FILE_LOCATION" "$RC")" == "0" ]; then - # Append source to RC file - echo -e "\\n#Source goto\\nsource $GOTO_FILE_LOCATION\\n" >> "$RC" - fi +# sudo-check +if [ $EUID -ne 0 ]; then + _goto_install_error 'Please run this script in sudo mode or as root user' + exit +fi - # shellcheck source=/dev/null - source "$GOTO_FILE_LOCATION" - else - _goto_install_error "Error sourcing goto in your startup file.." - _goto_install_error "E.g ~/.bashrc ~/.cshrc etc.." +GOTO_FILE_LOCATION='/usr/local/share/goto.bash' +RC="" +if [ -f ~/.bashrc ]; then + RC="$HOME/.bashrc" +elif [ -f ~/.cshrc ]; then + RC="$HOME/.cshrc" +elif [ -f ~/.kshrc ]; then + RC="$HOME/.kshrc" +elif [ -f ~/.zshrc ]; then + RC="$HOME/.zshrc" +fi + +cp ./goto.bash "$GOTO_FILE_LOCATION" + +if [ -n "$RC" ]; then + # Append source to RC startup file if not already there + if [ "$(grep -c "source $GOTO_FILE_LOCATION" "$RC")" == "0" ]; then + # Append source to RC file + echo -e "\\n#Source goto\\nsource $GOTO_FILE_LOCATION\\n" >> "$RC" fi + # shellcheck source=/dev/null + source "$GOTO_FILE_LOCATION" +else + _goto_install_error "Error sourcing goto in your startup file.." + _goto_install_error "E.g ~/.bashrc ~/.cshrc etc.." +fi From 4f47eac6064f7737aee6211fcf7de07a80925a92 Mon Sep 17 00:00:00 2001 From: Lazarus Lazaridis Date: Mon, 12 Mar 2018 08:25:49 +0200 Subject: [PATCH 6/7] Update goto script extension --- install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install b/install index 7a981d0..cbc0ed1 100755 --- a/install +++ b/install @@ -32,7 +32,7 @@ if [ $EUID -ne 0 ]; then exit fi -GOTO_FILE_LOCATION='/usr/local/share/goto.bash' +GOTO_FILE_LOCATION='/usr/local/share/goto.sh' RC="" if [ -f ~/.bashrc ]; then RC="$HOME/.bashrc" @@ -44,7 +44,7 @@ elif [ -f ~/.zshrc ]; then RC="$HOME/.zshrc" fi -cp ./goto.bash "$GOTO_FILE_LOCATION" +cp ./goto.sh "$GOTO_FILE_LOCATION" if [ -n "$RC" ]; then # Append source to RC startup file if not already there From 37f927cd263c65269dbfb4fbee168d424b7584f5 Mon Sep 17 00:00:00 2001 From: Lazarus Lazaridis Date: Mon, 12 Mar 2018 08:26:19 +0200 Subject: [PATCH 7/7] Check script existence before sourcing --- install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install b/install index cbc0ed1..e75ad5c 100755 --- a/install +++ b/install @@ -50,7 +50,7 @@ if [ -n "$RC" ]; then # Append source to RC startup file if not already there if [ "$(grep -c "source $GOTO_FILE_LOCATION" "$RC")" == "0" ]; then # Append source to RC file - echo -e "\\n#Source goto\\nsource $GOTO_FILE_LOCATION\\n" >> "$RC" + echo -e "\\n\\n# Source goto\\n[[ -s \"$GOTO_FILE_LOCATION\" ]] && source $GOTO_FILE_LOCATION\\n" >> "$RC" fi # shellcheck source=/dev/null