I'm using the tmuxinator ruby gem which I installed via gem install tmuxinator,as per the projects github installation instructions.

tmuxinator link

As part of their installation instructions they specify also downloading a "completion" file from the repo and linking to it from your shells rc file.

My question: Seeing as I install the project as a ruby gem and not from cloning their github repo if I just download the file needed it wont be updated. Should I instead clone the repo and keep it somewhere, pointing to that location from the zshrc?

Is there a best practice or typical way people do this? Otherwise it seems like I either don't keep my files updated or I have to clone every project repo that works this way?

  • From the tmuxinator.gemspec it would look like the completion files are part of the gem, so the file in question - tmuxinator.zsh should already be on your system. See if you can track it down and just use the absolute path in ~/.zshrc: source /abs/path/to/tmuxinator.zsh. Unless the path changes with each update, it should keep work and always be up to date with the installed gem. – Adaephon Aug 26 '16 at 10:21
  • You're correct Adaephon I should have checked that first. Thanks. – Jordan Aug 26 '16 at 10:28
  • @Adaephon the path depends on the version of the gem currently installed. A symlink will break on upgrade if the old version is removed, so I wrote the code in the answer below to catch that and update appropriately. – Tom Hale Jan 15 '17 at 13:17

Here's something which will work in either zsh or bash to achieve what you're after.

If you do a gem clean to remove an old version of tmuxinator, it will fix things up for you when the code is next run (ie at next shell startup if in your .zshrc)

# Allow shell-specific code
function sh_is_zsh { [[ -n $ZSH_VERSION ]]; }
function sh_is_bash { [[ -n $BASH_VERSION ]]; }

# Update "tmuxinator.{z,ba}sh" if needed
tmuxinator_source="$XDG_CONFIG_HOME/tmuxinator/tmuxinator.$(sh_is_zsh && echo zsh || echo bash)"
# If not a regular file or symlink to one
if [[ ! -f $tmuxinator_source ]]; then
    # If doesn't exist or is a symlink to nowhere
    if [[ ! -e $tmuxinator_source ]] || [[ -L $tmuxinator_source ]] && [[ ! -e $tmuxinator_source ]]; then
        echo "Creating ${tmuxinator_source##*/} symlink:"
        tmp=$(gem which tmuxinator) # tmuxinator executable
        tmp=$(readlink -f "${tmp%/*}/../completion") # completion scripts dir
        ln -fsv "$tmp/${tmuxinator_source##*/}" "$tmuxinator_source"
        unset tmp
      echo "Not creating symlink at at existing:"
      ls -lF "$tmuxinator_source"

source "$tmuxinator_source"
unset $tmuxinator_source

Note this is shellcheck clean for extra brownie points.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.