├── LICENCE ├── README.md └── bin └── gst /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Lucas Tolchinsky 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GST 2 | === 3 | 4 | `gst` is like [gs](http://github.com/soveran/gs). The t is for Tonchis. 5 | 6 | ### TL;DR 7 | 8 | `gst` is a gemset manager inspired by [gs](http://github.com/soveran/gs). 9 | The difference is that it stays in the same shell and just modifies gem env variables. 10 | To be compatible with `gs`, it uses a `.gs` directory and sets the `GS_NAME` variable. 11 | 12 | ### USAGE 13 | 14 | Since `gst` is a script and runs in a child environment of your shell, the latter will not take the env changes unless you `source` them. 15 | 16 | ```shell 17 | $ gst init 18 | $ source gst in 19 | $ source gst out 20 | ``` 21 | 22 | Protip: in bash, `.` is the same as `source`. 23 | 24 | You can also run commands in the gemset using `gst in` without sourcing. This will execute them in the proper gem context but will not affect the current shell. 25 | 26 | ```shell 27 | $ gst in gem env home 28 | ``` 29 | 30 | ### COMMANDS 31 | 32 | ```shell 33 | init Creates the .gs directory 34 | in Modifies GEM_HOME, GEM_PATH and PATH to use the .gs directory and sets the GS_NAME variable. 35 | out Restores the previous GEM_HOME, GEM_PATH and PATH. Also unsets GS_NAME. 36 | ``` 37 | 38 | ### INSTALLATION 39 | 40 | With Homebrew 41 | 42 | ```shell 43 | brew tap tonchis/goodies && brew install gst 44 | ``` 45 | 46 | And for the standalone version, here's a oneliner. 47 | 48 | ```shell 49 | $ wget https://raw.githubusercontent.com/tonchis/gst/master/bin/gst && chmod +x gst && sudo mv gst /usr/local/bin 50 | ``` 51 | 52 | ### WHY? 53 | 54 | As I was using `gs` I noticed it wouldn't play well with `chruby`. 55 | 56 | The issue was the collision between the way `gs` works, by modifying the `gem` env variables and firing up a new shell with them, and the fact that `chruby` also sets those variables when using the `autoload` script or the `chruby` command. 57 | 58 | The last one being in my `.zshrc` script, it was stepping over `gs`'s work. 59 | 60 | Thus I decided to write my own gemset manager that doesn't run a new shell, but uses the current one. 61 | 62 | -------------------------------------------------------------------------------- /bin/gst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | usage() { 3 | cat << EOF 4 | usage: gst [COMMAND] 5 | 6 | SYNOPSIS 7 | gst is a gemset manager inspired by [gs](http://github.com/soveran/gs). 8 | The difference is that it stays in the same shell and just modifies gem env variables. 9 | To be compatible with gs, it uses a .gs directory and sets the GS_NAME variable. 10 | 11 | USAGE 12 | Since gst is a script and runs in a child environment of your shell, the latter will not take the env changes unless you source them. 13 | 14 | $ gst init 15 | $ source gst in 16 | $ source gst out 17 | 18 | Protip: in bash, \`.\` is the same as \`source\`. 19 | 20 | You can also run commands in the gemset using \`gst in\` without sourcing. This will execute them in the proper gem contex but will not affect the current shell. 21 | 22 | $ gst in gem env home 23 | 24 | COMMANDS 25 | init Creates the .gs directory 26 | in Modifies GEM_HOME, GEM_PATH and PATH to use the .gs directory and sets the GS_NAME variable. 27 | out Restores the previous GEM_HOME, GEM_PATH and PATH. Also unsets GS_NAME. 28 | EOF 29 | } 30 | 31 | if [[ "$1" != "in" && "$#" -ne 1 ]]; then 32 | usage 33 | exit 1 34 | fi 35 | 36 | case "$1" in 37 | "init") 38 | mkdir .gs;; 39 | "in") 40 | GS_DIR="$(pwd)/.gs" 41 | if [[ -d $GS_DIR ]]; then 42 | if [[ -z $GS_NAME ]]; then 43 | GST_OLD_PATH=$PATH 44 | GST_OLD_GEM_PATH=$GEM_PATH 45 | GST_OLD_GEM_HOME=$GEM_HOME 46 | 47 | export GST_OLD_PATH GST_OLD_GEM_PATH GST_OLD_GEM_HOME 48 | 49 | GS_NAME=$(pwd | sed -E "s/^.*\/(.*)$/\\1/") 50 | PATH="$GS_DIR/bin":$PATH 51 | GEM_PATH=$GS_DIR:$GEM_PATH 52 | GEM_HOME=$GS_DIR 53 | 54 | export PATH GEM_PATH GEM_HOME GS_NAME 55 | fi 56 | 57 | if [[ -n $2 ]]; then ${@:2}; fi 58 | else 59 | echo "Directory .gs not found. Run \`gst init\` first." 60 | fi 61 | ;; 62 | "out") 63 | if [[ -n $GS_NAME ]]; then 64 | PATH=$GST_OLD_PATH 65 | GEM_PATH=$GST_OLD_GEM_PATH 66 | GEM_HOME=$GST_OLD_GEM_HOME 67 | 68 | export PATH GEM_PATH GEM_HOME 69 | unset GST_OLD_PATH GST_OLD_GEM_PATH GST_OLD_GEM_HOME GS_NAME 70 | fi 71 | ;; 72 | *) 73 | usage 74 | exit 1 75 | ;; 76 | esac 77 | 78 | --------------------------------------------------------------------------------