lib/codestrap.rb
# Adds an entry to rcfile depending on shell
#
Adds an entry to rcfile depending on shell
Adds an entry to rcfile depending on shell
def strap_rcfile
      line = "\nexport PATH=$PATH:$HOME/.codestrap/bin\n"
      rcfile = begin
        case env['SHELL']
          when %r{/bin/bash$}
            File.join(env['HOME'], '.bash_profile')
          when %r{/bin/zsh$}
            File.join(env['HOME'], '.zshrc')
          when %r{/bin/sh$}
            File.join(env['HOME'], '.profile')
          else
            nil
        end
      end
      write = begin
        case
          when !rcfile
            false
          when(File.exist?(rcfile) and File.foreach(rcfile).grep(%r{export PATH=\$PATH:\$HOME/\.codestrap/bin}).length < 1)
            line = "\n" + line
            true
          when(not File.exist?(rcfile))
            true
          else
            false
        end
      end
      if write
        puts "Adding PATH='$PATH:$HOME/.codestrap/bin' to #{rcfile}"
        File.open(rcfile,'a') do |fh|
          fh.write(line)
        end
      end
    end
def strap_rcfile line = "\nexport PATH=$PATH:$HOME/.codestrap/bin\n" rcfile = begin case env [ 'SHELL' ] when %r{ /bin/bash$ } File . join ( env [ 'HOME' ] , '.bash_profile' ) when %r{ /bin/zsh$ } File . join ( env [ 'HOME' ] , '.zshrc' ) when %r{ /bin/sh$ } File . join ( env [ 'HOME' ] , '.profile' ) else nil end end write = begin case when ! rcfile false when ( File . exist? ( rcfile ) and File . foreach ( rcfile ) . grep ( %r{ export PATH= \$ PATH: \$ HOME/ \. codestrap/bin } ) . length < 1 ) line = "\n" + line true when ( not File . exist? ( rcfile ) ) true else false end end if write puts "Adding PATH='$PATH:$HOME/.codestrap/bin' to #{rcfile}" File . open ( rcfile , 'a' ) do | fh | fh . write ( line ) end end end
Adds an entry to rcfile depending on shell
Adds an entry to rcfile depending on shell
# Check shell # Check rcfile # Write file