diff --git a/README.md b/README.md index 5b3cf2d..fbbd736 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,63 @@ The most recently selected versions are presented at the top of the dropdown. 2. For example, `tgswitch 0.10.7` for version 0.10.7 of terragrunt. 3. Hit **Enter** to switch version. +### Use .tgswitchrc file +drawing + +1. Create a `.tgswitchrc` file containing the desired version +2. For example, `echo "0.14.1" >> .tgswitchrc` for version 0.10.5 of terraform +3. Run the command `tgswitch` in the same directory as your `.tgswitchrc` + +**Automatically switch with bash** + +Add the following to the end of your `~/.bashrc` file: +(Use `.tgswitchrc`) + +``` +cdtgswitch(){ + builtin cd "$@"; + cdir=$PWD; + if [ -f "$cdir/.tgswitchrc" ]; then + tgswitch + fi +} +alias cd='cdtgswitch' +``` + +drawing + +**Automatically switch with zsh** + + +Add the following to the end of your `~/.zshrc` file: + +``` +load-tgswitch() { + local tgswitchrc_path=".tgswitchrc" + + if [ -f "$tgswitchrc_path" ]; then + tgswitch + fi +} +add-zsh-hook chpwd load-tgswitch +load-tgswitch +``` +> NOTE: if you see an error like this: `command not found: add-zsh-hook`, then you might be on an older version of zsh (see below), or you simply need to load `add-zsh-hook` by adding this to your `.zshrc`: +> ``` +> autoload -U add-zsh-hook +> ``` + +*older version of zsh* +``` +cd(){ + builtin cd "$@"; + cdir=$PWD; + if [ -f "$cdir/.tgswitchrc" ]; then + tgswitch + fi +} +``` + ## Additional Info See how to *upgrade*, *uninstall*, *troubleshoot* here:[More info](https://warrensbox.github.io/tgswitch/additional) diff --git a/lib/symlink.go b/lib/symlink.go index 1f287f1..02d9efe 100644 --- a/lib/symlink.go +++ b/lib/symlink.go @@ -17,7 +17,7 @@ func CreateSymlink(cwd string, dir string) { Try running "unlink" to remove existing symlink. If error persist, you may not have the permission to create a symlink at %s. Error: %s - `, dir, dir, err) + `, dir, err) os.Exit(1) } } @@ -33,7 +33,7 @@ func RemoveSymlink(symlinkPath string) { Try running "unlink" to remove existing symlink. If error persist, you may not have the permission to create a symlink at %s. Error: %s - `, symlinkPath, symlinkPath, err) + `, symlinkPath, err) os.Exit(1) } else { errRemove := os.Remove(symlinkPath) @@ -44,7 +44,7 @@ func RemoveSymlink(symlinkPath string) { Try running "unlink" to remove existing symlink. If error persist, you may not have the permission to create a symlink at %s. Error: %s - `, symlinkPath, symlinkPath, errRemove) + `, symlinkPath, errRemove) os.Exit(1) } }